You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ch...@apache.org on 2015/06/02 19:36:02 UTC
svn commit: r1683146 - in /uima/sandbox/uima-ducc/trunk:
uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/
uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/
uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/
uima-d...
Author: challngr
Date: Tue Jun 2 17:36:02 2015
New Revision: 1683146
URL: http://svn.apache.org/r1683146
Log:
UIMA-4394 Use non-classloading HTTP dispatcher for non-CLI things http requests.
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/BaseHttpDispatcher.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/DuccEventHttpDispatcherCl.java
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CliBase.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DispatcherFactory.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccMonitor.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOneLauncher.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/DuccEventHttpDispatcher.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/common/IDuccJobDeployment.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/common/JobManagerStateReconciler.java
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CliBase.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CliBase.java?rev=1683146&r1=1683145&r2=1683146&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CliBase.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CliBase.java Tue Jun 2 17:36:02 2015
@@ -40,8 +40,6 @@ import org.apache.uima.ducc.common.crypt
import org.apache.uima.ducc.common.utils.DuccProperties;
import org.apache.uima.ducc.common.utils.DuccPropertiesResolver;
import org.apache.uima.ducc.common.utils.Utils;
-import org.apache.uima.ducc.transport.dispatcher.ClassManager;
-import org.apache.uima.ducc.transport.dispatcher.DuccEventHttpDispatcher;
import org.apache.uima.ducc.transport.dispatcher.IDuccEventDispatcher;
import org.apache.uima.ducc.transport.event.AbstractDuccOrchestratorEvent;
import org.apache.uima.ducc.transport.event.IDuccContext.DuccContext;
@@ -204,24 +202,6 @@ public abstract class CliBase
}
}
}
-
- DuccEventHttpDispatcher makeDispatcher(String targetUrl)
- {
- String[] classpath = {
- "lib/apache-camel/xstream*",
- "lib/google-gson/gson*",
- };
-
- DuccEventHttpDispatcher ret = null;
- try {
- ClassManager cm = new ClassManager(classpath);
- ret = (DuccEventHttpDispatcher) cm.construct("org.apache.uima.ducc.transport.dispatcher.DuccEventHttpDispatcher", new Object[] {targetUrl});
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return ret;
- }
/**
* Standard init for all except the Service calls that are sent to the SM
@@ -349,7 +329,6 @@ public abstract class CliBase
String targetUrl = DuccUiUtilities.dispatchUrl(servlet);
- // dispatcher = makeDispatcher(targetUrl);
dispatcher = DispatcherFactory.create(targetUrl);
init_done = true;
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DispatcherFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DispatcherFactory.java?rev=1683146&r1=1683145&r2=1683146&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DispatcherFactory.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DispatcherFactory.java Tue Jun 2 17:36:02 2015
@@ -18,7 +18,7 @@
*/
package org.apache.uima.ducc.cli;
-import org.apache.uima.ducc.transport.dispatcher.DuccEventHttpDispatcher;
+import org.apache.uima.ducc.transport.dispatcher.DuccEventHttpDispatcherCl;
import org.apache.uima.ducc.transport.dispatcher.IDuccEventDispatcher;
public class DispatcherFactory {
@@ -26,7 +26,7 @@ public class DispatcherFactory {
public static IDuccEventDispatcher create(Object specs) throws Exception {
IDuccEventDispatcher retVal = null;
String targetUrl = (String) specs;
- retVal = new DuccEventHttpDispatcher(targetUrl);
+ retVal = new DuccEventHttpDispatcherCl(targetUrl, -1);
return retVal;
}
}
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccMonitor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccMonitor.java?rev=1683146&r1=1683145&r2=1683146&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccMonitor.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccMonitor.java Tue Jun 2 17:36:02 2015
@@ -24,19 +24,18 @@ import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
-
-// import org.apache.commons.cli.CommandLine;
-// import org.apache.commons.cli.CommandLineParser;
-// import org.apache.commons.cli.HelpFormatter;
-// import org.apache.commons.cli.Options;
-// import org.apache.commons.cli.PosixParser;
import org.apache.uima.ducc.cli.IUiOptions.UiOption;
import org.apache.uima.ducc.common.json.MonitorInfo;
import org.apache.uima.ducc.common.utils.DuccPropertiesResolver;
import org.apache.uima.ducc.common.utils.SynchronizedSimpleDateFormat;
import org.apache.uima.ducc.common.utils.Utils;
-import org.apache.uima.ducc.transport.dispatcher.DuccEventHttpDispatcher;
+import org.apache.uima.ducc.transport.dispatcher.DuccEventHttpDispatcherCl;
import org.apache.uima.ducc.transport.event.IDuccContext.DuccContext;
+// import org.apache.commons.cli.CommandLine;
+// import org.apache.commons.cli.CommandLineParser;
+// import org.apache.commons.cli.HelpFormatter;
+// import org.apache.commons.cli.Options;
+// import org.apache.commons.cli.PosixParser;
public abstract class DuccMonitor {
@@ -346,7 +345,7 @@ public abstract class DuccMonitor {
debug(urlString);
// Poll until finished
while (flag_observer.get()) {
- DuccEventHttpDispatcher dispatcher = new DuccEventHttpDispatcher(urlString, urlTimeout);
+ DuccEventHttpDispatcherCl dispatcher = new DuccEventHttpDispatcherCl(urlString, urlTimeout);
MonitorInfo monitorInfo = (MonitorInfo) dispatcher.dispatchJson(MonitorInfo.class);
// String json = getSingleLineStatus(urlString);
// if (json != null) {
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOneLauncher.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOneLauncher.java?rev=1683146&r1=1683145&r2=1683146&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOneLauncher.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOneLauncher.java Tue Jun 2 17:36:02 2015
@@ -754,13 +754,13 @@ public class AllInOneLauncher extends Cl
mh.frameworkTrace(cid, mid, "exit");
}
- private void addArg(ArrayList<String> cmdLine, String arg) {
- String mid = "addArg";
- mh.frameworkTrace(cid, mid, "enter");
- cmdLine.add(arg);
- mh.frameworkDebug(cid, mid, arg);
- mh.frameworkTrace(cid, mid, "exit");
- }
+// private void addArg(ArrayList<String> cmdLine, String arg) {
+// String mid = "addArg";
+// mh.frameworkTrace(cid, mid, "enter");
+// cmdLine.add(arg);
+// mh.frameworkDebug(cid, mid, arg);
+// mh.frameworkTrace(cid, mid, "exit");
+// }
/*
* Options that AllInOne needs
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/BaseHttpDispatcher.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/BaseHttpDispatcher.java?rev=1683146&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/BaseHttpDispatcher.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/BaseHttpDispatcher.java Tue Jun 2 17:36:02 2015
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.ducc.transport.dispatcher;
+
+
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.apache.uima.ducc.common.exception.DuccRuntimeException;
+import org.apache.uima.ducc.transport.event.DuccEvent;
+/**
+ * Implementation of the HTTP based dispatcher. Uses commons HTTPClient for
+ * messaging. The body of each message is converted to a String (xml format).
+ * Default socket timeout is 30 minutes.
+ *
+ */
+/**
+ * Implementation of the HTTP based dispatcher. Uses commons HTTPClient for
+ * messaging. The body of each message is converted to a String (xml format).
+ * Default socket timeout is 30 minutes.
+ *
+ */
+public abstract class BaseHttpDispatcher
+ implements IDuccEventDispatcher
+{
+ String targetEndpoint;
+
+ int socketTimeout = 0; // no timeout
+
+ public BaseHttpDispatcher( String targetEndpoint, int timeout)
+ throws Exception
+ {
+ this.targetEndpoint = targetEndpoint;
+ // System.out.println("ENDPOINT: " + targetEndpoint);
+ if ( timeout == -1 ) {
+ String st = System.getProperty("ducc.cli.httpclient.sotimeout");
+ if (st != null ) {
+ socketTimeout = Integer.parseInt(st);
+ }
+ } else {
+ socketTimeout = timeout;
+ }
+ }
+
+ abstract String toXml(Object ev) throws Exception;
+
+ abstract Object fromXml(String str) throws Exception;
+
+ public String dispatch(String outgoing, String content_type)
+ throws Exception
+ {
+
+ // String serBody = XStreamUtils.marshall(duccEvent);
+ // String serBody = toXml(duccEvent);
+
+ URL url = new URL(targetEndpoint);
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ if ( outgoing != null ) { // if not null, we POST. GET is default.
+ //System.out.println(targetEndpoint + " using POST");
+ //System.out.println("-------------- POST body ---------------");
+ //System.out.println(outgoing);
+ //System.out.println("----- end ---- POST body ---------------");
+ conn.setRequestProperty("Content-Type", content_type);
+ conn.setDoOutput(true); // post
+ // conn.setRequestProperty("Content-Type", "text/xml");
+ OutputStream postout = conn.getOutputStream();
+ postout.write(outgoing.getBytes());
+ postout.close();
+ } else {
+ // System.out.println(targetEndpoint + " using GET");
+ }
+
+ int status = conn.getResponseCode(); // this will fire the connection
+
+ if ( status == 200 ) {
+ // System.out.println("Response headers:");
+ //Map<String, List<String>> headers = conn.getHeaderFields();
+ //for ( String s : headers.keySet() ) {
+ //List<String> values = headers.get(s);
+ // System.out.print(" " + s + ": ");
+ // for ( String v : values ) System.out.print(v + " ");
+ // System.out.println("\n");
+
+ //if ( (s != null ) && s.equals("ContentType") ) { // nullkey! its the HTTP/1.1 200 OK header which is un-named
+
+ //}
+ //}
+
+
+ InputStream content = conn.getInputStream();
+ StringBuffer sb = new StringBuffer();
+ byte[] slice = new byte[4096];
+ int bytes_read = 0;
+ BufferedInputStream bis = new BufferedInputStream(content);
+ while ( (bytes_read = bis.read(slice, 0, slice.length)) != -1 ) {
+ sb.append(new String(slice, 0, bytes_read));
+ }
+ content.close();
+
+ String response = sb.toString();
+ // System.out.println("Response: " + response);
+
+ return response;
+ } else {
+ String body = conn.getResponseMessage(); // getContent tends to throw if status is an error status and there is no body
+ //System.out.println("BODY from failed HTTP request:");
+ //System.out.println("-------------- POST body ---------------");
+ //System.out.println(body);
+ //System.out.println("----- fail --- POST body ---------------");
+
+ throw new DuccRuntimeException("Ducc Unable to Process Request. Http Response Code: " + status + ". Ducc Service (OR) Returned Exception:",new Exception(body));
+ }
+ }
+
+ public DuccEvent dispatchAndWaitForDuccReply(DuccEvent duccEvent)
+ throws Exception
+ {
+ String serBody = null;
+ try{
+ serBody = toXml(duccEvent);
+ String response = dispatch(serBody, "text/xml");
+ return (DuccEvent) fromXml(response);
+ } catch ( Throwable t ) {
+ t.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * Must call this if done using this class
+ */
+ public void close() {
+ //if ( method != null ) {
+ // method.releaseConnection();
+ //}
+ }
+
+}
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/DuccEventHttpDispatcher.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/DuccEventHttpDispatcher.java?rev=1683146&r1=1683145&r2=1683146&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/DuccEventHttpDispatcher.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/DuccEventHttpDispatcher.java Tue Jun 2 17:36:02 2015
@@ -19,16 +19,12 @@
package org.apache.uima.ducc.transport.dispatcher;
-import java.io.BufferedInputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-
-import org.apache.uima.ducc.common.exception.DuccRuntimeException;
import org.apache.uima.ducc.transport.event.DuccEvent;
import org.apache.uima.ducc.transport.event.SubmitJobDuccEvent;
import org.apache.uima.ducc.transport.event.SubmitJobReplyDuccEvent;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.xml.DomDriver;
/**
* Implementation of the HTTP based dispatcher. Uses commons HTTPClient for
* messaging. The body of each message is converted to a String (xml format).
@@ -41,175 +37,42 @@ import org.apache.uima.ducc.transport.ev
* Default socket timeout is 30 minutes.
*
*/
-public class DuccEventHttpDispatcher implements IDuccEventDispatcher {
+public class DuccEventHttpDispatcher
+ extends BaseHttpDispatcher
+ implements IDuccEventDispatcher
+{
+ String targetEndpoint;
- private ClassManager classManager = null;
- private String targetEndpoint;
-
- String[] classpath = {
- "lib/apache-camel/xstream*",
- "lib/google-gson/gson*",
- };
-
int socketTimeout = 0; // no timeout
public DuccEventHttpDispatcher( String targetEndpoint )
throws Exception
{
- this(targetEndpoint, -1);
+ super(targetEndpoint, -1);
}
-
- public DuccEventHttpDispatcher( String targetEndpoint, int timeout )
+
+ public DuccEventHttpDispatcher( String targetEndpoint, int timeout)
throws Exception
{
- this.targetEndpoint = targetEndpoint;
- // System.out.println("ENDPOINT: " + targetEndpoint);
- if ( timeout == -1 ) {
- String st = System.getProperty("ducc.cli.httpclient.sotimeout");
- if (st != null ) {
- socketTimeout = Integer.parseInt(st);
- }
- } else {
- socketTimeout = timeout;
- }
-
- classManager = new ClassManager(classpath);
+ super(targetEndpoint, timeout);
}
String toXml(Object ev)
throws Exception
{
- // DomDriver dd = new DomDriver();
-
- Object dd_obj = classManager.construct("com.thoughtworks.xstream.io.xml.DomDriver", new Object[] {null});
-
- // XStream xStream = new XStream(dd);
- Object xStream_obj = classManager.construct("com.thoughtworks.xstream.XStream", new Object[] {dd_obj});
-
- // return xStream.toXML(ev);
- return (String) classManager.invoke(xStream_obj, "toXML", new Object[] {ev});
+ DomDriver dd = new DomDriver();
+ XStream xStream = new XStream(dd);
+ return xStream.toXML(ev);
}
Object fromXml(String str)
throws Exception
{
- // DomDriver dd = new DomDriver();
- Object dd_obj = classManager.construct("com.thoughtworks.xstream.io.xml.DomDriver", new Object[] {null});
-
- // XStream xStream = new XStream(dd);
- Object xStream_obj = classManager.construct("com.thoughtworks.xstream.XStream", new Object[] {dd_obj});
-
- // return xStream.fromXML(str);
- return classManager.invoke(xStream_obj, "fromXML", new Object[] {str});
- }
-
- public String dispatch(String outgoing, String content_type)
- throws Exception
- {
-
- // String serBody = XStreamUtils.marshall(duccEvent);
- // String serBody = toXml(duccEvent);
-
- URL url = new URL(targetEndpoint);
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- if ( outgoing != null ) { // if not null, we POST. GET is default.
- //System.out.println(targetEndpoint + " using POST");
- //System.out.println("-------------- POST body ---------------");
- //System.out.println(outgoing);
- //System.out.println("----- end ---- POST body ---------------");
- conn.setRequestProperty("Content-Type", content_type);
- conn.setDoOutput(true); // post
- // conn.setRequestProperty("Content-Type", "text/xml");
- OutputStream postout = conn.getOutputStream();
- postout.write(outgoing.getBytes());
- postout.close();
- } else {
- // System.out.println(targetEndpoint + " using GET");
- }
-
- int status = conn.getResponseCode(); // this will fire the connection
-
- if ( status == 200 ) {
- // System.out.println("Response headers:");
- //Map<String, List<String>> headers = conn.getHeaderFields();
- //for ( String s : headers.keySet() ) {
- //List<String> values = headers.get(s);
- // System.out.print(" " + s + ": ");
- // for ( String v : values ) System.out.print(v + " ");
- // System.out.println("\n");
-
- //if ( (s != null ) && s.equals("ContentType") ) { // nullkey! its the HTTP/1.1 200 OK header which is un-named
-
- //}
- //}
-
-
- InputStream content = conn.getInputStream();
- StringBuffer sb = new StringBuffer();
- byte[] slice = new byte[4096];
- int bytes_read = 0;
- BufferedInputStream bis = new BufferedInputStream(content);
- while ( (bytes_read = bis.read(slice, 0, slice.length)) != -1 ) {
- sb.append(new String(slice, 0, bytes_read));
- }
- content.close();
-
- String response = sb.toString();
- // System.out.println("Response: " + response);
-
- return response;
- } else {
- String body = conn.getResponseMessage(); // getContent tends to throw if status is an error status and there is no body
- //System.out.println("BODY from failed HTTP request:");
- //System.out.println("-------------- POST body ---------------");
- //System.out.println(body);
- //System.out.println("----- fail --- POST body ---------------");
-
- throw new DuccRuntimeException("Ducc Unable to Process Request. Http Response Code: " + status + ". Ducc Service (OR) Returned Exception:",new Exception(body));
- }
- }
-
- public DuccEvent dispatchAndWaitForDuccReply(DuccEvent duccEvent)
- throws Exception
- {
- String serBody = null;
- try{
- serBody = toXml(duccEvent);
- String response = dispatch(serBody, "text/xml");
- return (DuccEvent) fromXml(response);
- } catch ( Throwable t ) {
- t.printStackTrace();
- }
- return null;
- }
-
- Object fromJson(String str, Class<?> cl)
- throws Exception
- {
- // DomDriver dd = new Gson
- Object gson_obj = classManager.construct("com.google.gson.Gson");
-
- // return xStream.fromXML(targetToUnmarshall);
- return classManager.invoke(gson_obj, "fromJson", new Object[] {str, cl});
+ DomDriver dd = new DomDriver();
+ XStream xStream = new XStream(dd);
+ return xStream.fromXML(str);
}
-
- public Object dispatchJson(Class<?> cl)
- throws Exception
- {
- // no body, dispatch will use GET
- String response = dispatch(null, "application/json"); // rfc4627 - json mime type
- return fromJson(response, cl);
- }
-
- /**
- * Must call this if done using this class
- */
- public void close() {
- //if ( method != null ) {
- // method.releaseConnection();
- //}
- }
public static void main(String[] args) {
try {
DuccEventHttpDispatcher dispatcher =
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/DuccEventHttpDispatcherCl.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/DuccEventHttpDispatcherCl.java?rev=1683146&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/DuccEventHttpDispatcherCl.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/dispatcher/DuccEventHttpDispatcherCl.java Tue Jun 2 17:36:02 2015
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.ducc.transport.dispatcher;
+
+
+import org.apache.uima.ducc.transport.event.DuccEvent;
+import org.apache.uima.ducc.transport.event.SubmitJobDuccEvent;
+import org.apache.uima.ducc.transport.event.SubmitJobReplyDuccEvent;
+/**
+ * Implementation of the HTTP based dispatcher. Uses commons HTTPClient for
+ * messaging. The body of each message is converted to a String (xml format).
+ * Default socket timeout is 30 minutes.
+ *
+ */
+/**
+ * Implementation of the HTTP based dispatcher. Uses commons HTTPClient for
+ * messaging. The body of each message is converted to a String (xml format).
+ * Default socket timeout is 30 minutes.
+ *
+ */
+public class DuccEventHttpDispatcherCl
+ extends BaseHttpDispatcher
+ implements IDuccEventDispatcher {
+
+ private ClassManager classManager = null;
+
+ String[] classpath = {
+ "lib/apache-camel/xstream*",
+ "lib/google-gson/gson*",
+ };
+
+ int socketTimeout = 0; // no timeout
+
+ public DuccEventHttpDispatcherCl( String targetEndpoint )
+ throws Exception
+ {
+ this(targetEndpoint, -1);
+ }
+
+ public DuccEventHttpDispatcherCl( String targetEndpoint, int timeout )
+ throws Exception
+ {
+ super(targetEndpoint, timeout);
+ classManager = new ClassManager(classpath);
+ }
+
+ String toXml(Object ev)
+ throws Exception
+ {
+ // DomDriver dd = new DomDriver();
+
+ Object dd_obj = classManager.construct("com.thoughtworks.xstream.io.xml.DomDriver", new Object[] {null});
+
+ // XStream xStream = new XStream(dd);
+ Object xStream_obj = classManager.construct("com.thoughtworks.xstream.XStream", new Object[] {dd_obj});
+
+ // return xStream.toXML(ev);
+ return (String) classManager.invoke(xStream_obj, "toXML", new Object[] {ev});
+ }
+
+ Object fromXml(String str)
+ throws Exception
+ {
+ // DomDriver dd = new DomDriver();
+ Object dd_obj = classManager.construct("com.thoughtworks.xstream.io.xml.DomDriver", new Object[] {null});
+
+ // XStream xStream = new XStream(dd);
+ Object xStream_obj = classManager.construct("com.thoughtworks.xstream.XStream", new Object[] {dd_obj});
+
+ // return xStream.fromXML(str);
+ return classManager.invoke(xStream_obj, "fromXML", new Object[] {str});
+ }
+
+ Object fromJson(String str, Class<?> cl)
+ throws Exception
+ {
+ // DomDriver dd = new Gson
+ Object gson_obj = classManager.construct("com.google.gson.Gson");
+
+ // return xStream.fromXML(targetToUnmarshall);
+ return classManager.invoke(gson_obj, "fromJson", new Object[] {str, cl});
+ }
+
+
+ public Object dispatchJson(Class<?> cl)
+ throws Exception
+ {
+ // no body, dispatch will use GET
+ String response = dispatch(null, "application/json"); // rfc4627 - json mime type
+ return fromJson(response, cl);
+ }
+
+ /**
+ * Must call this if done using this class
+ */
+ public void close() {
+ //if ( method != null ) {
+ // method.releaseConnection();
+ //}
+ }
+ public static void main(String[] args) {
+ try {
+ DuccEventHttpDispatcherCl dispatcher =
+ new DuccEventHttpDispatcherCl("http://"+args[0]+":19988/or",1000*4);
+ SubmitJobDuccEvent duccEvent = new SubmitJobDuccEvent(null, 1);
+ DuccEvent event = dispatcher.dispatchAndWaitForDuccReply(duccEvent);
+ if ( event instanceof SubmitJobReplyDuccEvent ) {
+ System.out.println("Client received SubmitJobReplyDuccEvent");
+ }
+ } catch( Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/common/IDuccJobDeployment.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/common/IDuccJobDeployment.java?rev=1683146&r1=1683145&r2=1683146&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/common/IDuccJobDeployment.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/common/IDuccJobDeployment.java Tue Jun 2 17:36:02 2015
@@ -23,6 +23,7 @@ import java.util.List;
import org.apache.uima.ducc.common.utils.id.DuccId;
import org.apache.uima.ducc.transport.cmdline.ICommandLine;
+import org.apache.uima.ducc.transport.cmdline.JavaCommandLine;
public interface IDuccJobDeployment extends Serializable {
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/common/JobManagerStateReconciler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/common/JobManagerStateReconciler.java?rev=1683146&r1=1683145&r2=1683146&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/common/JobManagerStateReconciler.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/common/JobManagerStateReconciler.java Tue Jun 2 17:36:02 2015
@@ -22,7 +22,6 @@ import java.util.Map;
import org.apache.uima.ducc.common.utils.id.DuccId;
import org.apache.uima.ducc.transport.cmdline.ICommandLine;
-import org.apache.uima.ducc.transport.event.common.IDuccWork;
/**