I ran into the following issue when setting up a JAXRS test service in a unit test. This is the code (taken from an AbstractJUnit4SpringContextTests-derived test class):
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setServiceBeans(applicationContext.getBean("searchXY"));
sf.setAddress("http://localhost:9000/");
sf.create();
restClient = new RestTestClient();//custom class for client-side testing
....
InputStream dummyRequestFileAsStream = getInputStreamForClasspathResource(
DUMMY_REQUEST_FILE);
LOGGER.info("Testing searchQuery ReST service access");
int httpStatus = restClient.postXmlStream(
"http://localhost:9000/search/searchXY",
dummyRequestFileAsStream);
I'm feeding an XML test file into the service. CXF would impertinently try to wrap the xml into a javax.xml.bind.JAXBElement, invoke the service, and fail with an IllegalArgumentException (in the reflection API) because the service of course does not accept a JAX-RS-specific element but rather the SearchRequest element that I defined in my XSD before.
However, when I insert the following line into my spring context, everything's fine:
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
Anyone else seen this?