0

I have created a sample project to show my trouble while trying to produce an XML response from my Rest web service.

I use Open JDK 15, Jersey 3.0.2 and Jetty 11.0.0

You can clone and run the project to see my point : https://github.com/dpapin1118/jersey-jetty

Whichever Xml Provider I choose, Jersey ends up picking another provider that is not compatiblé with Xml (or no provider at all).

It looks like if my Resource Config was not taken in account by the Server

            ResourceConfig resourceConfig = new ResourceConfig(
                    EchoControllerXml.class
            ).packages("lu.isd.jetty.model.echo")
                    .register(MoxyXmlFeature.class);

and that the

Server server = JettyHttpContainerFactory.createServer(appUri, resourceConfig, false);

was not working.

In the end, calling curl http://localhost:10020/xml/bonjour does not return anything but generate a

java.io.IOException: Unconsumed content
    at org.eclipse.jetty.server.HttpInput.consumeAll(HttpInput.java:133)
    at org.eclipse.jetty.server.HttpConnection.onCompleted(HttpConnection.java:432)
    at org.eclipse.jetty.server.HttpChannel.onCompleted(HttpChannel.java:859)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:384)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:289)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:324)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
    at org.eclipse.jetty.io.SocketChannelEndPoint$1.run(SocketChannelEndPoint.java:106)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:790)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:912)
    at java.base/java.lang.Thread.run(Thread.java:832)

I have managed to use both Json and XML in previous Jersey version by adding the correct maven dependency and register the right provider, but nothing worked with those very recent versions of Jersey, Jetty and Java.

Note that Json has no issue.

the duck
  • 375
  • 3
  • 13
  • 2
    I think you should read up on the change made from `javax` to `jakarta`. Jersey 3 uses Jakarta now. No more javax – Paul Samsotha Aug 20 '21 at 01:57
  • Actually, when I run the server with my IDE (IntelliJ), it works. But when I run java -jar target\jersey-jetty-0.9-jar-with-dependencies.jar, it stops at line HttpServer.java:35 because the "server" object is null. There is no stacktrace from the JettyHttpContainerFactory. – the duck Aug 21 '21 at 07:36
  • 1
    https://stackoverflow.com/q/36687312/2587435 – Paul Samsotha Aug 21 '21 at 09:29
  • 1
    If you have another unrelated problem, please post another question instead of asking non related follow up questions inside comments. – Paul Samsotha Aug 21 '21 at 09:31

0 Answers0