Skip to content

Commit 47dca6e

Browse files
committed
Added server-side servlet stuff
1 parent 7868112 commit 47dca6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2561
-0
lines changed

build.xml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<!-- This is a template Ant file for a very basic Google AppEngine project -->
2+
3+
<project name="calabash_servlet" default="war">
4+
5+
<!-- When you copy this template to your working directories, change the
6+
value of appengine.sdk accordingly. You may also want to use Ant's
7+
property file feature, allowing each developer to have their own
8+
local property file with the path to the SDK from that workspace. -->
9+
<property name="appengine.sdk" location="../appengine-java-sdk-1.2.1"/>
10+
11+
<!-- Check that the SDK value is set and seems sane, so we can give a nicer
12+
error if not. -->
13+
<fail message="Please define the appengine.sdk property to point to your SDK directory">
14+
<condition>
15+
<not> <and>
16+
<isset property="appengine.sdk"/>
17+
<available file="${appengine.sdk}/config/user/ant-macros.xml"/>
18+
</and> </not>
19+
</condition>
20+
</fail>
21+
22+
<!-- Pick up the Ant macros and taskdefs for App Engine -->
23+
<import file="${appengine.sdk}/config/user/ant-macros.xml"/>
24+
25+
26+
<!-- Remote debug port for dev_appserver -->
27+
<property name="debug.port" value="5005"/>
28+
29+
<!-- HTTP port for dev_appserver -->
30+
<property name="http.port" value="8080"/>
31+
32+
<!-- Name of log file to write logs to -->
33+
<property name="log.file" value="app.log"/>
34+
35+
<!-- Number of days worth of logs to retrieve -->
36+
<property name="log.days" value="2"/>
37+
38+
39+
<!-- Change if you like e.g. "war" better than "www" for the output -->
40+
<property name="war.dir" location="war"/>
41+
42+
<target name="war" depends="compile"
43+
description="Assemble the application directory">
44+
<mkdir dir="${war.dir}/WEB-INF"/>
45+
<copy todir="${war.dir}">
46+
<fileset dir="html">
47+
<exclude name="**/.svn/**"/>
48+
<exclude name="**/*~"/>
49+
</fileset>
50+
</copy>
51+
<copy todir="${war.dir}/WEB-INF">
52+
<fileset dir="src/WEB-INF">
53+
<include name="*.xml"/>
54+
</fileset>
55+
</copy>
56+
<enhance_war war="${war.dir}"/>
57+
</target>
58+
59+
<target name="enhance" depends="compile"
60+
description="Enhance the classes after compilation">
61+
<enhance_war war="${war.dir}"/>
62+
</target>
63+
64+
<target name="compile"
65+
description="Compile the application servlet code">
66+
<mkdir dir="${war.dir}/WEB-INF/classes"/>
67+
<mkdir dir="${war.dir}/WEB-INF/lib"/>
68+
<javac srcdir="src" destdir="${war.dir}/WEB-INF/classes">
69+
<classpath>
70+
<fileset dir="${appengine.sdk}/lib/user">
71+
<include name="*.jar"/>
72+
</fileset>
73+
<fileset dir="${appengine.sdk}/lib/shared">
74+
<include name="*.jar"/>
75+
</fileset>
76+
<fileset dir="war/WEB-INF/lib">
77+
<include name="*.jar"/>
78+
</fileset>
79+
</classpath>
80+
</javac>
81+
</target>
82+
83+
<target name="clean"
84+
description="Force a clean slate to rebuild">
85+
<delete dir="${war.dir}"/>
86+
</target>
87+
88+
89+
90+
<target name="dev_appserver" depends="war"
91+
description="Run the dev_appserver">
92+
<dev_appserver war="${war.dir}" port="${http.port}"/>
93+
</target>
94+
95+
<target name="debug" depends="war"
96+
description="Launches dev_appserver with remote debugging enabled">
97+
<echo message="Launching dev_appserver on Web port ${http.port}, Java remote debug port ${debug.port}"/>
98+
<dev_appserver war="${war.dir}" port="${http.port}">
99+
<options>
100+
<arg value="--jvm_flag=-Xdebug"/>
101+
<arg value="--jvm_flag=-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${debug.port}"/>
102+
</options>
103+
</dev_appserver>
104+
</target>
105+
106+
107+
108+
<target name="update" depends="war"
109+
description="Uploads the application, including indexes">
110+
<appcfg action="update" war="${war.dir}"/>
111+
</target>
112+
113+
<target name="update_indexes" depends="war"
114+
description="Uploads only the application's indexes">
115+
<appcfg action="update_indexes" war="${war.dir}"/>
116+
</target>
117+
118+
<target name="rollback" depends="war"
119+
description="Rolls back any in-progress application update">
120+
<appcfg action="rollback" war="${war.dir}"/>
121+
</target>
122+
123+
<target name="request_logs"
124+
description="Downloads the application's logs">
125+
<appcfg action="request_logs" war="${war.dir}">
126+
<options>
127+
<arg value="--num_days=${log.days}"/>
128+
</options>
129+
<args>
130+
<arg value="${log.file}"/>
131+
</args>
132+
</appcfg>
133+
</target>
134+
135+
</project>
136+

