You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by tw...@apache.org on 2008/03/20 13:56:31 UTC
svn commit: r639272 - in /incubator/uima/sandbox/trunk/SimpleServer/src:
main/java/org/apache/uima/simpleserver/
main/java/org/apache/uima/simpleserver/servlet/
test/java/org/apache/uima/simpleserver/test/
Author: twgoetz
Date: Thu Mar 20 05:56:30 2008
New Revision: 639272
URL: http://svn.apache.org/viewvc?rev=639272&view=rev
Log:
Jira UIMA-884:
- add ability to run without a result spec
- add test case for zero-config service
https://issues.apache.org/jira/browse/UIMA-884
Modified:
incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/Service.java
incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/servlet/SimpleServerServlet.java
incubator/uima/sandbox/trunk/SimpleServer/src/test/java/org/apache/uima/simpleserver/test/ServerTest.java
Modified: incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/Service.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/Service.java?rev=639272&r1=639271&r2=639272&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/Service.java (original)
+++ incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/Service.java Thu Mar 20 05:56:30 2008
@@ -44,6 +44,7 @@
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.resource.ResourceManager;
import org.apache.uima.resource.ResourceSpecifier;
+import org.apache.uima.simpleserver.config.ConfigFactory;
import org.apache.uima.simpleserver.config.Output;
import org.apache.uima.simpleserver.config.ServerSpec;
import org.apache.uima.simpleserver.config.TypeMap;
@@ -65,6 +66,8 @@
*/
public class Service {
+ private static final String noDescriptionProvided = "No description provided";
+
private static final Logger logger = UIMAFramework.getLogger(Service.class);
private AnalysisEngine ae = null;
@@ -72,7 +75,7 @@
private CAS cas = null;
private ServerSpec serviceSpec = null;
-
+
private ResultExtractor resultExtractor = null;
private volatile boolean initialized = false;
@@ -147,13 +150,18 @@
private void configure(File serviceSpecFile) throws IOException, SimpleServerException,
XmlException {
- this.serviceSpec = XmlConfigReader.readServerSpec(serviceSpecFile);
- validateResultSpec();
+ if (serviceSpecFile == null) {
+ this.serviceSpec = ConfigFactory.newServerSpec(noDescriptionProvided, noDescriptionProvided,
+ true);
+ } else {
+ this.serviceSpec = XmlConfigReader.readServerSpec(serviceSpecFile);
+ validateResultSpec();
+ }
this.initialized = true;
}
private final void logInitializationError() {
- //TODO: log which service could not be initialized!!!!!!!!!!!!!!!!!
+ // TODO: log which service could not be initialized!!!!!!!!!!!!!!!!!
SimpleServerException e = new SimpleServerException(
SimpleServerException.service_state_exception, new Object[] {});
getLogger().log(Level.SEVERE, "", e);
@@ -258,7 +266,7 @@
public Result process(String text) {
return process(text, null);
}
-
+
public ServerSpec getServiceSpec() {
return this.serviceSpec;
}
Modified: incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/servlet/SimpleServerServlet.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/servlet/SimpleServerServlet.java?rev=639272&r1=639271&r2=639272&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/servlet/SimpleServerServlet.java (original)
+++ incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/servlet/SimpleServerServlet.java Thu Mar 20 05:56:30 2008
@@ -46,7 +46,7 @@
public class SimpleServerServlet extends HttpServlet {
public static final String utf8 = "utf-8";
-
+
public static final String MODE_PARAMETER = "mode";
public static final String DEFAULT_CODE_PAGE = utf8;
@@ -239,8 +239,11 @@
}
protected boolean initServer() {
- File resultSpec = new File(this.baseWebappDirectory.getAbsoluteFile(),
- getInitParameter("ResultSpecFile"));
+ File resultSpec = null;
+ String resultSpecParamValue = getInitParameter("ResultSpecFile");
+ if (resultSpecParamValue != null) {
+ resultSpec = new File(this.baseWebappDirectory.getAbsoluteFile(), resultSpecParamValue);
+ }
String pearPath = getInitParameter("PearPath");
String descriptorPath = getInitParameter("DescriptorPath");
Modified: incubator/uima/sandbox/trunk/SimpleServer/src/test/java/org/apache/uima/simpleserver/test/ServerTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/SimpleServer/src/test/java/org/apache/uima/simpleserver/test/ServerTest.java?rev=639272&r1=639271&r2=639272&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/SimpleServer/src/test/java/org/apache/uima/simpleserver/test/ServerTest.java (original)
+++ incubator/uima/sandbox/trunk/SimpleServer/src/test/java/org/apache/uima/simpleserver/test/ServerTest.java Thu Mar 20 05:56:30 2008
@@ -76,6 +76,16 @@
}
JettyUtils.addServletWithMapping(server, uimaServlet, "/uima");
+ // Set up config-less UIMA servlet
+ SimpleServerServlet uimaNoConfigServlet = new SimpleServerServlet(true);
+ try {
+ uimaNoConfigServlet.init(descriptorFile, null);
+ } catch (ServletException e1) {
+ e1.printStackTrace();
+ assertTrue(false);
+ }
+ JettyUtils.addServletWithMapping(server, uimaNoConfigServlet, "/uima-no-config");
+
// Start the server
try {
server.start();
@@ -107,6 +117,19 @@
try {
HttpResponse response = HttpClientUtils.callGet(JettyUtils.getHost(server), JettyUtils
.getPort(server), "/uima?text=foo%20bar");
+ assertTrue(response.getStatusLine().getStatusCode() == HttpServletResponse.SC_OK);
+ System.out.println(HttpClientUtils.getResponseContent(response));
+ } catch (Exception e) {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ @Test
+ public void test2() {
+ try {
+ HttpResponse response = HttpClientUtils.callGet(JettyUtils.getHost(server), JettyUtils
+ .getPort(server), "/uima-no-config?text=foo%20bar");
assertTrue(response.getStatusLine().getStatusCode() == HttpServletResponse.SC_OK);
System.out.println(HttpClientUtils.getResponseContent(response));
} catch (Exception e) {