2

I have a Java EE 7 WebApplication providing Parsing and Search Functionality. While using tika-parsers 1.10 everything works but as soon as i upgrade to 1.11 my REST-Services fail for reading/writing json.

    <dependency>
        <groupId>org.apache.tika</groupId>
        <artifactId>tika-parsers</artifactId>
        <version>1.11</version>
    </dependency>

Error message:

javax.ws.rs.client.ResponseProcessingException: No message body reader has been found for class de.drivve.km.idd.IddAccount, ContentType: application/json
at org.apache.cxf.jaxrs.impl.ResponseImpl.reportMessageHandlerProblem(ResponseImpl.java:433)
at org.apache.cxf.jaxrs.impl.ResponseImpl.doReadEntity(ResponseImpl.java:384)
at org.apache.cxf.jaxrs.impl.ResponseImpl.readEntity(ResponseImpl.java:319)

I am running on Wildfly 10 having a few other dependencies that might be noteworthy:

    ...
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxb-provider</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson-provider</artifactId>
        <scope>provided</scope>
    </dependency>
    ...
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.7.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.7.0</version>
    </dependency>
    ...

It seems apache-cxf(required by tika-parsers) is used instead of jackson to read/write json. Any idea how to work around that?

Philipp
  • 4,180
  • 7
  • 27
  • 41
  • 1
    Apache CXF is a JAX-RS implementation, it is not a replacement for Jackson. Do an experiment first by adding exclusions for the CXF libraries to the tika dependency (because I can pretty much assure you those dependencies are not needed for tika to work); see if that actually makes the problem go away. – Gimby Jan 22 '16 at 09:13
  • Youre are right. I had to exclude "cxf-rt-rs-client" (the other cxf-libraries seemed to be no problem) Thanks! – Philipp Jan 22 '16 at 10:08

1 Answers1

4

Gimby pointed it out correctly. I had to add an exclusion to the tika-parser-dependency:

    <dependency>
        <groupId>org.apache.tika</groupId>
        <artifactId>tika-parsers</artifactId>
        <version>1.11</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-rs-client</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

Now my REST-Services work again and most of my tika parsing tests(e.g. docx, pdf, ppt, html). But now, when trying to parse an odt-file tika fails with the following exception:

java.lang.NoSuchMethodError: org.apache.commons.io.IOUtils.toString(Ljava/io/InputStream;Ljava/nio/charset/Charset;)Ljava/lang/String;
at org.apache.tika.parser.pkg.ZipContainerDetector.detectOpenDocument(ZipContainerDetector.java:192)
at org.apache.tika.parser.pkg.ZipContainerDetector.detectZipFormat(ZipContainerDetector.java:145)
at org.apache.tika.parser.pkg.ZipContainerDetector.detect(ZipContainerDetector.java:90)
at org.apache.tika.detect.CompositeDetector.detect(CompositeDetector.java:77)
at org.apache.tika.parser.AutoDetectParser.parse(AutoDetectParser.java:112)
...
Philipp
  • 4,180
  • 7
  • 27
  • 41
  • Do you need to be able to parse these ODT files? If so then this is not the answer to the question but only a way to exchange one problem for another. – Gimby Jan 22 '16 at 10:55
  • In fact i need to be able to parse odt files. Not sure why cxf-rt-rs-client is required for that. Is it possible to "configure not to use cxf" as messagebody reader/writer wihtout excluding any tika-parser dependencies? – Philipp Jan 22 '16 at 12:53
  • Its a difficult one. I'm assuming that the CXF dependencies are transitively pushing in another JSON handler API and your own JAX-RS implementation (Jersey? RestEASY?) is auto-picking it. So you would need to lookup in the documentation of your JAX-RS implementation how to manually configure one to always use. – Gimby Jan 22 '16 at 14:21
  • So if we are in agreement that this is not actually an answer to your question, I would delete it. Rather edit relevant information into your question. – Gimby Jan 22 '16 at 14:21
  • Actually excluding cxf was/is not that bad as it resolves the missing messageBodyReader and points out what was interfering. Still in my case i need to find another solution. I am using RestEASY by the way. – Philipp Jan 22 '16 at 14:44