You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by bu...@apache.org on 2016/07/21 12:57:57 UTC
svn commit: r1753681 - in /uima/uima-as/trunk: src/main/scripts/
uimaj-as-core/src/main/java/org/apache/uima/aae/deploymentDescriptor/
uimaj-as-core/src/main/resources/
uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/service/
Author: burn
Date: Thu Jul 21 12:57:57 2016
New Revision: 1753681
URL: http://svn.apache.org/viewvc?rev=1753681&view=rev
Log:
UIMA-5022 Ensure that dd2spring errors are not hidden when Saxon calls exit; fix the confusing import-failed one
Modified:
uima/uima-as/trunk/src/main/scripts/dd2spring.xsl
uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/deploymentDescriptor/XsltImportByName.java
uima/uima-as/trunk/uimaj-as-core/src/main/resources/uimaee_messages.properties
uima/uima-as/trunk/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/service/Dd2spring.java
Modified: uima/uima-as/trunk/src/main/scripts/dd2spring.xsl
URL: http://svn.apache.org/viewvc/uima/uima-as/trunk/src/main/scripts/dd2spring.xsl?rev=1753681&r1=1753680&r2=1753681&view=diff
==============================================================================
--- uima/uima-as/trunk/src/main/scripts/dd2spring.xsl (original)
+++ uima/uima-as/trunk/src/main/scripts/dd2spring.xsl Thu Jul 21 12:57:57 2016
@@ -2402,7 +2402,12 @@
<xsl:sequence select="document($importNode/@location)"/>
</xsl:when>
<xsl:when test="$importNode/@name">
- <xsl:sequence select="document(x1:resolveByName($importNode/@name))"/>
+ <xsl:variable name="result" select="x1:resolveByName($importNode/@name)"/>
+ <xsl:if test="not($result)">
+ <xsl:sequence select=
+ "f:msgWithLineNumber('ERROR', ('ERROR cannot import by', $importNode/@name), $importNode)"/>
+ </xsl:if>
+ <xsl:sequence select="document($result)"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select=
@@ -2727,7 +2732,7 @@
<xsl:if test="not($result)">
<xsl:sequence select="f:msgWithLineNumber(
'ERROR',
- ('ERROR cannot load delegate descriptor with key', $key),
+ ('ERROR cannot load delegate descriptor with', $key),
$local_ae_descriptor)"/>
</xsl:if>
<xsl:sequence select="$result"/>
@@ -3023,16 +3028,24 @@
</xsl:for-each>
</xsl:function>
+ <!-- Terminate processing on first error -->
<xsl:function name="f:msgWithLineNumber">
<xsl:param name="kind"/>
<xsl:param name="msg"/> <!-- can be multi-element sequence -->
<xsl:param name="node"/>
- <xsl:message>
+ <xsl:variable name="yesno">
+ <xsl:choose>
+ <xsl:when test="$kind eq 'ERROR'">
+ <xsl:sequence select="'yes'"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:sequence select="'no'"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:message terminate="{$yesno}">
*** <xsl:sequence select="concat($kind,':')"/> line-number: <xsl:sequence select="saxon:line-number($node)"/>
<xsl:sequence select="$msg"/>
</xsl:message>
- <!-- xsl:if test="$kind eq 'ERROR'">
- <xsl:sequence select="error()"/>
- </xsl:if-->
</xsl:function>
</xsl:stylesheet>
Modified: uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/deploymentDescriptor/XsltImportByName.java
URL: http://svn.apache.org/viewvc/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/deploymentDescriptor/XsltImportByName.java?rev=1753681&r1=1753680&r2=1753681&view=diff
==============================================================================
--- uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/deploymentDescriptor/XsltImportByName.java (original)
+++ uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/deploymentDescriptor/XsltImportByName.java Thu Jul 21 12:57:57 2016
@@ -21,15 +21,19 @@ package org.apache.uima.aae.deploymentDe
import org.apache.uima.UIMAFramework;
import org.apache.uima.aae.UIMAEE_Constants;
-import org.apache.uima.aae.controller.UimacppServiceController;
import org.apache.uima.resource.ResourceManager;
import org.apache.uima.resource.metadata.Import;
import org.apache.uima.resource.metadata.impl.Import_impl;
import org.apache.uima.util.InvalidXMLException;
import org.apache.uima.util.Level;
+/*
+ * Used by dd2spring.xsl
+ *
+ * UIMA-5022 Return null on error so xslt can report the failure
+ */
public class XsltImportByName {
- private static final Class CLASS_NAME = XsltImportByName.class;
+ private static final Class<XsltImportByName> CLASS_NAME = XsltImportByName.class;
public static String resolveByName(String input) {
ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager();
@@ -38,12 +42,12 @@ public class XsltImportByName {
try {
return theImport.findAbsoluteUrl(resourceManager).toExternalForm();
} catch (InvalidXMLException e) {
- if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.WARNING)) {
- UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, XsltImportByName.class.getName(),
+ if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.SEVERE)) {
+ UIMAFramework.getLogger(CLASS_NAME).logrb(Level.SEVERE, XsltImportByName.class.getName(),
"resolveByName", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
- "UIMAEE_exception__WARNING", e);
+ "UIMAEE_exception__SEVERE", e.toString());
}
- return "ERROR converting import by name to absolute path";
+ return null;
}
}
Modified: uima/uima-as/trunk/uimaj-as-core/src/main/resources/uimaee_messages.properties
URL: http://svn.apache.org/viewvc/uima/uima-as/trunk/uimaj-as-core/src/main/resources/uimaee_messages.properties?rev=1753681&r1=1753680&r2=1753681&view=diff
==============================================================================
--- uima/uima-as/trunk/uimaj-as-core/src/main/resources/uimaee_messages.properties (original)
+++ uima/uima-as/trunk/uimaj-as-core/src/main/resources/uimaee_messages.properties Thu Jul 21 12:57:57 2016
@@ -20,6 +20,7 @@ UIMAEE_service_id_INFO = Starting Uima E
UIMAEE_service_exception_WARNING = Service: {0} Runtime Exception
UIMAEE_service_warmup_failed_WARNING = Service: {0} Failed While Warming the Pipeline
UIMAEE_exception__WARNING =
+UIMAEE_exception__SEVERE = {0}
UIMAEE_invalid_cpc_request__INFO = Invalid {0} Request. Analysis Engine Instance Not Found For Thread:
UIMAEE_primary_cas_pool_init__CONFIG = Primary CAS Pool Size: {0} Context: {1} Initial Cas Heap Size:{2} cells. Supports Incoming Service Requests.
UIMAEE_secondary_cas_pool_init__CONFIG = Secondary CAS Pool Size: {0} Context: {1}. Supports Incoming Replies from Delegates.
Modified: uima/uima-as/trunk/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/service/Dd2spring.java
URL: http://svn.apache.org/viewvc/uima/uima-as/trunk/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/service/Dd2spring.java?rev=1753681&r1=1753680&r2=1753681&view=diff
==============================================================================
--- uima/uima-as/trunk/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/service/Dd2spring.java (original)
+++ uima/uima-as/trunk/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/service/Dd2spring.java Thu Jul 21 12:57:57 2016
@@ -19,11 +19,8 @@
package org.apache.uima.adapter.jms.service;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
-import java.io.PrintStream;
-import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
@@ -42,24 +39,17 @@ public class Dd2spring {
private ClassLoader saxonClassLoader;
- private boolean testMode = false;
-
- public void setTestMode() {
- testMode = true;
- }
-
/**
* Test driver arg = path_to_source, path_to_xslt, path_to_saxon_jar, uima-as-debug flag
*
* @param args
- * @throws Dd2springException
*/
- public static void main(String[] args) throws Dd2springException {
+ public static void main(String[] args) {
new Dd2spring().convertDd2Spring(args[0], args[1], args[2], args[3]);
}
public File convertDd2Spring(String ddFilePath, String dd2SpringXsltFilePath,
- String saxonClasspath, String uimaAsDebug) throws Dd2springException {
+ String saxonClasspath, String uimaAsDebug) {
URL urlForSaxonClassPath;
try {
@@ -84,8 +74,10 @@ public class Dd2spring {
return null;
}
- String errData = convertDd2Spring(tempFile, ddFilePath, dd2SpringXsltFilePath, urlForSaxonClassPath);
- System.err.print(errData);
+ // UIMA-5022 No longer capture output and scan for "ERROR: " as that hid
+ // errors that Saxon followed by calling exit!
+ // Processing now terminates on the first error.
+ convertDd2Spring(tempFile, ddFilePath, dd2SpringXsltFilePath, urlForSaxonClassPath);
// delete the file when terminating if
// a) uimaAsDebug is not specified (is null) or
@@ -93,30 +85,22 @@ public class Dd2spring {
if (null == uimaAsDebug || uimaAsDebug.equals("")) {
tempFile.deleteOnExit();
}
-
- // scan output for "ERROR: " and throw if found
- // https://issues.apache.org/jira/browse/UIMA-4213
- if (errData.contains("*** ERROR: ")) {
- if (testMode) {
- System.out.println("DD2Spring transformation had one or more errors; the tempFile created was" + tempFile.getAbsolutePath());
- } else {
- throw new Dd2springException("DD2spring transformation had one or more errors; the tempFile created was" + tempFile.getAbsolutePath());
- }
- }
+
return tempFile;
}
/**
- *
+ *
+ * @param tempFile
+ * file to hold generated Spring from dd2spring transform
* @param ddFilePath
* file path to UIMA Deployment Descriptor - passed to saxon
* @param dd2SpringXsltFilePath
* file path to dd2spring.xslt transformation file - passed to saxon
* @param saxonClasspathURL
* classpath for saxon8.jar
- * @return temp file with generated Spring from dd2spring transform
*/
- public String convertDd2Spring(File tempFile, String ddFilePath, String dd2SpringXsltFilePath,
+ public void convertDd2Spring(File tempFile, String ddFilePath, String dd2SpringXsltFilePath,
URL saxonClasspathURL) {
if (null == saxonClassLoader) {
@@ -129,99 +113,84 @@ public class Dd2spring {
}
Class<?> mainStartClass = null;
try {
+ mainStartClass = Class.forName("net.sf.saxon.Transform", true, saxonClassLoader);
+ } catch (ClassNotFoundException e) {
+ System.err.println("Error - can't load Saxon jar from " + saxonClasspathURL
+ + " for dd2spring transformation.");
+ e.printStackTrace();
+ UIMAFramework.getLogger(THIS_CLASS).logrb(Level.CONFIG, THIS_CLASS.getName(),
+ "convertDD2Spring", JmsConstants.JMS_LOG_RESOURCE_BUNDLE,
+ "UIMA_dd2spring_saxon_missing_SEVERE");
+ return;
+ }
+
+ // args for saxon
+ // -l -s deployment_descriptor} -o output_file_path dd2spring.xsl_file_path <-x sax_parser_class>
+ // If a custom framework includes a custom XML parser we may also need a custom parser for Saxon,
+ // so check for the existence of a class with "_SAXParser" appended to the framework name.
+
+ List<String> argsForSaxon = new ArrayList<String>();
+ String uimaFrameworkClass = System.getProperty("uima.framework_impl");
+ if (uimaFrameworkClass != null) {
+ String saxonParserClass = uimaFrameworkClass + "_SAXParser";
try {
- mainStartClass = Class.forName("net.sf.saxon.Transform", true, saxonClassLoader);
+ ClassLoader.getSystemClassLoader().loadClass(saxonParserClass);
+ argsForSaxon.add("-x");
+ argsForSaxon.add(saxonParserClass);
} catch (ClassNotFoundException e) {
- System.err.println("Error - can't load Saxon jar from " + saxonClasspathURL
- + " for dd2spring transformation.");
- e.printStackTrace();
- UIMAFramework.getLogger(THIS_CLASS).logrb(Level.CONFIG, THIS_CLASS.getName(),
- "convertDD2Spring", JmsConstants.JMS_LOG_RESOURCE_BUNDLE,
- "UIMA_dd2spring_saxon_missing_SEVERE");
- return "";
- }
-
- // args for saxon
- // -l -s deployment_descriptor} -o output_file_path dd2spring.xsl_file_path <-x sax_parser_class>
- // If a custom framework includes a custom XML parser we may also need a custom parser for Saxon,
- // so check for the existence of a class with "_SAXParser" appended to the framework name.
-
- List<String> argsForSaxon = new ArrayList<String>();
- String uimaFrameworkClass = System.getProperty("uima.framework_impl");
- if (uimaFrameworkClass != null) {
- String saxonParserClass = uimaFrameworkClass + "_SAXParser";
- try {
- ClassLoader.getSystemClassLoader().loadClass(saxonParserClass);
- argsForSaxon.add("-x");
- argsForSaxon.add(saxonParserClass);
- } catch (ClassNotFoundException e) {
- // No parser clkass defined
- }
+ // No parser class defined
}
- argsForSaxon.add("-l"); // turn on line numbers
- argsForSaxon.add("-s"); // source file
- argsForSaxon.add(ddFilePath); // source file
- argsForSaxon.add("-o"); // output file
- argsForSaxon.add(tempFile.getAbsolutePath()); // output file
- argsForSaxon.add(dd2SpringXsltFilePath); // xslt transform to apply
-
- UIMAFramework.getLogger(THIS_CLASS).log(Level.INFO, "Saxon args: " + argsForSaxon);
-
- Method mainMethod = null;
- try {
- mainMethod = mainStartClass.getMethod("main", String[].class);
- } catch (SecurityException e) {
- e.printStackTrace();
- UIMAFramework.getLogger(THIS_CLASS).logrb(Level.CONFIG, THIS_CLASS.getName(),
- "convertDD2Spring", JmsConstants.JMS_LOG_RESOURCE_BUNDLE,
- "UIMA_dd2spring_security_exception_calling_saxon");
- return "";
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- UIMAFramework.getLogger(THIS_CLASS).logrb(Level.CONFIG, THIS_CLASS.getName(),
- "convertDD2Spring", JmsConstants.JMS_LOG_RESOURCE_BUNDLE,
- "UIMA_dd2spring_internal_error_calling_saxon");
- return "";
- }
- PrintStream savedErr = System.err;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- try {
- System.setErr(ps);
- mainMethod.invoke(null,
- new Object[] { argsForSaxon.toArray(new String[argsForSaxon.size()]) });
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- UIMAFramework.getLogger(THIS_CLASS).logrb(Level.CONFIG, THIS_CLASS.getName(),
- "convertDD2Spring", JmsConstants.JMS_LOG_RESOURCE_BUNDLE,
- "UIMA_dd2spring_internal_error_calling_saxon");
- ps.close();
- return baos.toString("UTF-8");
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- UIMAFramework.getLogger(THIS_CLASS).logrb(Level.CONFIG, THIS_CLASS.getName(),
- "convertDD2Spring", JmsConstants.JMS_LOG_RESOURCE_BUNDLE,
- "UIMA_dd2spring_internal_error_calling_saxon");
- ps.close();
- return baos.toString("UTF-8");
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- UIMAFramework.getLogger(THIS_CLASS).logrb(Level.CONFIG, THIS_CLASS.getName(),
- "convertDD2Spring", JmsConstants.JMS_LOG_RESOURCE_BUNDLE,
- "UIMA_dd2spring_internal_error_calling_saxon");
- ps.close();
- return baos.toString("UTF-8");
- } finally {
- System.setErr(savedErr);
- }
-
- ps.close();
- return baos.toString("UTF-8");
- } catch (UnsupportedEncodingException e) {
+ }
+ argsForSaxon.add("-l"); // turn on line numbers
+ argsForSaxon.add("-s"); // source file
+ argsForSaxon.add(ddFilePath); // source file
+ argsForSaxon.add("-o"); // output file
+ argsForSaxon.add(tempFile.getAbsolutePath()); // output file
+ argsForSaxon.add(dd2SpringXsltFilePath); // xslt transform to apply
+
+ UIMAFramework.getLogger(THIS_CLASS).log(Level.INFO, "Saxon args: " + argsForSaxon);
+
+ Method mainMethod = null;
+ try {
+ mainMethod = mainStartClass.getMethod("main", String[].class);
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ UIMAFramework.getLogger(THIS_CLASS).logrb(Level.CONFIG, THIS_CLASS.getName(),
+ "convertDD2Spring", JmsConstants.JMS_LOG_RESOURCE_BUNDLE,
+ "UIMA_dd2spring_security_exception_calling_saxon");
+ return;
+ } catch (NoSuchMethodException e) {
e.printStackTrace();
- return "";
+ UIMAFramework.getLogger(THIS_CLASS).logrb(Level.CONFIG, THIS_CLASS.getName(),
+ "convertDD2Spring", JmsConstants.JMS_LOG_RESOURCE_BUNDLE,
+ "UIMA_dd2spring_internal_error_calling_saxon");
+ return;
}
-
+
+ try {
+ mainMethod.invoke(null,
+ new Object[] { argsForSaxon.toArray(new String[argsForSaxon.size()]) });
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ UIMAFramework.getLogger(THIS_CLASS).logrb(Level.CONFIG, THIS_CLASS.getName(),
+ "convertDD2Spring", JmsConstants.JMS_LOG_RESOURCE_BUNDLE,
+ "UIMA_dd2spring_internal_error_calling_saxon");
+ return;
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ UIMAFramework.getLogger(THIS_CLASS).logrb(Level.CONFIG, THIS_CLASS.getName(),
+ "convertDD2Spring", JmsConstants.JMS_LOG_RESOURCE_BUNDLE,
+ "UIMA_dd2spring_internal_error_calling_saxon");
+ return;
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ UIMAFramework.getLogger(THIS_CLASS).logrb(Level.CONFIG, THIS_CLASS.getName(),
+ "convertDD2Spring", JmsConstants.JMS_LOG_RESOURCE_BUNDLE,
+ "UIMA_dd2spring_internal_error_calling_saxon");
+ return;
+ }
+
+ return;
}
}