src/META-INF/jdoconfig.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
5+
6+
<persistence-manager-factory name="transactions-optional">
7+
<property name="javax.jdo.PersistenceManagerFactoryClass" value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/>
8+
<property name="javax.jdo.option.ConnectionURL" value="appengine"/>
9+
<property name="javax.jdo.option.NontransactionalRead" value="true"/>
10+
<property name="javax.jdo.option.NontransactionalWrite" value="true"/>
11+
<property name="javax.jdo.option.RetainValues" value="true"/>
12+
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
13+
</persistence-manager-factory>
14+
</jdoconfig>

src/WEB-INF/appengine-web.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
2+
<!-- Replace this with your application id from http://appengine.google.com -->
3+
<application>feedscape</application>
4+
5+
<version>5</version>
6+
7+
<system-properties>
8+
<property name="user.home" value="http://feedscape.appspot.com"/>
9+
<property name="user.dir" value="http://feedscape.appspot.com"/>
10+
<property name="com.xmlcalabash.phonehome" value="false"/>
11+
</system-properties>
12+
13+
</appengine-web-app>

src/WEB-INF/web.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="ISO-8859-1"?>
2+
<web-app
3+
xmlns="http://java.sun.com/xml/ns/javaee"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
6+
version="2.5">
7+
<display-name>Xproc Servlet</display-name>
8+
9+
<servlet>
10+
<servlet-name>calabash</servlet-name>
11+
<servlet-class>com.portlanddatasystems.xproc.CalabashServlet</servlet-class>
12+
</servlet>
13+
14+
<servlet-mapping>
15+
<servlet-name>calabash</servlet-name>
16+
<url-pattern>/run</url-pattern>
17+
</servlet-mapping>
18+
19+
</web-app>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.portlanddatasystems.xproc;
2+
3+
import java.io.IOException;
4+
import javax.servlet.ServletOutputStream;
5+
import javax.servlet.http.*;
6+
7+
//import net.sf.saxon.s9api.SaxonApiException;
8+
9+
import java.io.BufferedReader;
10+
import java.io.InputStreamReader;
11+
import java.io.StringReader;
12+
13+
import org.apache.commons.fileupload.FileItemIterator;
14+
import org.apache.commons.fileupload.FileItemStream;
15+
import org.apache.commons.fileupload.FileUploadException;
16+
import org.apache.commons.fileupload.servlet.ServletFileUpload;
17+
18+
import java.io.InputStream;
19+
20+
import javax.servlet.ServletException;
21+
22+
//import java.net.URI;
23+
//import com.xmlcalabash.util.URIUtils;
24+
//import java.io.PrintWriter;
25+
26+
@SuppressWarnings("serial")
27+
public class CalabashServlet extends HttpServlet {
28+
PipelineRunner pipeline = null;
29+
ServletFileUpload upload;
30+
31+
public void init() {
32+
InputStream xslSheet = getServletContext().getResourceAsStream("/WEB-INF/proc.xsl");
33+
this.pipeline = new PipelineRunner(xslSheet);
34+
this.upload = new ServletFileUpload();
35+
}
36+
37+
public void doGet(HttpServletRequest req, HttpServletResponse resp)
38+
throws IOException {
39+
resp.setContentType("text/plain");
40+
resp.getWriter().println("You're supposed to POST an XProc-ish file to this URL.");
41+
//PrintWriter out = resp.getWriter();
42+
//out.println("You're supposed to POST an XProc-ish file to this URL.");
43+
//out.println("That's all");
44+
}
45+
46+
public void doPost(HttpServletRequest req, HttpServletResponse resp)
47+
throws ServletException, IOException {
48+
//StringReader input = new StringReader(req.getParam("config"));
49+
//BufferedReader input = req.getReader();
50+
//XdmNode pipeline = input.transform("pipeline.xsl");
51+
//XdmNode pipeline = builder.build(new SAXSource(new InputSource(req.getReader())));
52+
ServletOutputStream output = resp.getOutputStream();
53+
//output.println("Ok...\n");
54+
55+
resp.setContentType("application/xml");
56+
//resp.setContentType("text/plain");
57+
//String filename = getServletContext().getRealPath("/WEB-INF/web.xml"); //getContext TODO
58+
//output.println(filename);
59+
60+
FileItemIterator iter = null;
61+
FileItemStream item = null;
62+
//ServletFileUpload upload = new ServletFileUpload();
63+
try {
64+
iter = upload.getItemIterator(req);
65+
} catch (FileUploadException fue) {
66+
output.println("Bad servlet iter!");
67+
System.out.println("Bad out iter!");
68+
fue.printStackTrace();
69+
}
70+
try {
71+
item = iter.next();
72+
} catch (FileUploadException fue) {
73+
output.println("Bad servlet next!");
74+
System.out.println("Bad out next!");
75+
fue.printStackTrace();
76+
}
77+
InputStream in = item.openStream();
78+
//output.println(in.toString());
79+
BufferedReader input = new BufferedReader(new InputStreamReader(in));
80+
81+
//output.println(input.toString());
82+
//String line;
83+
//while ((line = input.readLine()) != null) {
84+
// output.println(line);
85+
//}
86+
//output.println(pipeline.toString());
87+
//output.println(home.toString());
88+
//output.println(cwd.toString());
89+
//output.println("That's all");
90+
String aftermath = pipeline.run(input, output);
91+
if (aftermath != null) {
92+
output.println("<error>");
93+
output.println(aftermath);
94+
output.println("</error>");
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)