You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by cw...@apache.org on 2018/07/31 14:02:40 UTC
svn commit: r1837147 -
/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/protocol/builtin/DefaultServiceProtocolHandler.java
Author: cwiklik
Date: Tue Jul 31 14:02:40 2018
New Revision: 1837147
URL: http://svn.apache.org/viewvc?rev=1837147&view=rev
Log:
UIMA-5821 Modified to serialize Exception object into byte[] for the JD
Modified:
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/protocol/builtin/DefaultServiceProtocolHandler.java
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/protocol/builtin/DefaultServiceProtocolHandler.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/protocol/builtin/DefaultServiceProtocolHandler.java?rev=1837147&r1=1837146&r2=1837147&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/protocol/builtin/DefaultServiceProtocolHandler.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/protocol/builtin/DefaultServiceProtocolHandler.java Tue Jul 31 14:02:40 2018
@@ -18,7 +18,9 @@
*/
package org.apache.uima.ducc.ps.service.protocol.builtin;
+import java.io.ByteArrayOutputStream;
import java.io.InvalidClassException;
+import java.io.ObjectOutputStream;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
@@ -249,7 +251,19 @@ public class DefaultServiceProtocolHandl
}
if ( Objects.nonNull(errorAsString ) ) {
IMetaTask mc = transaction.getMetaTask();
- mc.setUserSpaceException(errorAsString);
+ // the ducc.deploy.JpType is only present for jobs. If not specified
+ // we return stringified exception to the client. The JD expects
+ // Java Exception object for its error handling
+ if ( Objects.isNull(System.getProperty("ducc.deploy.JpType")) ) {
+
+ mc.setUserSpaceException(errorAsString);
+ } else {
+ logger.log(Level.INFO, "Sending Exception to JD:\n" +
+ ((Exception)processResult.getExceptionObject()));
+ // JD expects serialized exception as byte[]
+ mc.setUserSpaceException(serializeError(processResult.getExceptionObject()));
+ }
+
}
// send END Request
@@ -289,7 +303,24 @@ public class DefaultServiceProtocolHandl
return String.valueOf(Thread.currentThread().getId());
}
-
+ private byte[] serializeError(Throwable t) throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+
+ try {
+ oos.writeObject(t);
+ } catch (Exception e) {
+ try {
+ logger.log(Level.WARNING, "Unable to Serialize "+t.getClass().getName()+" - Will Stringify It Instead");
+
+ } catch( Exception ee) {}
+ throw e;
+ } finally {
+ oos.close();
+ }
+
+ return baos.toByteArray();
+ }
private void delegateStop() {
service.quiesceAndStop();
}