Skip to content Skip to sidebar Skip to footer

Python Web Service For A Java Application?

Forgive me if this is a stupid question. I am completely new to building web services and complete web apps. I want to develop a particular functionality for a java based web appl

Solution 1:

I think it is possible. Let's assume that your webservice method returns a json string. You can use this string, convert into a HashMap in Java and work with the data.

I personally prefer cherrypy, for the ease of creating a webservice. It has an inbuilt server too.

You can use FlexJSON to convert json string into a HashMap. The method deserialize will help in doing so. This is how I did it.

publicMap<String, Object> JsonToMap(String data) {
        Map<String, Object> dataMap;
        dataMap = newJSONDeserializer<Map>().deserialize(data);
        return dataMap;
    }

Here, String data is the json string that your python webservice method is supposed to return.

Solution 2:

That depends on how you mean this. Do you mean to use the service as a library within the app? If so, you may want to look at Jython and make it into a plugin.

If, however, you want to run the service as a separate app, then use the web interface to call it from Java, that should be no problem. In theory, the end user of a web service (in this case, the user is your app) should never have to worry about what language the service is written in; as long as the standards are kept to (JSON, XML, etc), most languages will have the capability to work together.

Solution 3:

When developing in a framework, it is generally simpler to develop with the language of the framework than it is to develop with a different language.

Servlets are components of the web server (which is also called a Servlet container). The Servlet container and the required Servlet API is all Java. While you could Frankenstein in some sort of Python code, odds are good that the integration effort would eventually make that "simplicity" far more complex than you particularly desire.

If you want a Python web application, use a Python web framework. If you want a Java web application, use a Java framework. Don't try to make the two cross compatible, as the integration points (and used / offered conveniences) are not even guaranteed to be present on the "other side" of the fence.

Solution 4:

There are many web frameworks for java, some are better than others. For a fairly comprehensive reference, consider consulting http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#Java.

Python is indeed a fairly intuitive language and because it is frequently used as a server side scripting language, a lot of respectable web frameworks (like webpy and django) have emerged.

It depends what tasks you are trying to implement. If your project requires a java applet, you may be able to embed it within a web page which you dynamically compose using a python framework. However, if you are looking for interoperability between java and python, you will wish to read more about Jython (and it's limitations) as lacqui has suggested.

Personally, I'm a fan of webpy over cherrypy for quick, lightweight, practical and easy web development and templating, however, if speed is a major concern, you may wish to consider this before adopting a dynamically typed interpreted language. Python 3 is on average around 50 times slower than Java 6 over the JVM (http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&lang=python3&lang2=java)

For more information regarding the comparison of java versus python, take a look at http://pythonconquerstheuniverse.wordpress.com/category/java-and-python/.

Post a Comment for "Python Web Service For A Java Application?"