Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send JSON data in request body suing apache CXF webclient?

I am using apache cxf webclient to consume a service written in .NET

sample JSON to be sent in request body to a web service

{
   "Conditions":
      [
         {
            "Field":"TextBody",
            "Comparer":"ContainsAny",
            "Values":["stocks","retire"],
            "Proximity":0
         },
         {
            "Field":"SentAt",
            "Comparer":"LessThan",
            "Values":["1331769600"],
            "Proximity":0
         },
      ],
   "Operator":"And",
   "ExpireResultIn":3600
}

Is there any way if I want to submit data from both form and in Json body in one request ? webclient API apache CXF -

web client API doc

WebClient client = WebClient.create("http://mylocalhost.com:8989/CXFTest/cxfws/rest/restservice/json");
 client.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON);

After this which method and how to use ?

client.form(...form object )

client.post(...JSON string ) 

They have not shared Object of "Conditions" in JSON which I can annotate and pass to post method of client

like image 356
Neel Salpe Avatar asked Jan 06 '14 10:01

Neel Salpe


1 Answers

I got answer here Need to set JSON provider in my case it was 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());
like image 195
Neel Salpe Avatar answered Nov 16 '22 07:11

Neel Salpe