On Monday, January 30, 2012 6:33:45 PM K Fung wrote: > Sorry Johan, I'm not sure what you're asking :( > > - Can we do anything on the CXF server side to make JSR311 chose CXF?
In this particular case, the JAX-RS MediaType class has a static singleton delegate. Whichever impl is detected first "wins". A solution on our side could be every place we call MediaType.valueOf(...) we replace that with a direct call into our own class. That would make sure we get the right version. Dan > - Can we ask Sun/Oracle to see if they can do anything about the invalid > MediaType being sent in the HttpUrlConnection > - ...something else? > > -kl > > On Mon, Jan 30, 2012 at 6:29 PM, Johan Edstrom <[email protected]> wrote: > > Even more interestingly - how do we fix it? :) > > > > On Jan 30, 2012, at 7:26 PM, K Fung wrote: > > > Hi Stephan, > > > > > > (this e-mail is based off revision 14 of your source code, da71e69dfdcd) > > > > > > I have some good news and bad news. The good news is that I have a > > > workaround that can make all of your parameterized tests pass. The bad > > > > news > > > > > is that CXF and Jersey binaries are indeed getting mixed up when you run > > > these tests. > > > > > > For the workaround, In JerseyTestClient, change your getResource method > > > > so > > > > > that it looks like the following: > > > public String getResource(URI uri) { > > > > > > JerseyTestClient.LOGGER.debug("getResource(), uri = " + uri); > > > WebResource webResource = new Client().resource(uri); > > > return webResource.accept(MediaType.WILDCARD_TYPE).get(String.class); > > > > > > } > > > > > > By sending an explicit Accept header, this will block HttpUrlConnection > > > from sending an invalid header to CXF. CXF was (correctly!) spitting out > > > > a > > > > > 406 when the HttpUrlConnection was sending: > > > > > > text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 > > > > > > (I'm not sure why HttpUrlConnection was sending this invalid accept. I > > > didn't drill down into this too deeply. Perhaps the JDK team can tell us > > > why). > > > > > > This would obviously imply that your test clients should always be > > > > sending > > > > > an Accept header but this shouldn't be too much of a burden for you (and > > > > it > > > > > seems you've already done it in the latest version of CxfTestClient). > > > > > > Nevertheless, as I feared, CXF and Jersey code are getting mixed up on > > > > the > > > > > server-side. You can see this in the stack: > > > > > > 012-01-30 17:40:18,785 DEBUG [qtp525030058-29] > > > org.apache.cxf.phase.PhaseInterceptorChain: Invoking handleMessage on > > > interceptor org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor@1ff61bcf > > > java.lang.IllegalArgumentException: Error parsing media type '*; q=.2' > > > at > > > > com.sun.jersey.core.impl.provider.header.MediaTypeProvider.fromString(Medi > > aTypeProvider.java:77)> > > > at > > > > com.sun.jersey.core.impl.provider.header.MediaTypeProvider.fromString(Medi > > aTypeProvider.java:50)> > > > at javax.ws.rs.core.MediaType.valueOf(MediaType.java:119) > > > at > > > > org.apache.cxf.jaxrs.utils.JAXRSUtils.parseMediaTypes(JAXRSUtils.java:1097 > > ) > > > > > at > > > > org.apache.cxf.jaxrs.utils.JAXRSUtils.sortMediaTypes(JAXRSUtils.java:1189) > > > > > at > > > > org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSIn > > Interceptor.java:136)> > > > at > > > > org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInI > > nterceptor.java:88)> > > > at > > > > org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorCha > > in.java:263)> > > > at > > > > org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiation > > Observer.java:123)> > > > at > > > > org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPD > > estination.java:206)> > > > at > > > > org.apache.cxf.transport.servlet.ServletController.invokeDestination(Servl > > etController.java:213)> > > > at > > > > org.apache.cxf.transport.servlet.ServletController.invoke(ServletControlle > > r.java:154)> > > > at > > > > org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringSe > > rvlet.java:126)> > > > at > > > > org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(Abstrac > > tHTTPServlet.java:184)> > > > at > > > > org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPSer > > vlet.java:112)> > > > at javax.servlet.http.HttpServlet.service(HttpServlet.java:693) > > > at > > > > org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPS > > ervlet.java:163)> > > > at > > > org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538) > > > at > > > > org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478) > > > > > at > > > > org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.ja > > va:225)> > > > at > > > > org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.ja > > va:940)> > > > at > > > org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406 > > > ) > > > at > > > > org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.jav > > a:186)> > > > at > > > > org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.jav > > a:874)> > > > at > > > > org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:1 > > 17)> > > > at > > > > org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollectio > > n.java:149)> > > > at > > > > org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java > > :110)> > > > at org.eclipse.jetty.server.Server.handle(Server.java:349) > > > at > > > > org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java: > > 441)> > > > at > > > > org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(Http > > Connection.java:919)> > > > at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:582) > > > at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:218) > > > at > > > > org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.ja > > va:52)> > > > at > > > > org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoin > > t.java:586)> > > > at > > > > org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint > > .java:44)> > > > at > > > > org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.jav > > a:598)> > > > at > > > > org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java > > :533)> > > > at java.lang.Thread.run(Thread.java:662) > > > Caused by: java.text.ParseException: Expected separator '/' instead of > > > > ';' > > > > > at > > > > com.sun.jersey.core.header.reader.HttpHeaderReader.nextSeparator(HttpHeade > > rReader.java:112)> > > > at > > > > com.sun.jersey.core.impl.provider.header.MediaTypeProvider.valueOf(MediaTy > > peProvider.java:88)> > > > at > > > > com.sun.jersey.core.impl.provider.header.MediaTypeProvider.fromString(Medi > > aTypeProvider.java:75)> > > > ... 37 more > > > > > > Regards, > > > kl > > > > > > P.S. I assume you deliberately wanted a Jersey client to connect to a > > > CXF > > > server. -- Daniel Kulp [email protected] - http://dankulp.com/blog Talend Community Coder - http://coders.talend.com
