Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
This is a simple stupid script to startup ModJy inside of an embedded
Jetty server. Tested with Jython 2.5.1 and Jetty Hightide 6.1H.18

Example invocation:

    jython jetty_run.py --port 8080 --app_dir myapp

There should be a WSGI application in:

    myapp/application.py

Source listing of myapp/application.py:

    1 def handler(environ, start_response):
    2    status = '200 OK'
    3    response_headers = [('Content-type','text/plain')]
    4    start_response(status, response_headers)
    5    return ['Hello world!\n']

"""

from org.mortbay.jetty import Server
from org.mortbay.jetty.servlet import Context
from org.mortbay.jetty.servlet import ServletHolder
from com.xhaus.modjy import ModjyJServlet
from java.util import Properties
import argparse

parser = argparse.ArgumentParser(description="Startup the webtools")
parser.add_argument('--port', type=int, required=True)
parser.add_argument('--app_dir', type=str, required=True)
args = parser.parse_args()
props = Properties()
props.setProperty('app_directory', args.app_dir)
server = Server(args.port)
root = Context(server,"/",Context.SESSIONS)
root.setInitParams(props)
root.addServlet(ServletHolder(ModjyJServlet()), "/*")
server.start()