You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by domino <su...@gmail.com> on 2012/03/09 11:31:42 UTC
Resource method has more than one parameter representing a request
body
Hello,
I need to POST more than one parameter. Is this possible through
@Multipart/@FormParam or something? Here is the service method I need:
@POST
@Path("/postdata2")
@Produces("application/json")
public String postData2(@Multipart("list1")
@XmlJavaTypeAdapter(XmlMapAdapter.class) List<Map<String, String>> list1,
@Multipart("testItem2") TestItem t2);
My TestItem is annotated with @XmlRootElement. When I call from my jaxrs
client, it throws the following exception.
SEVERE: Resource method service.rs.TestService.postData2 has more than one
parameter representing a request body
Exception in thread "main"
org.apache.cxf.jaxrs.client.ClientWebApplicationException: Resource method
service.rs.TestService.postData2 has more than one parameter representing a
request body
at
org.apache.cxf.jaxrs.client.ClientProxyImpl.reportInvalidResourceMethod(ClientProxyImpl.java:546)
at
org.apache.cxf.jaxrs.client.ClientProxyImpl.getParametersInfo(ClientProxyImpl.java:214)
at
org.apache.cxf.jaxrs.client.ClientProxyImpl.invoke(ClientProxyImpl.java:138)
at $Proxy20.postData2(Unknown Source)
at service.TestServiceClient.main(TestServiceClient.java:82)
>From http://cxf.apache.org/docs/jax-rs-multiparts.html it seems that what I
need should be possible, since it has an example that says (from
http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java):
@POST
@Path("/books/jaxb2")
@Consumes("multipart/related;type=\"text/xml\"")
@Produces("text/xml")
public Response addBookParts(@Multipart("rootPart") Book b1,
@Multipart("book2") Book b2)
throws Exception {
if (b1.equals(b2)) {
throw new WebApplicationException();
}
if (!b1.getName().equals(b2.getName())) {
throw new WebApplicationException();
}
b1.setId(124);
return Response.ok(b1).build();
}
Thanks
--
View this message in context: http://cxf.547215.n5.nabble.com/Resource-method-has-more-than-one-parameter-representing-a-request-body-tp5550174p5550174.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Resource method has more than one parameter representing a request
body
Posted by Sergey Beryozkin <sb...@gmail.com>.
On 09/03/12 16:05, domino wrote:
> Thanks, Sergey.
>
>> @Multipart annotations are currently ignored (will fix it), so try
>> @FormParam
>
> Few questions.
>
> 1) Didn't find a JIRA request for this issue. Could you point me to one if
> it exists and do you have a rough ETA?
https://issues.apache.org/jira/browse/CXF-4178 - fix is in the trunk
only for now
>
> 2) Please recommend an approach in the absence of @Multipart that will work
> well for a complex type that needs XmlJavaTypeAdapter (for ex,
> List<Map<String,String>>).
>
Avoid having multiple parameters representing the request body
> @FormParam: Is it possible to avoid providing String-arg constructors (or
> fromValue/valueOf static methods) and use only XmlJavaTypeAdapter?
>
On the server - yes, should be possible, but not on the client
> Webclient Approach: Is it possible to use XmlJavaTypeAdapter at all?
>
No, only for proxies.
Cheers, Sergey
> Thanks
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Resource-method-has-more-than-one-parameter-representing-a-request-body-tp5550174p5551014.html
> Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
Re: Resource method has more than one parameter representing a
request body
Posted by domino <su...@gmail.com>.
Thanks, Sergey.
> @Multipart annotations are currently ignored (will fix it), so try
> @FormParam
Few questions.
1) Didn't find a JIRA request for this issue. Could you point me to one if
it exists and do you have a rough ETA?
2) Please recommend an approach in the absence of @Multipart that will work
well for a complex type that needs XmlJavaTypeAdapter (for ex,
List<Map<String,String>>).
@FormParam: Is it possible to avoid providing String-arg constructors (or
fromValue/valueOf static methods) and use only XmlJavaTypeAdapter?
Webclient Approach: Is it possible to use XmlJavaTypeAdapter at all?
Thanks
--
View this message in context: http://cxf.547215.n5.nabble.com/Resource-method-has-more-than-one-parameter-representing-a-request-body-tp5550174p5551014.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Resource method has more than one parameter representing a request
body
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi,
On 09/03/12 10:31, domino wrote:
> Hello,
>
> I need to POST more than one parameter. Is this possible through
> @Multipart/@FormParam or something? Here is the service method I need:
>
> @POST
> @Path("/postdata2")
> @Produces("application/json")
> public String postData2(@Multipart("list1")
> @XmlJavaTypeAdapter(XmlMapAdapter.class) List<Map<String, String>> list1,
> @Multipart("testItem2") TestItem t2);
>
> My TestItem is annotated with @XmlRootElement. When I call from my jaxrs
> client, it throws the following exception.
>
> SEVERE: Resource method service.rs.TestService.postData2 has more than one
> parameter representing a request body
@Multipart annotations are currently ignored (will fix it), so try
@FormParam
Cheers, Sergey
> Exception in thread "main"
> org.apache.cxf.jaxrs.client.ClientWebApplicationException: Resource method
> service.rs.TestService.postData2 has more than one parameter representing a
> request body
> at
> org.apache.cxf.jaxrs.client.ClientProxyImpl.reportInvalidResourceMethod(ClientProxyImpl.java:546)
> at
> org.apache.cxf.jaxrs.client.ClientProxyImpl.getParametersInfo(ClientProxyImpl.java:214)
> at
> org.apache.cxf.jaxrs.client.ClientProxyImpl.invoke(ClientProxyImpl.java:138)
> at $Proxy20.postData2(Unknown Source)
> at service.TestServiceClient.main(TestServiceClient.java:82)
>
> From http://cxf.apache.org/docs/jax-rs-multiparts.html it seems that what I
> need should be possible, since it has an example that says (from
> http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java):
>
> @POST
> @Path("/books/jaxb2")
> @Consumes("multipart/related;type=\"text/xml\"")
> @Produces("text/xml")
> public Response addBookParts(@Multipart("rootPart") Book b1,
> @Multipart("book2") Book b2)
> throws Exception {
> if (b1.equals(b2)) {
> throw new WebApplicationException();
> }
> if (!b1.getName().equals(b2.getName())) {
> throw new WebApplicationException();
> }
> b1.setId(124);
> return Response.ok(b1).build();
> }
>
> Thanks
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Resource-method-has-more-than-one-parameter-representing-a-request-body-tp5550174p5550174.html
> Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
Re: Resource method has more than one parameter representing a
request body
Posted by domino <su...@gmail.com>.
I have one approach that is working using @Multipart (shown below), but I'd
ideally like a "regular" way to consume the service using jaxrs:client and
without possibly using the concept of "attachments".
Approach that is working:
@POST
@Path("/postdata3")
@Consumes("multipart/mixed")
@Produces("application/json")
public String postData3(@Multipart(value = "testItem1", type =
"application/json") TestItem t1,
@Multipart(value = "testItem2", type = "application/json") TestItem
t2
);
WebClient client =
WebClient.create("http://myserver/services/test/postdata3");
client.type("multipart/mixed").accept("application/json");
List<Attachment> atts = new LinkedList<Attachment>();
atts.add(new Attachment("testItem1", "application/json", t1));
atts.add(new Attachment("testItem2", "application/json", t2));
javax.ws.rs.core.Response s = client.postCollection(atts,
Attachment.class);
System.out.println(s.getStatus());
--
View this message in context: http://cxf.547215.n5.nabble.com/Resource-method-has-more-than-one-parameter-representing-a-request-body-tp5550174p5550429.html
Sent from the cxf-user mailing list archive at Nabble.com.