> -----Original Message----- > From: KARR, DAVID (ATTSI) > Sent: Monday, February 21, 2011 3:38 PM > To: [email protected] > Subject: Trivial response bombs using JAXRSServerFactoryBean > > I have a skeleton JAX-RS service (CXF 2.3.2). When I test it with wget > or SoapUI, it correctly returns an empty object. It's deployed in a > WAR > inside an EAR in WebLogic 10.3.2. > > I'm now copying over code from an older project that lets me test my > controller in a unit test. > > This is my "startServer()" method, which was copied almost unchanged > from the older project: > --------------------- @BeforeClass > public static void startServer() { > JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); > sf.setServiceBean(catalogContentController); > sf.getInInterceptors().add(new LoggingInInterceptor()); > sf.getOutInterceptors().add(new LoggingOutInterceptor()); > sf.setProvider(new JacksonJsonProvider()); > > sf.setAddress(BASE_SERVICE_URI); > > Map<Object, Object> mappings = new HashMap<Object, Object>(); > mappings.put("xml", "application/xml"); > mappings.put("json", "application/json"); > sf.setExtensionMappings(mappings); > > JacksonInit jacksonInit = new JacksonInit(); > ObjectMapper objectMapper = new ObjectMapper(); > jacksonInit.setObjectMapper(objectMapper); > jacksonInit.setAnnotationIntrospector(new > AnnotationIntrospector.Pair(new JacksonAnnotationIntrospector(), > > new JaxbAnnotationIntrospector())); > jacksonInit.init(); > > sf.create(); > } > --------------- > > Inside a test method, I have code like this: > > --------------------- > WebClient client = WebClient.create(BASE_SERVICE_URI); > client.path("/catalog/rootCategories"); > > GetRootCategoriesResponse response = null; > response = client.get(GetRootCategoriesResponse.class); > System.out.println("response[" + response + "]"); > --------------------- > > When I run this, I'm seeing the following: > -------------------------- > java.lang.NoSuchMethodError: > javax.servlet.http.HttpServletRequest.getLocalAddr()Ljava/lang/String; > at > org.apache.cxf.transport.http.HttpServletRequestSnapshot.<init>(HttpSer > v > letRequestSnapshot.java:79) > at > org.apache.cxf.transport.http.AbstractHTTPDestination$1.cacheInput(Abst > r > actHTTPDestination.java:303) > at > org.apache.cxf.transport.http.AbstractHTTPDestination.cacheInput(Abstra > c > tHTTPDestination.java:519) > at > org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(Abst > r > actHTTPDestination.java:531) > at > org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(Abst > r > actHTTPDestination.java:524) > at > org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStre > a > m.onFirstWrite(AbstractHTTPDestination.java:659) > at > org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutp > u > tStream.java:42) > at > org.apache.cxf.io.CacheAndWriteOutputStream.write(CacheAndWriteOutputSt > r > eam.java:68) > at > com.sun.xml.bind.v2.runtime.output.UTF8XmlOutput.flushBuffer(UTF8XmlOut > p > ut.java:401) > at > com.sun.xml.bind.v2.runtime.output.UTF8XmlOutput.endDocument(UTF8XmlOut > p > ut.java:132) > at > com.sun.xml.bind.v2.runtime.XMLSerializer.endDocument(XMLSerializer.jav > a > :837) > at > com.sun.xml.bind.v2.runtime.MarshallerImpl.postwrite(MarshallerImpl.jav > a > :379) > at > com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:32 > 6 > ) > at > com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java: > 2 > 54) > at > javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshalle > r > Impl.java:75) > at > org.apache.cxf.jaxrs.provider.JAXBElementProvider.marshalToOutputStream > ( > JAXBElementProvider.java:441) > --------------------------------
Hmm, I think I see an old version of the Servlet api in my classpath. That's likely my problem here.
