Top Description Inners Fields Constructors Methods
org.python.util

public Class PyServlet

extends HttpServlet
Class Inheritance
Imports
java.io.File, .IOException, java.util.Enumeration, .Map, .Properties, java.util.logging.Level, .Logger, java.util.regex.Matcher, .Pattern, javax.servlet.ServletContext, .ServletException, .ServletRequest, .ServletResponse, javax.servlet.http.HttpServlet, .HttpServletRequest, org.python.Version, org.python.core.PrePy, .Py, .PyException, .PyObject, .PyString, .PySystemState

This servlet is used to re-serve Jython servlets. It stores bytecode for Jython servlets and re-uses it if the underlying .py file has not changed.

e.g. http://localhost:8080/test/hello.py

from javax.servlet.http import HttpServlet
class hello(HttpServlet):
    def doGet(self, req, res):
        res.setContentType("text/html");
        out = res.getOutputStream()
        print >>out, "<html>"
        print >>out, "<head><title>Hello World, How are we?</title></head>"
        print >>out, "<body>Hello World, how are we?"
        print >>out, "</body>"
        print >>out, "</html>"
        out.close()
in web.xml for the PyServlet context:
<web-app>
    <servlet>
        <servlet-name>PyServlet</servlet-name>
        <servlet-class>org.python.util.PyServlet</servlet-class>
        <init-param>
            <param-name>python.home</param-name>
            <param-value>/usr/home/jython-2.5</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>PyServlet</servlet-name>
        <url-pattern>*.py</url-pattern>
    </servlet-mapping>
</web-app>

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private Map<String, PyServlet.CacheEntry>
private static final Pattern
protected static final String
private PythonInterpreter
protected static final Logger
public static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected static <T> T
createInstance(PythonInterpreter interp, File file, Class<T> type)

protected static PythonInterpreter
public void
destroy()

Overrides javax.servlet.GenericServlet.destroy.

Implements javax.servlet.Servlet.destroy.

Called by the servlet container to indicate to a servlet that the servlet is being taken out of service.

private void
protected static String
private synchronized HttpServlet
public void
init()

Overrides javax.servlet.GenericServlet.init.

A convenience method which can be overridden so that there's no need to call super.init(config).

protected static void
init(Properties props, ServletContext context)

PyServlet's initialization can be performed as a ServletContextListener or as a regular servlet, and this is the shared init code.

private HttpServlet
public void
reset()

Clears the cache of loaded servlets and makes a new PythonInterpreter to service further requests.

public void
service(ServletRequest
the HttpServletRequest object that contains the request the client made of the servlet
req
,
ServletResponse
the HttpServletResponse object that contains the response the servlet returns to the client
res
)

Overrides javax.servlet.http.HttpServlet.service.

Implements javax.servlet.Servlet.service.

Dispatches client requests to the protected service method.

Inherited from javax.servlet.http.HttpServlet:
doDeletedoGetdoHeaddoOptionsdoPostdoPutdoTracegetLastModifiedservice

Field Detail

cacheback to summary
private Map<String, PyServlet.CacheEntry> cache
FIND_NAMEback to summary
private static final Pattern FIND_NAME
INIT_ATTRback to summary
protected static final String INIT_ATTR
interpback to summary
private PythonInterpreter interp
loggerback to summary
protected static final Logger logger
SKIP_INIT_NAMEback to summary
public static final String SKIP_INIT_NAME

Constructor Detail

PyServletback to summary
public PyServlet()

Method Detail

createInstanceback to summary
protected static <T> T createInstance(PythonInterpreter interp, File file, Class<T> type) throws ServletException
createInterpreterback to summary
protected static PythonInterpreter createInterpreter(ServletContext servletContext)
destroyback to summary
public void destroy()

Overrides javax.servlet.GenericServlet.destroy.

Implements javax.servlet.Servlet.destroy.

Doc from javax.servlet.GenericServlet.destroy.

Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. See Servlet#destroy.

Annotations
@Override
destroyCacheback to summary
private void destroyCache()
getRootPathback to summary
protected static String getRootPath(ServletContext context)
getServletback to summary
private synchronized HttpServlet getServlet(String path) throws ServletException, IOException
initback to summary
public void init()

Overrides javax.servlet.GenericServlet.init.

Doc from javax.servlet.GenericServlet.init.

A convenience method which can be overridden so that there's no need to call super.init(config).

Instead of overriding init(ServletConfig), simply override this method and it will be called by GenericServlet.init(ServletConfig config). The ServletConfig object can still be retrieved via getServletConfig.

Annotations
@Override
initback to summary
protected static void init(Properties props, ServletContext context)

PyServlet's initialization can be performed as a ServletContextListener or as a regular servlet, and this is the shared init code. If both initializations are used in a single context, the system state initialization code only runs once.

loadServletback to summary
private HttpServlet loadServlet(String path) throws ServletException, IOException
resetback to summary
public void reset()

Clears the cache of loaded servlets and makes a new PythonInterpreter to service further requests.

serviceback to summary
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException

Overrides javax.servlet.http.HttpServlet.service.

Implements javax.servlet.Servlet.service.

Doc from javax.servlet.http.HttpServlet.service.

Dispatches client requests to the protected service method. There's no need to override this method.

Parameters
req:ServletRequest

the HttpServletRequest object that contains the request the client made of the servlet

res:ServletResponse

the HttpServletResponse object that contains the response the servlet returns to the client

Annotations
@Override
Exceptions
ServletException:
if the HTTP request cannot be handled or if either parameter is not an instance of its respective HttpServletRequest or HttpServletResponse counterparts.
IOException:
if an input or output error occurs while the servlet is handling the HTTP request
org.python.util back to summary

private Class PyServlet.CacheEntry

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public long
public HttpServlet

Constructor Summary

AccessConstructor and Description
pack-priv
CacheEntry(HttpServlet servlet, long date)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dateback to summary
public long date
servletback to summary
public HttpServlet servlet

Constructor Detail

CacheEntryback to summary
pack-priv CacheEntry(HttpServlet servlet, long date)