|
From: <am...@us...> - 2009-03-05 15:54:48
|
Revision: 6069
http://jython.svn.sourceforge.net/jython/?rev=6069&view=rev
Author: amak
Date: 2009-03-05 15:54:43 +0000 (Thu, 05 Mar 2009)
Log Message:
-----------
Adding the original modjy demo application to the Demo subdirectory.
This application gives the users a complete running application that they can use as a template for aplication development.
In the future, we might develop a more sophisticated application.
Added Paths:
-----------
branches/modjy/Demo/modjy_webapp/
branches/modjy/Demo/modjy_webapp/WEB-INF/
branches/modjy/Demo/modjy_webapp/WEB-INF/lib/
branches/modjy/Demo/modjy_webapp/WEB-INF/lib-python/
branches/modjy/Demo/modjy_webapp/WEB-INF/lib-python/readme.txt
branches/modjy/Demo/modjy_webapp/WEB-INF/web.xml
branches/modjy/Demo/modjy_webapp/demo_app.py
branches/modjy/Demo/modjy_webapp/readme.txt
Added: branches/modjy/Demo/modjy_webapp/WEB-INF/lib-python/readme.txt
===================================================================
--- branches/modjy/Demo/modjy_webapp/WEB-INF/lib-python/readme.txt (rev 0)
+++ branches/modjy/Demo/modjy_webapp/WEB-INF/lib-python/readme.txt 2009-03-05 15:54:43 UTC (rev 6069)
@@ -0,0 +1,11 @@
+The WEB-INF/lib-python directory, if it exists, is automatically added
+to sys.path. Adding jython modules into this directory will make them
+available for import into your application.
+
+If you add your modules in a subdirectory, then be sure that that
+subdirectory contains an __init__.py file, so that the subdirectory
+is considered to be a package.
+
+See here for more details.
+http://www.rexx.com/~dkuhlman/python_101/python_101.html#SECTION004540000000000000000
+http://www.python.org/doc/essays/packages.html
Added: branches/modjy/Demo/modjy_webapp/WEB-INF/web.xml
===================================================================
--- branches/modjy/Demo/modjy_webapp/WEB-INF/web.xml (rev 0)
+++ branches/modjy/Demo/modjy_webapp/WEB-INF/web.xml 2009-03-05 15:54:43 UTC (rev 6069)
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE web-app
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+
+ <display-name>modjy demo application</display-name>
+ <description>
+ modjy WSGI demo application
+ </description>
+
+ <servlet>
+ <servlet-name>modjy</servlet-name>
+ <servlet-class>com.xhaus.modjy.ModjyJServlet</servlet-class>
+ <init-param>
+ <param-name>python.home</param-name>
+ <param-value>C:/jython2.5</param-value>
+ </init-param>
+<!--
+ There are two different ways you can specify an application to modjy
+ 1. Using the app_import_name mechanism
+ 2. Using a combination of app_directory/app_filename/app_callable_name
+ Examples of both are given below
+ See the documenation for more details.
+ http://modjy.xhaus.com/locating.html#locating_callables
+-->
+<!--
+ This is the app_import_name mechanism. If you specify a value
+ for this variable, then it will take precedence over the other mechanism
+ <init-param>
+ <param-name>app_import_name</param-name>
+ <param-value>my_wsgi_module.my_handler_class().handler_method</param-value>
+ </init-param>
+-->
+<!--
+ And this is the app_directory/app_filename/app_callable_name combo
+ The defaults for these three variables are ""/application.py/handler
+ So if you specify no values at all for any of app_* variables, then modjy
+ will by default look for "handler" in "application.py" in the servlet
+ context root.
+ <init-param>
+ <param-name>app_directory</param-name>
+ <param-value>some_sub_directory</param-value>
+ </init-param>
+-->
+ <init-param>
+ <param-name>app_filename</param-name>
+ <param-value>demo_app.py</param-value>
+ </init-param>
+<!--
+ Supply a value for this parameter if you want your application
+ callable to have a different name than the default.
+ <init-param>
+ <param-name>app_callable_name</param-name>
+ <param-value>my_handler_func</param-value>
+ </init-param>
+-->
+ <!-- Do you want application callables to be cached? -->
+ <init-param>
+ <param-name>cache_callables</param-name>
+ <param-value>1</param-value>
+ </init-param>
+ <!-- Should the application be reloaded if it's .py file changes? -->
+ <!-- Does not work with the app_import_name mechanism -->
+ <init-param>
+ <param-name>reload_on_mod</param-name>
+ <param-value>1</param-value>
+ </init-param>
+ <init-param>
+ <param-name>log_level</param-name>
+ <param-value>debug</param-value>
+<!-- <param-value>info</param-value> -->
+<!-- <param-value>warn</param-value> -->
+<!-- <param-value>error</param-value> -->
+<!-- <param-value>fatal</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>
Added: branches/modjy/Demo/modjy_webapp/demo_app.py
===================================================================
--- branches/modjy/Demo/modjy_webapp/demo_app.py (rev 0)
+++ branches/modjy/Demo/modjy_webapp/demo_app.py 2009-03-05 15:54:43 UTC (rev 6069)
@@ -0,0 +1,37 @@
+import sys
+
+def escape_html(s): return s.replace('&', '&').replace('<', '<').replace('>', '>')
+
+def cutoff(s, n=100):
+ if len(s) > n: return s[:n]+ '.. cut ..'
+ return s
+
+def handler(environ, start_response):
+ writer = start_response("200 OK", [ ('content-type', 'text/html') ])
+ response_parts = []
+ response_parts.append("<html>")
+ response_parts.append("<head>")
+ response_parts.append("<title>Modjy demo application</title>")
+ response_parts.append("</head>")
+ response_parts.append("<body>")
+ response_parts.append("<p>Modjy servlet running correctly: jython %s on %s:</p>" % (sys.version, sys.platform))
+ response_parts.append("<h3>Hello WSGI World!</h3>")
+ response_parts.append("<h4>Here are the contents of the WSGI environment</h4>")
+ environ_str = "<table border='1'>"
+ keys = environ.keys()
+ keys.sort()
+ for ix, name in enumerate(keys):
+ if ix % 2:
+ background='#ffffff'
+ else:
+ background='#eeeeee'
+ style = " style='background-color:%s;'" % background
+ value = escape_html(cutoff(str(environ[name]))) or ' '
+ environ_str = "%s\n<tr><td%s>%s</td><td%s>%s</td></tr>" % \
+ (environ_str, style, name, style, value)
+ environ_str = "%s\n</table>" % environ_str
+ response_parts.append(environ_str)
+ response_parts.append("</body>")
+ response_parts.append("</html>")
+ response_text = "\n".join(response_parts)
+ return [response_text]
Added: branches/modjy/Demo/modjy_webapp/readme.txt
===================================================================
--- branches/modjy/Demo/modjy_webapp/readme.txt (rev 0)
+++ branches/modjy/Demo/modjy_webapp/readme.txt 2009-03-05 15:54:43 UTC (rev 6069)
@@ -0,0 +1,15 @@
+To deploy this application
+
+1. Copy the jython.jar file into the WEB-INF/lib subdirectory
+2. Set the value of python.home property in WEB-INF/web.xml so
+ that it points to your jython installation.
+3. Copy this directory to the applications directory of your servlet
+ container. On Apache Tomcat, this is the "webapps" subdirectory
+ of the tomcat install directory.
+4. Enter the URL http://localhost:8080/modjy_webapp into your
+ browser.
+5. You should see a table containing the WSGI environment.
+
+Please see the installation documentation for more details.
+
+http://modjy.xhaus.com/install.html
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|