You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Sergey Beryozkin <sb...@gmail.com> on 2011/09/10 19:52:03 UTC

Re: POST request : List input through JSON not being recognized
Hi
redirecting to the users list...

What exception is thrown ? May be it should be "{"Users":"", note 
capital 'U'

cheers, Sergey
On 09/09/11 17:34, ZenEighth wrote:
> Hi,
>
> Using CXF 2.4.2, developing a JAX-RS and JAX-WS combined webservice, which
> use the same method.
>
> Am trying to invoke a POST message and would like to pass a List<User>, to
> add to the DB. The method looks something like this:
> @POST
> @Path("/game/{id}/users/")
> @WebMethod(operationName = "addUsers")
> public Response addUsers(@PathParam("id") @WebParam(name = "id") String id,
> List<User>  users);
>
> All this method does is get this List, adds this to the DB.
>
> However, I can't seem to make this POST request work while passing JSON
> data, as shown below tried both versions below, but I can't get the
> List<User>  populated, and it throws exception too.
> 1)
> {"User":[{"deleted":"false","id":"1","login":"Test1","name":"Testing1"},{"deleted":"false","id":"2","login":"Test2","name":"Testing2"}]}
>
> 2)
> {"users":[{"deleted":"false","id":"1","login":"Test1","name":"Testing1"},{"deleted":"false","id":"2","login":"Test2","name":"Testing2"}]}
>
> The User class is pretty simple, just few properties as shown above.
>
> Let me know if you need any more details on this.
>
> Any help on this is very much appreciated!
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/POST-request-List-Object-input-through-JSON-not-being-recognized-tp4786966p4786966.html
> Sent from the cxf-dev mailing list archive at Nabble.com.


Re: POST request : List input through JSON not being recognized Posted by ZenEighth <ze...@gmail.com>.
Thank you Sergey for your reply...apologies for the delay on my part..and for
this lengthy post :)

1)
Using CXF 2.4.2, with JAX-RS of the same version, 2.4.2 (please see my
second point related to this below), I am getting an exception that suggests
'List is not recognized/supported'. My apologies as I lost the exact
exception, and I since moved my code to wrap the List<> inside another
class. This seems to work, although I would love to go back to using List<>
directly, if possible. (I can get the exception for you, if you would like
me to though.)

Its the JSON input that causes this issue, XML input seems to work fine. 

2)  However, I noticed something that I can't explain. If I set both
Apache-CXF and JAX-RS (cxf-rt-frontend-jaxrs) the same 2.4.2 version in my
projects' pom file, I *cannot* get JSON data/response back, ever(XML is
fine). Even on a simple GET, it always throws this exception shown
below(Jettison version that Maven pulls-in is, Jettison-1.3.jar) :

java.lang.NoSuchMethodError:
org.codehaus.jettison.mapped.Configuration.setSupressAtAttributes(Z)V
 at
org.apache.cxf.jaxrs.provider.JSONUtils.createConfiguration(JSONUtils.java:110)
 at
org.apache.cxf.jaxrs.provider.JSONProvider.createWriter(JSONProvider.java:420)
 at
org.apache.cxf.jaxrs.provider.JSONProvider.marshal(JSONProvider.java:405)
 at
org.apache.cxf.jaxrs.provider.JSONProvider.marshal(JSONProvider.java:443)
 at
org.apache.cxf.jaxrs.provider.JSONProvider.writeTo(JSONProvider.java:319)
 at
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.serializeMessage(JAXRSOutInterceptor.java:257)
 at
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.processResponse(JAXRSOutInterceptor.java:144)
 at
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRSOutInterceptor.java:83)
 at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
 at
org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77)
 at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
 at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
 at
org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:206)
 at
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:218)
 at
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:161)
 at
org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:114)
 at
org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:184)
 at
org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:112)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:690) 


BUT, if I change my project pom file to push-down the version on
JAX-RS(cxf-rt-frontend-jaxrs) *alone* to 2.4.0, and keep the rest of CXF
libraries @ 2.4.2, I get beautiful JSON responses for the same GET's and
POST's etc. This is totally repeatable by me on my end. And the weird thing
is Jettison library is still Jettison-1.3.jar. Thought this might interest
you. 

Summary:
So, to recap, my LIST<> input error happens with either versions of
JAX-RS(2.4.2 and 2.4.0), and this is with JSON input only (XML and SOAP are
fine). And secondly, if I use JAX-RS 2.4.2 and CXF 2.4.2, I *cannot* get
back JSON responses for a simple GET either. However, if I bump-down JAX-RS
to 2.4.0, and keep the rest of CXF libraries at 2.4.2, I get JSON output
from the same code (no changes are needed), and this is repeatable.

BTW, I have this deployed on an ancient version of JBoss, jBoss 4.2.3GA, and
I can't upgrade that :)

Here are the cxf related info from my pom file:
        <properties>
             <cxf.version>2.4.2</cxf.version>
        </properties>
          .................
          ................
<dependencies>
       <dependency>
		<groupId>org.apache.cxf</groupId>
		<artifactId>cxf-rt-frontend-jaxws</artifactId>
		<version>${cxf.version}</version>
	</dependency>
	<dependency>
		<groupId>org.apache.cxf</groupId>
		<artifactId>cxf-rt-transports-http</artifactId>
		<version>${cxf.version}</version>
	</dependency>
	<dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
      <version>2.4.0</version>
   </dependency>
          .................
          ................
</dependencies>

Thank you once again Sergey..!



--
View this message in context: http://cxf.547215.n5.nabble.com/POST-request-List-Object-input-through-JSON-not-being-recognized-tp4786966p4796953.html
Sent from the cxf-dev mailing list archive at Nabble.com.