I'm running into a curious dependency issue running unit tests using CXF
endpoints. My test sets up a basic REST service using the local
transport (i.e. local://myservice) via Camel and then attempts to use it
via a proxy generated by JAXRSClientFactory. My pom includes camel-cxf,
cxf-rt-frontend-jaxrs, and cxf-rt-transports-local. The oddity is that
when the service only handles "native" java objects (e.g. String)
everything works fine, but if it's handling JAXB bound objects it errors
out with:
javax.ws.rs.InternalServerErrorException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at
org.apache.cxf.jaxrs.client.AbstractClient.convertToWebApplicationException(AbstractClient.java:462)
at
org.apache.cxf.jaxrs.client.ClientProxyImpl.checkResponse(ClientProxyImpl.java:307)
at
org.apache.cxf.jaxrs.client.ClientProxyImpl.handleResponse(ClientProxyImpl.java:673)
at
org.apache.cxf.jaxrs.client.ClientProxyImpl.doChainedInvocation(ClientProxyImpl.java:639)
at
org.apache.cxf.jaxrs.client.ClientProxyImpl.invoke(ClientProxyImpl.java:215)
at com.sun.proxy.$Proxy22.getBook(Unknown Source)
at com.company.test.DataBindingTest.dataBindingTest(DataBindingTest.java:28)
<snip surefire/maven stack...>
unless I add cxf-rt-transports-http-jetty to my pom's dependencies. Also
enabled TRACE logging on org.apache.cxf.* but no messages indicating why
the server is erroring out. Any idea why it requires the jetty
transport to function property?
Details: CXF 2.7.8, Camel 2.12.2, Java 1.7.0_45
Full unit test for reference:
public class DataBindingTest extends CamelTestSupport {
private LibraryBean libBean = new LibraryBean();
@Test
public void dataBindingTest() throws Exception {
LibraryService client = JAXRSClientFactory.create("local://rest",
LibraryService.class);
Book bookResp = client.getBook("1984");
Book expect = null;
for (Book b : libBean.books) {
if (b.getName().equals("1984")) {
expect = b;
break;
}
}
assertEquals(expect, bookResp);
}
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext cc = super.createCamelContext();
cc.addComponent("activemq",
activeMQComponent("vm://localhost?broker.persistent=false"));
return cc;
}
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry jr = super.createRegistry();
jr.bind("libraryBean", libBean);
return jr;
}
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
from("cxfrs://local://rest?resourceClasses=com.company.test.rest.LibraryService&"
+
"bindingStyle=SimpleConsumer")
.setExchangePattern(ExchangePattern.InOut)
.to("log:com.ptc.esb.test.library?level=INFO&showAll=true")
.to("activemq:queue:library");
from("activemq:queue:library")
.setExchangePattern(ExchangePattern.InOut)
.to("log:com.company.test.library?level=INFO&showAll=true")
.choice()
.when(header("operationName").isEqualTo("getBook"))
.to("bean:libraryBean?method=getBook")
.when(header("operationName").isEqualTo("getBooks"))
.to("bean:libraryBean?method=getBooks")
.endChoice()
.to("log:com.company.test.library?level=INFO&showAll=true");
}
};
}
}
Thanks,
-Chris