Hi Nick,

Sorry for a delay, just back from a short break,
On 07/05/14 10:48, Nick Burch wrote:
Hi All

One for our JAXRS gurus here...

At ApacheCon, we came up with the idea of having a welcome page on the
Tika Server, so that we could point people to it to try Tika, and let
them discover what it offered. Based on that, and the mailing list
discussions, we raised TIKA-1269.

(Related to that is TIKA-1270, which aims to add endpoints similar to
the --list- ones the Tika CLI has, which is in progress)

While we work out the best way to allow users to discover + learn about
+ try the various REST endpoints on TIKA-1269, I've started with
something basic. This is done with the simple TikaWelcome class, which
has a Path of /

The problem - when the MetadataEP and UnpackerResource are enabled, it
doesn't work! With those to there, when you request / you get a 404 and
the server logs:
rg.apache.cxf.jaxrs.utils.JAXRSUtils findTargetMethod
WARNING: No operation matching request path "/" is found, Relative Path:
/, HTTP Method: GET, ContentType: */*, Accept: */*,. Please enable
FINE/TRACE log level for more details.

However, if you comment out those two endpoint classes from the
sf.setResourceClasses() call in TikaServerCLI, then the request gets
correctly routed to the welcome page.

Neither MetadataEP nor UnpackerResource have a path that clashes, so
I've no idea why having them active stops / working. Any ideas?

(Patch below if you want to try disabling them yourself to investigate)


UnpackerResource has no Path annotation so it is defaulted to "/".
In JAX-RS 1.1 if we have say 2 root resources with the same path then the selection is unpredictable. AFAIK all JAX-RS 1.1 stacks have the extensions to address this issue and this is the CXF one:

http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Customselectionbetweenmultipleresources

JAX-RS 2.0 fixes this issue, I'll be working on upgrading Tika to CXF 3.0 shortly, and it will work as expected. However, the selection between multiple root resources with the same top-level Path is more expensive so ideally we could introduce a dedicated @Path to UnpackerResource.

The other option is to consider implementing a Welcome functionality in a JAX-RS 2.0 ContainerRequestFilter (supported in CXF 2.7.x), build a welcome info there and abort/block a request

Cheers, Sergey

Nick


Index: src/main/java/org/apache/tika/server/TikaServerCli.java
===================================================================
--- src/main/java/org/apache/tika/server/TikaServerCli.java    (revision
1592656)
+++ src/main/java/org/apache/tika/server/TikaServerCli.java    (working
copy)
@@ -92,10 +92,20 @@
        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
        // Note - at least one of these stops TikaWelcome matching on /
        // This prevents TikaWelcome acting as a partial solution to
TIKA-1269
-      sf.setResourceClasses(MetadataEP.class, MetadataResource.class,
-              TikaResource.class, UnpackerResource.class,
-              TikaDetectors.class, TikaMimeTypes.class,
-              TikaVersion.class, TikaWelcome.class);
+//      sf.setResourceClasses(MetadataEP.class, MetadataResource.class,
+//              TikaResource.class, UnpackerResource.class,
+//              TikaDetectors.class, TikaMimeTypes.class,
+//              TikaVersion.class, TikaWelcome.class);
+      sf.setResourceClasses(
+//              MetadataEP.class,
+              MetadataResource.class,
+              TikaResource.class,
+//              UnpackerResource.class,
+              TikaDetectors.class,
+              TikaMimeTypes.class,
+              TikaVersion.class,
+              TikaWelcome.class
+      );

        List<Object> providers = new ArrayList<Object>();
        providers.add(new TarWriter());



Reply via email to