【发布时间】:2012-03-08 19:29:29
【问题描述】:
如何在 POST 请求的请求正文中发送多个参数?
@POST
@Consumes("multipart/form-data")
@Produces("application/json")
public String addForm1(@FormParam("i1") Integer i1, @FormParam("i2") Integer i2);
以上代码返回 HTTP 415。
将@FormParam 替换为@Multipart 会导致Resource method has more than one parameter representing a request body 错误,如下所示。
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)
另外,为了在 POST 方法中传递多个复杂类型(例如 List<Map<String, String>>' or 'List<MyNestedCustomObject>),我需要做什么?我可以通过使用JAXB 并使用@XmlJavaTypeAdapter 对其进行注释来传递此类参数,但我想在传递多个参数的情况下这不起作用?我是否需要定义自己的消息正文阅读器和作者?任何示例代码都会很有用。
谢谢
【问题讨论】:
标签: java web-services cxf jax-rs