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.