2

I am using the Restlet Version 2.2.0 with the IBM jdk 1.6.0_26 and I am trying to implement a REST Service. While executing my test project I am getting the following error:

Starting the internal [HTTP/1.1] server on port 8080
Server started ...
An exception occured writing the response entity

java.lang.NoSuchMethodError: javax/xml/stream/XMLInputFactory.newFactory()Ljavax/xml/stream/XMLInputFactory;
    at org.restlet.ext.jackson.JacksonRepresentation.createObjectMapper(JacksonRepresentation.java:215)
    at org.restlet.ext.jackson.JacksonRepresentation.getObjectMapper(JacksonRepresentation.java:333)
    at org.restlet.ext.jackson.JacksonRepresentation.createObjectWriter(JacksonRepresentation.java:277)
    at org.restlet.ext.jackson.JacksonRepresentation.getObjectWriter(JacksonRepresentation.java:361)
    at org.restlet.ext.jackson.JacksonRepresentation.write(JacksonRepresentation.java:474)
    at org.restlet.engine.adapter.ServerCall.writeResponseBody(ServerCall.java:519)
    at org.restlet.engine.adapter.ServerCall.sendResponse(ServerCall.java:463)
    at org.restlet.engine.adapter.ServerAdapter.commit(ServerAdapter.java:196)
    at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:153)
    at org.restlet.engine.connector.HttpServerHelper$1.handle(HttpServerHelper.java:73)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)
    at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:77)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:80)
    at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:567)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)
    at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:539)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:737)
Unable to send error response

java.io.IOException: headers already sent
    at sun.net.httpserver.ExchangeImpl.sendResponseHeaders(ExchangeImpl.java:180)
    at sun.net.httpserver.HttpExchangeImpl.sendResponseHeaders(HttpExchangeImpl.java:80)
    at org.restlet.engine.connector.HttpExchangeCall.writeResponseHead(HttpExchangeCall.java:157)
    at org.restlet.engine.adapter.ServerCall.sendResponse(ServerCall.java:459)
    at org.restlet.engine.adapter.ServerAdapter.commit(ServerAdapter.java:214)
    at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:153)
    at org.restlet.engine.connector.HttpServerHelper$1.handle(HttpServerHelper.java:73)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)
    at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:77)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:80)
    at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:567)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)
    at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:539)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:737)

While using Sun/Oracle 1.6 JDK the problem doesn't exist, but I need to stay at IBM jdk 1.6.0_26.

Any help would be appreciated.

Thanks, EHa

DaveyDaveDave
  • 9,821
  • 11
  • 64
  • 77
EHa
  • 21
  • 4

2 Answers2

0

It's likely a problem with the fallback JAXP selection between the two JDKs. Run java with -Djaxp.debug=1 and have a look at your logs. I'm currently encountering this same issue and my logs are showing

JAXP: find factoryId =javax.xml.parsers.SAXParserFactory
JAXP: loaded from fallback value: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
JAXP: created new instance of class com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl using ClassLoader: null

I'm pretty certain that my issue is OSGi related. Here's the link to another question with what could be a similar outcome: Unable to find a factory for http://www.w3.org/2001/XMLSchema

Rob Paisley
  • 437
  • 1
  • 3
  • 13
  • Did you have a solution here ? If so, can you remember which one? :) – Victor May 20 '20 at 16:27
  • @Victor I was able to get past it, though I can't speak with certainty regarding how. I suspect it was explicitly selecting the Thread's ContextClassLoader as I was in an OSGi environment. – Rob Paisley May 20 '20 at 16:31
0

I faced exactly the same error but in a different context. The error was sourced from the following:

import com.fasterxml.jackson.dataformat.xml.XmlMapper;
...
...
    private static XmlMapper xmlMapper=null;
...
...
    xmlMapper = new XmlMapper();

From this comment here I thought to change the version of of jackson-dataformat-xml from 2.14.2 down to 2.12.7, and it worked.

tarekahf
  • 738
  • 1
  • 16
  • 42