Top Fields Constructors Methods
com.xhaus.modjy

public Class ModjyJServlet

extends HttpServlet
Class Inheritance
Imports
java.io.File, .FileReader, .IOException, .LineNumberReader, java.util.Enumeration, .Properties, javax.servlet.ServletContext, .ServletException, javax.servlet.http.HttpServlet, .HttpServletRequest, .HttpServletResponse, org.python.core.Options, .Py, .PyException, .PyObject, .PyString, .PySystemState, .PyType, org.python.util.PythonInterpreter

Field Summary

Modifier and TypeField and Description
protected PythonInterpreter
protected static final String
protected static final String
protected static final String
protected HttpServlet
protected static final String
protected static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
checkSitePackages(Properties
- The properties from which config options are found
props
)

Check if the user has requested to initialise the jython installation "site-packages".

public void
destroy()

Overrides javax.servlet.GenericServlet.destroy.

Implements javax.servlet.Servlet.destroy.

Close down the modjy servlet.

public void
init()

Overrides javax.servlet.GenericServlet.init.

Initialise the modjy servlet.

protected void
processPthFile(PythonInterpreter
- The PythonInterpreter which will execute imports
interp
,
PySystemState
- The PySystemState whose path should be updated
systemState
,
String
- The actual path to the lib-python directory
pythonLibPath
,
String
- The PySystemState whose path should be updated
pthFilename
)

Process an individual file .pth file in the lib-python directory

protected void
processPythonLib(PythonInterpreter
- The PythonInterpreter used to service requests
interp
,
PySystemState
- The PySystemState whose path should be updated
systemState
)

Do all processing in relation to the lib-python subdirectory of WEB-INF

protected Properties
readConfiguration()

Read configuration 1.

public void
service(HttpServletRequest
- The incoming HttpServletRequest
req
,
HttpServletResponse
- The outgoing HttpServletResponse
resp
)

Overrides javax.servlet.http.HttpServlet.service.

Actually service the incoming request.

protected void
setupEnvironment(PythonInterpreter
- The PythonInterpreter used to service requests
interp
,
Properties
- The properties from which config options are found
props
,
PySystemState
- The PySystemState corresponding to the interpreter servicing requests
systemState
)

Setup the modjy environment, i.e. 1.

Inherited from javax.servlet.http.HttpServlet:
doDeletedoGetdoHeaddoOptionsdoPostdoPutdoTracegetLastModifiedservice

Field Detail

interpback to summary
protected PythonInterpreter interp
LIB_PYTHONback to summary
protected static final String LIB_PYTHON
LOAD_SITE_PACKAGES_PARAMback to summary
protected static final String LOAD_SITE_PACKAGES_PARAM
MODJY_PYTHON_CLASSNAMEback to summary
protected static final String MODJY_PYTHON_CLASSNAME
modjyServletback to summary
protected HttpServlet modjyServlet
PTH_FILE_EXTENSIONback to summary
protected static final String PTH_FILE_EXTENSION
PYTHON_HOME_PARAMback to summary
protected static final String PYTHON_HOME_PARAM

Constructor Detail

ModjyJServletback to summary
public ModjyJServlet()

Method Detail

checkSitePackagesback to summary
protected void checkSitePackages(Properties props) throws PyException

Check if the user has requested to initialise the jython installation "site-packages". The value defaults to true, i.e. load site packages

Parameters
props:Properties

- The properties from which config options are found

destroyback to summary
public void destroy()

Overrides javax.servlet.GenericServlet.destroy.

Implements javax.servlet.Servlet.destroy.

Close down the modjy servlet.

Annotations
@Override
initback to summary
public void init() throws ServletException

Overrides javax.servlet.GenericServlet.init.

Initialise the modjy servlet. 1. Read the configuration 2. Initialise the jython runtime 3. Setup, in relation to the J2EE servlet environment 4. Create the jython-implemented servlet 5. Initialise the jython-implemented servlet

Annotations
@Override
Exceptions
ServletException:

Doc from javax.servlet.GenericServlet.init.

if an exception occurs that interrupts the servlet's normal operation

processPthFileback to summary
protected void processPthFile(PythonInterpreter interp, PySystemState systemState, String pythonLibPath, String pthFilename)

Process an individual file .pth file in the lib-python directory

Parameters
interp:PythonInterpreter

- The PythonInterpreter which will execute imports

systemState:PySystemState

- The PySystemState whose path should be updated

pythonLibPath:String

- The actual path to the lib-python directory

pthFilename:String

- The PySystemState whose path should be updated

processPythonLibback to summary
protected void processPythonLib(PythonInterpreter interp, PySystemState systemState)

Do all processing in relation to the lib-python subdirectory of WEB-INF

Parameters
interp:PythonInterpreter

- The PythonInterpreter used to service requests

systemState:PySystemState

- The PySystemState whose path should be updated

readConfigurationback to summary
protected Properties readConfiguration()

Read configuration 1. Both context and servlet parameters are included in the set, so that the definition of some parameters (e.g python.*) can be shared between multiple WSGI servlets. 2. servlet params take precedence over context parameters

serviceback to summary
public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException

Overrides javax.servlet.http.HttpServlet.service.

Actually service the incoming request. Simply delegate to the jython servlet.

Parameters
req:HttpServletRequest

- The incoming HttpServletRequest

resp:HttpServletResponse

- The outgoing HttpServletResponse

Annotations
@Override
Exceptions
ServletException:

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

if the HTTP request cannot be handled

IOException:

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

if an input or output error occurs while the servlet is handling the HTTP request

setupEnvironmentback to summary
protected void setupEnvironment(PythonInterpreter interp, Properties props, PySystemState systemState) throws PyException

Setup the modjy environment, i.e. 1. Find the location of the modjy.jar file and add it to sys.path 2. Process the WEB-INF/lib-python directory, if it exists

Parameters
interp:PythonInterpreter

- The PythonInterpreter used to service requests

props:Properties

- The properties from which config options are found

systemState:PySystemState

- The PySystemState corresponding to the interpreter servicing requests