Permalink
Browse files

Initial checkin of 'Piperack' a RESTful web interface to pipelines

  • Loading branch information...
ndw committed Oct 25, 2013
1 parent 0f6a10b commit a807faf40cc8400c621373bbd7a4802165ad5723
View
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,60 @@
================
Copyright notice
================
Version 4.3, January 2012
This software distribution is covered by this copyright notice.
All third-party libraries redistributed with this software remain the property
of their respective copyright owners and are subject to separate license
agreements. For questions, please contact the copyright holder:
Restlet SAS
ESSEC Ventures - CNIT - BP 230
2 place de la Defense
92053 Paris La Defense
FRANCE
http://www.restlet.org/about/legal
mailto:legal@restlet.com
________________________________________________________________________________
Copyright 2005-2013 Restlet S.A.S.
The contents of this file are subject to the terms of one of the following
open source licenses: Apache 2.0 or LGPL 3.0 or LGPL 2.1 or CDDL 1.0 or EPL
1.0 (the "Licenses"). You can select the license that you prefer but you may
not use this file except in compliance with one of these Licenses.
You can obtain a copy of the Apache 2.0 license at
http://www.opensource.org/licenses/apache-2.0
You can obtain a copy of the LGPL 3.0 license at
http://www.opensource.org/licenses/lgpl-3.0
You can obtain a copy of the LGPL 2.1 license at
http://www.opensource.org/licenses/lgpl-2.1
You can obtain a copy of the CDDL 1.0 license at
http://www.opensource.org/licenses/cddl1
You can obtain a copy of the EPL 1.0 license at
http://www.opensource.org/licenses/eclipse-1.0
See the Licenses for the specific language governing permissions and
limitations under the Licenses.
Alternatively, you can obtain a royalty free commercial license with less
limitations, transferable or non-transferable, directly at
http://www.restlet.com/products/restlet-framework
Restlet is a registered trademark of Restlet S.A.S.
________________________________________________________________________________
This product includes the FreeMarker software developed by the Visigoth
Software Society (http://www.visigoths.org/).
@@ -103,6 +103,9 @@
public String jsonFlavor = JSONtoXML.MARKLOGIC;
public boolean useXslt10 = false;
public int piperackPort = 8088;
public int piperackDefaultExpires = 300;
private Processor cfgProcessor = null;
private boolean firstInput = false;
private boolean firstOutput = false;
@@ -431,6 +434,10 @@ public void parse(XdmNode doc) {
saxonConfigurationProperty(node);
} else if ("pipeline-loader".equals(localName)) {
pipelineLoader(node);
} else if ("piperack-port".equals(localName)) {
piperackPort(node);
} else if ("piperack-default-expires".equals(localName)) {
piperackDefaultExpires(node);
} else {
throw new XProcException(doc, "Unexpected configuration option: " + localName);
}
@@ -489,6 +496,21 @@ public XProcStep newStep(XProcRuntime runtime,XAtomicStep step){
}
}
public static void showVersion(XProcRuntime runtime) {
System.out.println("XML Calabash version " + XProcConstants.XPROC_VERSION + ", an XProc processor.");
if (runtime != null) {
System.out.print("Running on Saxon version ");
System.out.print(runtime.getConfiguration().getProcessor().getSaxonProductVersion());
System.out.print(", ");
System.out.print(runtime.getConfiguration().getProcessor().getUnderlyingConfiguration().getEditionCode());
System.out.println(" edition.");
}
System.out.println("Copyright (c) 2007-2013 Norman Walsh");
System.out.println("See docs/notices/NOTICES in the distribution for licensing");
System.out.println("See also http://xmlcalabash.com/ for more information");
System.out.println("");
}
private void parseSaxonProcessor(XdmNode node) {
String value = node.getStringValue().trim();
@@ -665,6 +687,16 @@ private void pipelineLoader(XdmNode node) {
}
}
private void piperackPort(XdmNode node) {
String portno = node.getStringValue().trim();
piperackPort = Integer.parseInt(portno);
}
private void piperackDefaultExpires(XdmNode node) {
String secs = node.getStringValue().trim();
piperackDefaultExpires = Integer.parseInt(secs);
}
private void parseInput(XdmNode node) {
String port = node.getAttributeValue(_port);
String href = node.getAttributeValue(_href);
@@ -140,7 +140,7 @@ boolean run(UserArgs userArgs, XProcConfiguration config) throws SaxonApiExcepti
debug = config.debug;
if (userArgs.isShowVersion()) {
showVersion();
XProcConfiguration.showVersion(runtime);
}
XPipeline pipeline = null;
@@ -429,24 +429,9 @@ private void setParametersOnPipeline(XPipeline pipeline, String port, Map<QName,
}
}
private void showVersion() {
System.out.println("XML Calabash version " + XProcConstants.XPROC_VERSION + ", an XProc processor.");
if (runtime != null) {
System.out.print("Running on Saxon version ");
System.out.print(runtime.getConfiguration().getProcessor().getSaxonProductVersion());
System.out.print(", ");
System.out.print(runtime.getConfiguration().getProcessor().getUnderlyingConfiguration().getEditionCode());
System.out.println(" edition.");
}
System.out.println("Copyright (c) 2007-2012 Norman Walsh");
System.out.println("See docs/notices/NOTICES in the distribution for licensing");
System.out.println("See also http://xmlcalabash.com/ for more information");
System.out.println("");
}
private void usage() throws IOException {
System.out.println();
showVersion();
XProcConfiguration.showVersion(runtime);
InputStream instream = getClass().getResourceAsStream("/etc/usage.txt");
if (instream == null) {
@@ -0,0 +1,69 @@
package com.xmlcalabash.drivers;
import com.xmlcalabash.core.XProcConfiguration;
import com.xmlcalabash.core.XProcException;
import com.xmlcalabash.core.XProcRuntime;
import com.xmlcalabash.piperack.PiperackApplication;
import com.xmlcalabash.util.ParseArgs;
import com.xmlcalabash.util.UserArgs;
import net.sf.saxon.s9api.SaxonApiException;
import org.restlet.Component;
import org.restlet.data.Protocol;
/**
* Ths file is part of XMLCalabash.
* Created by ndw on 10/25/13.
*/
public class Piperack {
public static void main(String[] args) throws Exception {
UserArgs userArgs = null;
try {
userArgs = new ParseArgs().parsePiperack(args);
} catch (XProcException xe) {
System.err.println(xe.getMessage());
System.exit(-1);
}
XProcConfiguration config = null;
XProcRuntime runtime = null;
try {
config = userArgs.createConfiguration();
runtime = new XProcRuntime(config);
} catch (SaxonApiException e) {
System.err.println(e.getMessage());
System.exit(-1);
}
if (userArgs.isShowVersion()) {
System.out.println("Piperack, a web server for running XProc pipelines.");
XProcConfiguration.showVersion(runtime);
}
// Create a component
Component component = new Component();
component.getServers().add(Protocol.HTTP, config.piperackPort);
// Create an application
PiperackApplication application = new PiperackApplication(config, runtime);
// Attach the application to the component and start it
component.getDefaultHost().attach(application);
component.start();
while (true) {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// nop
}
// It doesn't seem like this should be necessary!
if (application.stopped()) {
System.exit(0);
}
application.expirePipelines();
}
}
}
Oops, something went wrong.

0 comments on commit a807faf

Please sign in to comment.