Hi Yes, you can't pass payloads with GET methods.
WADL looks better but as I said you need to have a qualified element for links from representations to the grammar section to appear. NPE is probably to do with the fact RequestWrapper does not have its theList field initialized Sergey On Wed, May 4, 2011 at 12:54 AM, yhu <[email protected]> wrote: > I can use POST method to post XML data. The POST type method addRequest() is > defined as below: > > @POST > @Path("/addRequest") > @Produces({MediaType.APPLICATION_XML}) > @Consumes({MediaType.APPLICATION_XML}) > public String addRequest(RequestWrapper rw) { > System.out.println(rw); > return rw.toString(); > } > > @XmlRootElement > public static class RequestWrapper { > List<String> theList; > String theRequest; > > @XmlElement (name="listItem") > @XmlElementWrapper > public Collection<String> getTheList() { > return theList; > } > > public void setTheList(List<String> theList) { > this.theList = theList; > } > > public String getTheRequest() { > return theRequest; > } > > public void setTheRequest(String theRequest) { > this.theRequest = theRequest; > } > > @Override > public String toString() { > return "RequestWrapper{" + > "theList=" + theList + > ", theRequest='" + theRequest + '\'' + > '}'; > } > } > > The according WADL is: > > - <application xmlns="http://wadl.dev.java.net/2009/02" > xmlns:xs="http://www.w3.org/2001/XMLSchema"> > - <grammars> > - <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" > attributeFormDefault="unqualified" elementFormDefault="unqualified"> > <xs:element name="requestWrapper" type="requestWrapper" /> > - <xs:complexType name="requestWrapper"> > - <xs:sequence> > - <xs:element minOccurs="0" name="theList"> > - <xs:complexType> > - <xs:sequence> > <xs:element maxOccurs="unbounded" minOccurs="0" name="listItem" > type="xs:string" /> > </xs:sequence> > </xs:complexType> > </xs:element> > <xs:element minOccurs="0" name="theRequest" type="xs:string" /> > </xs:sequence> > </xs:complexType> > </xs:schema> > </grammars> > - <resources > base="http://localhost:8080/ws-rest-prototype/services/LuckyNumbersRest"> > - <resource path="/luckynumbers"> > - <resource path="/addRequest"> > - <method name="POST"> > - <request> > <representation mediaType="application/xml" /> > </request> > - <response> > - <representation mediaType="application/xml"> > > </representation> > </response> > </method> > </resource> > </resource> > </resources> > </application> > > When I post XML data > <requestWrapper><theRequest>abc</theRequest></requestWrapper> to addRequest > method, I get the return: RequestWrapper{theList=null, theRequest='abc'}, it > is expected. > > However when I post XML data > <requestWrapper><theRequest>abc</theRequest><theList><listItem>item1</listItem></theList></requestWrapper> > , the error happens:(I use the latest CXF 2.4.0). Is something wrong in my > code or XML data? > > java.lang.NullPointerException > at > com.sun.xml.bind.v2.runtime.reflect.Lister$CollectionLister.addToPack > (Lister.java:301) > at > com.sun.xml.bind.v2.runtime.reflect.Lister$CollectionLister.addToPack > (Lister.java:265) > at > com.sun.xml.bind.v2.runtime.unmarshaller.Scope.add(Scope.java:117) > at > com.sun.xml.bind.v2.runtime.property.ArrayERProperty$ReceiverImpl.rec > eive(ArrayERProperty.java:209) > at > com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.endElem > ent(UnmarshallingContext.java:518) > at > com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleEn > dElement(StAXStreamConnector.java:217) > at > com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(S > tAXStreamConnector.java:181) > at > com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0( > UnmarshallerImpl.java:360) > at > com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(U > nmarshallerImpl.java:332) > at > org.apache.cxf.jaxrs.provider.JAXBElementProvider.unmarshalFromInputS > tream(JAXBElementProvider.java:214) > at > org.apache.cxf.jaxrs.provider.JAXBElementProvider.doUnmarshal(JAXBEle > mentProvider.java:180) > at > org.apache.cxf.jaxrs.provider.JAXBElementProvider.readFrom(JAXBElemen > tProvider.java:149) > at > org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils. > java:1013) > at > org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.jav > a:594) > at > org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.ja > va:559) > at > org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JA > XRSInInterceptor.java:230) > at > org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAX > RSInInterceptor.java:88) > at > org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercept > orChain.java:263) > at > org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainIniti > ationObserver.java:118) > at > org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(Abstract > HTTPDestination.java:208) > at > org.apache.cxf.transport.servlet.ServletController.invokeDestination( > ServletController.java:223) > at > org.apache.cxf.transport.servlet.ServletController.invoke(ServletCont > roller.java:166) > at > org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpr > ingServlet.java:113) > at > org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(Ab > stractHTTPServlet.java:184) > at > org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractH > TTPServlet.java:107) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) > at > org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(Abstract > HTTPServlet.java:163) > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl > icationFilterChain.java:290) > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF > ilterChain.java:206) > at > org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV > alve.java:233) > at > org.apache.catalina.core.StandardContextValve.invoke(StandardContextV > alve.java:191) > at > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j > ava:127) > at > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j > ava:102) > at > org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal > ve.java:109) > at > org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav > a:298) > at > org.apache.coyote.http11.Http11Processor.process(Http11Processor.java > :852) > at > org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce > ss(Http11Protocol.java:588) > at > org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:48 > 9) > at java.lang.Thread.run(Thread.java:662) > May 3, 2011 4:23:29 PM > org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper t > oResponse > WARNING: WebApplicationException has been caught : cause is > java.lang.NullPointe > rException > > > -- > View this message in context: > http://cxf.547215.n5.nabble.com/java-util-List-in-rquest-missed-in-WADL-tp4365634p4368714.html > Sent from the cxf-user mailing list archive at Nabble.com. > -- Sergey Beryozkin Application Integration Division of Talend http://sberyozkin.blogspot.com
