Hi Suchitha,
Case 2 is not currently supported.
I think you have have swapped the output from case 1 and case 2.
For case 1 Jersey will use the StAX API and skip the root element, and
it does not matter what the name of that root element is.
Can you try upgrading to a later version of Jersey, e.g. 1.1.4.1, to
see if case 1 works for you?
I tried to avoid logging of stack traces for exceptions or in the
responses but i think i need to enable such logging for say a level >=
FINE or when tracing is enabled.
Paul.
On Jan 7, 2010, at 2:15 AM, Suchitha Koneru (sukoneru) wrote:
> Hello Jersey Users ,
> I am using Jersey version 1.1.1-ea, JDK 1.5 and
> application server Jboss 5.1.0GA for developing restful services .
> I have used POSTER (plug in in fire fox) for testing out the restful
> service apis
>
>
> The following Restful service APIS did not work
>
> 1)
> @POST @Path("echoListThree")
> @Consumes ("application/xml")
> @Produces ("application/xml")
>
> public List<UserBean> echoList(List<UserBean> ubeans) {
> return ubeans ;
> }
>
> 2)
> @POST @Path("echoListFour")
> @Consumes ("application/xml")
> @Produces ("application/xml")
> public List<UserBean> echoJAXBList(JAXBElement<List<UserBean>>
> ubeans) {
> return ubeans.getValue();
> }
>
>
> The xml which was posted as input for both of these APIS is
> <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
> <userBeans>
>
> <userBean>
> <firstName>John</firstName>
> <lastName>Smith</lastName>
> <phoneNumber>9999999</phoneNumber>
> <userId>5</userId>
> </userBean>
>
> <userBean>
> <firstName>Suchitha</firstName>
> <lastName>Koneru</lastName>
> <phoneNumber>888888888</phoneNumber>
> <userId>1</userId>
> </userBean>
>
> </userBeans>
>
> The API 1) threw a Http 500 error and in the server logs I found
> the following exception
>
> 6:15:31,535 ERROR [[Jersey Web Application]] Servlet.service() for
> servlet Jersey Web Application threw exception
> java.lang.ClassCastException:
> sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
> at
> com
> .sun
> .jersey
> .core
> .provider
> .jaxb
> .AbstractJAXBElementProvider
> .readFrom(AbstractJAXBElementProvider.java:88)
> at
> com
> .sun
> .jersey
> .core
> .provider
> .jaxb
> .AbstractJAXBElementProvider
> .readFrom(AbstractJAXBElementProvider.java:63)
> at
> com
> .sun
> .jersey
> .spi.container.ContainerRequest.getEntity(ContainerRequest.java:393)
> at
> com
> .sun
> .jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider
> $EntityInjectable.getValue(EntityParamDispatchProvider.java:139)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .inject
> .InjectableValuesProvider
> .getInjectableValues(InjectableValuesProvider.java:43)
> at
> com
> .sun
> .jersey
> .server
> .impl.model.method.dispatch.AbstractResourceMethodDispatchProvider
> $
> EntityParamInInvoker
> .getParams(AbstractResourceMethodDispatchProvider.java:126)
> at
> com
> .sun
> .jersey
> .server
> .impl.model.method.dispatch.AbstractResourceMethodDispatchProvider
> $
> TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:
> 154)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .model
> .method
> .dispatch
> .ResourceJavaMethodDispatcher
> .dispatch(ResourceJavaMethodDispatcher.java:67)
> at
> com
> .sun
> .jersey
> .server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:166)
> at
> com
> .sun
> .jersey
> .server
> .impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:114)
> at
> com
> .sun
> .jersey
> .server
> .impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:74)
> at
> com
> .sun
> .jersey
> .server
> .impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:114)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .uri
> .rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:66)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl._handleRequest(WebApplicationImpl.java:709)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:667)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:658)
>
> The API 2) resulted in HTTP 400 error (description of the error was
> “The request sent by the client was syntactically incorrect ”)
>
> How ever when I try to post a single object as shown in the APIs 3)
> and 4) below , it works. The input xml in this case is
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes">
> <alertPref><custID>cust1</custID>
> <includeAck>true</includeAck>
> <includeClear>false</includeClear>
> <severityLevel>4</severityLevel>
> </alertPref>
>
>
> 3)
> @POST @Path("echoXml")
> @Consumes ("application/xml")
> @Produces ("application/xml")
>
> public AlertPrefInfo echoXML(JAXBElement<AlertPrefInfo> alertPref)
> throws Exception {
> System.out.println(alertPref.getValue());
> AlertPrefInfo prefInfo = alertPref.getValue();
> return prefInfo;
> }
> 4)
>
> @POST @Path("echoXmlTwo")
> @Consumes ("application/xml")
> @Produces ("application/xml")
>
> public AlertPrefInfo echoXMLTwo(AlertPrefInfo alertPref)
> throws Exception {
> System.out.println(alertPref);
> AlertPrefInfo prefInfo = alertPref;
> return prefInfo;
> }
>
> Do we need any special handling if we want the posted xml to be
> converted into a list of objects ? Is this an issue with JAXB or
> Jersey ? Could you please let me know
>
> Thank you,
> Suchitha.