You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "KARR, DAVID (ATTSI)" <dk...@att.com> on 2011/02/22 00:38:02 UTC
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>(HttpServ
letRequestSnapshot.java:79)
at
org.apache.cxf.transport.http.AbstractHTTPDestination$1.cacheInput(Abstr
actHTTPDestination.java:303)
at
org.apache.cxf.transport.http.AbstractHTTPDestination.cacheInput(Abstrac
tHTTPDestination.java:519)
at
org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(Abstr
actHTTPDestination.java:531)
at
org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(Abstr
actHTTPDestination.java:524)
at
org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStrea
m.onFirstWrite(AbstractHTTPDestination.java:659)
at
org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutpu
tStream.java:42)
at
org.apache.cxf.io.CacheAndWriteOutputStream.write(CacheAndWriteOutputStr
eam.java:68)
at
com.sun.xml.bind.v2.runtime.output.UTF8XmlOutput.flushBuffer(UTF8XmlOutp
ut.java:401)
at
com.sun.xml.bind.v2.runtime.output.UTF8XmlOutput.endDocument(UTF8XmlOutp
ut.java:132)
at
com.sun.xml.bind.v2.runtime.XMLSerializer.endDocument(XMLSerializer.java
:837)
at
com.sun.xml.bind.v2.runtime.MarshallerImpl.postwrite(MarshallerImpl.java
:379)
at
com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:326
)
at
com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:2
54)
at
javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshaller
Impl.java:75)
at
org.apache.cxf.jaxrs.provider.JAXBElementProvider.marshalToOutputStream(
JAXBElementProvider.java:441)
--------------------------------
What is likely happening here?
RE: Trivial response bombs using JAXRSServerFactoryBean
Posted by "KARR, DAVID (ATTSI)" <dk...@att.com>.
> -----Original Message-----
> From: KARR, DAVID (ATTSI)
> Sent: Monday, February 21, 2011 3:38 PM
> To: users@cxf.apache.org
> 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.