Author: mattmann
Date: Thu Apr 26 23:17:41 2012
New Revision: 1331147
URL: http://svn.apache.org/viewvc?rev=1331147&view=rev
Log:
- apply patch from TIKA-901: Provide version number in tika-server contributed
by Ingo Renner
Added:
tika/trunk/tika-server/src/main/java/org/apache/tika/server/TikaVersion.java
tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaVersionTest.java
Modified:
tika/trunk/CHANGES.txt
tika/trunk/tika-server/src/main/java/org/apache/tika/server/TikaServerCli.java
Modified: tika/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/tika/trunk/CHANGES.txt?rev=1331147&r1=1331146&r2=1331147&view=diff
==============================================================================
--- tika/trunk/CHANGES.txt (original)
+++ tika/trunk/CHANGES.txt Thu Apr 26 23:17:41 2012
@@ -4,7 +4,7 @@ Release 1.2 - Current Development
* Tika's JAX-RS based Network server now is based on Apache CXF,
which is available in Maven Central and now allows the server
module to be packaged and included in our release
- (TIKA-593).
+ (TIKA-593, TIKA-901).
* Tika: parseToString now lets you specify the max string length
per-call, in addition to per-Tika-instance. (TIKA-870)
Modified:
tika/trunk/tika-server/src/main/java/org/apache/tika/server/TikaServerCli.java
URL:
http://svn.apache.org/viewvc/tika/trunk/tika-server/src/main/java/org/apache/tika/server/TikaServerCli.java?rev=1331147&r1=1331146&r2=1331147&view=diff
==============================================================================
---
tika/trunk/tika-server/src/main/java/org/apache/tika/server/TikaServerCli.java
(original)
+++
tika/trunk/tika-server/src/main/java/org/apache/tika/server/TikaServerCli.java
Thu Apr 26 23:17:41 2012
@@ -17,20 +17,24 @@
package org.apache.tika.server;
-import org.apache.commons.cli.*;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Options;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.cxf.binding.BindingFactoryManager;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxrs.JAXRSBindingFactory;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
-import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
+import org.apache.tika.Tika;
public class TikaServerCli {
private static final Log logger = LogFactory.getLog(TikaServerCli.class);
@@ -53,6 +57,7 @@ public class TikaServerCli {
}
logger.info("Starting Tikaserver
"+properties.getProperty("tikaserver.version"));
+ logger.info("Starting Tika Server " + new Tika().toString());
try {
Options options = getOptions();
@@ -70,9 +75,9 @@ public class TikaServerCli {
helpFormatter.printHelp("tikaserver", options);
System.exit(-1);
}
-
+
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
- sf.setResourceClasses(MetadataResource.class, TikaResource.class,
UnpackerResource.class);
+ sf.setResourceClasses(MetadataResource.class, TikaResource.class,
UnpackerResource.class, TikaVersion.class);
List providers = new ArrayList();
providers.add(new TarWriter());
@@ -81,6 +86,7 @@ public class TikaServerCli {
providers.add(new SingletonResourceProvider(new MetadataResource()));
providers.add(new SingletonResourceProvider(new TikaResource()));
providers.add(new SingletonResourceProvider(new UnpackerResource()));
+ providers.add(new SingletonResourceProvider(new TikaVersion()));
sf.setProviders(providers);
sf.setAddress("http://localhost:" + TikaServerCli.DEFAULT_PORT + "/");
BindingFactoryManager manager = sf.getBus().getExtension(
Added:
tika/trunk/tika-server/src/main/java/org/apache/tika/server/TikaVersion.java
URL:
http://svn.apache.org/viewvc/tika/trunk/tika-server/src/main/java/org/apache/tika/server/TikaVersion.java?rev=1331147&view=auto
==============================================================================
---
tika/trunk/tika-server/src/main/java/org/apache/tika/server/TikaVersion.java
(added)
+++
tika/trunk/tika-server/src/main/java/org/apache/tika/server/TikaVersion.java
Thu Apr 26 23:17:41 2012
@@ -0,0 +1,34 @@
+/*
+ * 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.tika.server;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.apache.tika.Tika;
+
+@Path("/version")
+public class TikaVersion {
+
+ @GET
+ @Produces("text/plain")
+ public String getVersion() {
+ return new Tika().toString();
+ }
+
+}
Added:
tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaVersionTest.java
URL:
http://svn.apache.org/viewvc/tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaVersionTest.java?rev=1331147&view=auto
==============================================================================
---
tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaVersionTest.java
(added)
+++
tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaVersionTest.java
Thu Apr 26 23:17:41 2012
@@ -0,0 +1,93 @@
+/*
+ * 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.tika.server;
+
+import java.io.InputStream;
+
+import javax.ws.rs.core.Response;
+
+import org.apache.cxf.binding.BindingFactoryManager;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.jaxrs.JAXRSBindingFactory;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.tika.Tika;
+import org.junit.Test;
+
+public class TikaVersionTest extends CXFTestBase {
+
+ private static final String VERSION_PATH = "/version";
+ private static final String endPoint = "http://localhost:"
+ + TikaServerCli.DEFAULT_PORT;
+ private Server server;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+ sf.setResourceClasses(TikaVersion.class);
+ sf.setResourceProvider(
+ TikaVersion.class,
+ new SingletonResourceProvider(new TikaVersion())
+ );
+ sf.setAddress(endPoint + "/");
+
+ BindingFactoryManager manager = sf.getBus().getExtension(
+ BindingFactoryManager.class
+ );
+
+ JAXRSBindingFactory factory = new JAXRSBindingFactory();
+ factory.setBus(sf.getBus());
+
+ manager.registerBindingFactory(
+ JAXRSBindingFactory.JAXRS_BINDING_ID,
+ factory
+ );
+
+ server = sf.create();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ server.stop();
+ server.destroy();
+ }
+
+ @Test
+ public void testGetVersion() throws Exception {
+ Response response = WebClient
+ .create(endPoint + VERSION_PATH)
+ .type("text/plain")
+ .accept("text/plain")
+ .get();
+
+ assertEquals(new Tika().toString(),
+ getStringFromInputStream((InputStream) response.getEntity()));
+ }
+
+}