Skip to content

Instantly share code, notes, and snippets.

@knzm
Created November 8, 2011 16:39
Show Gist options
  • Save knzm/1348299 to your computer and use it in GitHub Desktop.
Save knzm/1348299 to your computer and use it in GitHub Desktop.
Jython + Servlet + WSGI + XML-RPC memo
INSTRUCTIONS
1. Put web.xml at /usr/share/tomcat6/webapps/jython_xmlrpc/WEB-INF/web.xml
2. Put jython.jar and servlet-api-2.4.jar at /usr/share/tomcat6/webapps/jython_xmlrpc/WEB-INF/lib/
3. Put index.wsgi at /usr/share/tomcat6/webapps/jython_xmlrpc/index.wsgi
4. Download http://pypi.python.org/pypi/wsgi-xmlrpc/ and unpack, then put wsgi_xmlrpc directory at /usr/share/tomcat6/webapps/jython_xmlrpc
5. Restart your tomcat server
# client demo
>>> import xmlrpclib
>>> server = xmlrpclib.Server("http://localhost:8080/jython_xmlrpc")
>>> server.test_1()
'test_1'
>>> server.test_2(1)
1
>>> server.test_3()
'test3'
#!/usr/bin/python
import os
import sys
from wsgi_xmlrpc import WSGIXMLRPCApplication
class Handler(object):
def test_1(self):
return u'test_1'
def test_2(self, value):
return value
def test_3():
return 'test3'
application = WSGIXMLRPCApplication(
instance=Handler(),
methods=[test_3],
)
if __name__ == '__main__':
from wsgiref import simple_server
server = simple_server.make_server('localhost', 8888, application)
server.serve_forever()
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>modjy</servlet-name>
<servlet-class>com.xhaus.modjy.ModjyJServlet</servlet-class>
<init-param>
<param-name>app_filename</param-name>
<param-value>index.wsgi</param-value>
</init-param>
<init-param>
<param-name>app_callable_name</param-name>
<param-value>application</param-value>
</init-param>
<init-param>
<param-name>reload_on_mod</param-name>
<param-value>1</param-value>
</init-param>
<init-param>
<param-name>load_site_packages</param-name>
<param-value>1</param-value>
</init-param>
<init-param>
<param-name>log_level</param-name>
<param-value>debug</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>modjy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment