Java 如何使用apache CXF webclient在请求正文中发送JSON数据?
我正在使用ApacheCxfWebClient来使用用.NET编写的服务 将在请求正文中发送到web服务的示例JSONJava 如何使用apache CXF webclient在请求正文中发送JSON数据?,java,web-services,Java,Web Services,我正在使用ApacheCxfWebClient来使用用.NET编写的服务 将在请求正文中发送到web服务的示例JSON { "Conditions": [ { "Field":"TextBody", "Comparer":"ContainsAny", "Values":["stocks","retire"], "Proximity":0 },
{
"Conditions":
[
{
"Field":"TextBody",
"Comparer":"ContainsAny",
"Values":["stocks","retire"],
"Proximity":0
},
{
"Field":"SentAt",
"Comparer":"LessThan",
"Values":["1331769600"],
"Proximity":0
},
],
"Operator":"And",
"ExpireResultIn":3600
}
如果我想在一个请求中提交表单和Json正文中的数据,有什么方法吗?
webclient API apache CXF-
这之后用哪种方法和怎么用
client.form(...form object )
client.post(...JSON string )
他们没有共享JSON中的“条件”对象,我可以对其进行注释并将其传递给客户端的post方法
需要设置JSON提供者在我的例子中是jackson
List<Object> providers = new ArrayList<Object>();
providers.add( new JacksonJaxbJsonProvider() );
WebClient client = WebClient.create("http://localhost:8080/poc_restapi_cxf/api",
providers);
client = client.accept("application/json")
.type("application/json")
.path("/order")
.query("id", "1");
Order order = client.get(Order.class);
System.out.println("Order:" + order.getCustomerName());
List providers=new ArrayList();
add(新的JacksonJaxbJsonProvider());
WebClient客户端=WebClient.create(“http://localhost:8080/poc_restapi_cxf/api",
供应商);
client=client.accept(“应用程序/json”)
.type(“应用程序/json”)
.path(“/order”)
.查询(“id”、“1”);
Order=client.get(Order.class);
System.out.println(“订单:+Order.getCustomerName());
有一种方法可以使用注释完成此操作,并且适合我的目的:
@Post
@Path("mypath/json/whatever")
@Consumes({MediaType.APPLICATION_JSON_VALUE})
public Response postClient(@Context HttpHeaders headers, String input) {
//Here the String input will be equal to the supplied json.
//...
}
@Post
@Path("mypath/json/whatever")
@Consumes({MediaType.APPLICATION_JSON_VALUE})
public Response postClient(@Context HttpHeaders headers, String input) {
//Here the String input will be equal to the supplied json.
//...
}