Author: cwiklik
Date: Tue Aug  8 19:42:46 2017
New Revision: 1804465

URL: http://svn.apache.org/viewvc?rev=1804465&view=rev
Log:
UIMA-5529 modified to serialize AnalysisEngineProcessException as string

Modified:
    
uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/DuccAbstractProcessContainer.java
    
uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaASProcessContainer.java
    
uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaProcessContainer.java

Modified: 
uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/DuccAbstractProcessContainer.java
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/DuccAbstractProcessContainer.java?rev=1804465&r1=1804464&r2=1804465&view=diff
==============================================================================
--- 
uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/DuccAbstractProcessContainer.java
 (original)
+++ 
uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/DuccAbstractProcessContainer.java
 Tue Aug  8 19:42:46 2017
@@ -21,6 +21,8 @@ package org.apache.uima.ducc.user.jp;
 import java.io.ByteArrayOutputStream;
 import java.io.DataOutputStream;
 import java.io.ObjectOutputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.net.InetAddress;
 import java.net.Socket;
 import java.util.HashMap;
@@ -50,7 +52,6 @@ public abstract class DuccAbstractProces
     protected abstract List<Properties>  doProcess(Object subject) throws 
Exception;
     protected  AnalysisEngineMetaData analysisEngineMetadata;
 
-       protected Throwable lastError = null;
     protected int scaleout=1;
     // Map to store DuccUimaSerializer instances. Each has affinity to a thread
        protected static Map<Long, DuccUimaSerializer> serializerMap =
@@ -155,7 +156,21 @@ public abstract class DuccAbstractProces
          }
      }
 
-    
+    protected String serializeAsString(Throwable t) throws Exception {
+        StringWriter sw = new StringWriter();
+        String serializedCause = "";
+        try {
+ 
+            t.printStackTrace(new PrintWriter(sw));
+            serializedCause =  sw.toString();
+        } catch (Throwable e) {
+                       e.printStackTrace();
+                       // Unable to serialize user Exception (not 
Serializable?)
+                       // Just send a simple msg telling user to check service 
log
+                       serializedCause = "Unable to Serialize User Exception - 
Please Check JP Log File For More Details";
+               }
+        return serializedCause;
+    }
     protected byte[] serialize(Throwable t) throws Exception {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream oos = new ObjectOutputStream(baos);

Modified: 
uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaASProcessContainer.java
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaASProcessContainer.java?rev=1804465&r1=1804464&r2=1804465&view=diff
==============================================================================
--- 
uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaASProcessContainer.java
 (original)
+++ 
uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaASProcessContainer.java
 Tue Aug  8 19:42:46 2017
@@ -115,14 +115,7 @@ public class UimaASProcessContainer  ext
                        return scaleout;
                }
        }
-       public byte[] getLastSerializedError() throws Exception {
 
-               if (lastError != null) {
-                       return serialize(lastError);
-               }
-               return null;
-
-       }
        /**
         * This method is called by each worker thread before entering
         * process loop in run(). Each work thread shares instance of
@@ -306,8 +299,7 @@ public class UimaASProcessContainer  ext
        public List<Properties> doProcess(Object xmi) throws Exception {
                CAS cas = uimaASClient.getCAS();   // fetch a new CAS from the 
client's Cas Pool
                try {
-                       // reset last error
-                       lastError = null;
+
                        // Use thread dedicated UimaSerializer to de-serialize 
the CAS
                        getUimaSerializer().deserializeCasFromXmi((String)xmi, 
cas);
 
@@ -353,12 +345,10 @@ public class UimaASProcessContainer  ext
                        }
 
                        return metricsList;
-               } catch( Throwable e ) {
-                       lastError = e;
+               } catch( Throwable t ) {
                        Logger logger = UIMAFramework.getLogger();
-                       logger.log(Level.WARNING, "UimaProcessContainer", e);
-                       e.printStackTrace();
-                       throw new AnalysisEngineProcessException();
+                       logger.log(Level.WARNING, "UimaProcessContainer", t);
+                       throw new RuntimeException(super.serializeAsString(t));
                } finally {
                        if ( cas != null) {
                                cas.release();

Modified: 
uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaProcessContainer.java
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaProcessContainer.java?rev=1804465&r1=1804464&r2=1804465&view=diff
==============================================================================
--- 
uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaProcessContainer.java
 (original)
+++ 
uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaProcessContainer.java
 Tue Aug  8 19:42:46 2017
@@ -21,6 +21,7 @@ package org.apache.uima.ducc.user.jp;
 
 
 import java.io.File;
+import java.io.PrintWriter;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -105,14 +106,6 @@ public class UimaProcessContainer extend
            scaleout = threadCount==null ? 1 : Integer.valueOf(threadCount);   
// Default to 1
            return scaleout;              
        }
-       public byte[] getLastSerializedError() throws Exception {
-
-               if (lastError != null) {
-                       return serialize(lastError);
-               }
-               return null;
-
-       }
 
        public int doInitialize(Properties props, String[] args) throws 
Exception {
                        return configureAndGetScaleout(args);
@@ -187,8 +180,6 @@ public class UimaProcessContainer extend
                latch.await();
                CAS cas = casPool.getCas();
                try {
-                       // reset last error
-                       lastError = null;
                        // deserialize the CAS
                        getUimaSerializer().deserializeCasFromXmi((String)xmi, 
cas);
 
@@ -218,14 +209,11 @@ public class UimaProcessContainer extend
                                                
String.valueOf(metrics.getNumProcessed()));
                                metricsList.add(p);
                        }
-                       
                        return metricsList;
-               } catch( Throwable e ) {
-                       lastError = e;
+               } catch( Throwable t ) {
                        Logger logger = UIMAFramework.getLogger();
-                       logger.log(Level.WARNING, "UimaProcessContainer", e);
-                       e.printStackTrace();
-                       throw new AnalysisEngineProcessException();
+                       logger.log(Level.WARNING, "UimaProcessContainer", t);
+                       throw new RuntimeException(super.serializeAsString(t));
                }
                finally {
                        if (ae != null) {


Reply via email to