1

I need to write a HTTP client which to communicate with Floodlight OpenFlow controller via its REST API.

For testing I did it in python, and it worked OK. But now I'm in a situation where it has to be done in Java, of which I'm admittedly still at the beginner's level. One of my apps uses AsyncHttpClient to dispatch async GET requests, and works just fine. Now as a Floodlight's REST client, it has to do POST and DELETE with JSON encoded body. My code for an async POST request works very much as expected.

But no luck with DELETE.

Somehow it doesn't write JSON string into its request body. The code is almost identical with POST. For debugging, I don't feed an AsyncCompletionHandler instance to execute() method.

System.out.println(ofEntry.toJson());  // this returns {"name": "xyz"} as expected.

Future<Response> f = httpClient.prepareRequest(new RequestBuilder("DELETE")
                                     .setUrl("http://" + myControllerBaseUrl + urlPathFlowPostDelete)
                                     .setHeader("content-type", "application/json")
                                     .setBody(ofEntry.toJson())
                                     .build()).execute();

System.out.println(f.getStatusCode());  // returns 200.

System.out.println(f.getResponseBody()); // returns {"status" : "Error! No data posted."}.

Just to make sure, I peeped into packet dump with wireshark, and found out the server isn't lying :)

The author of the library has written an extensive amount of relevant, valuable information, but unfortunately I can't find example code specifically for building a DELETE request.

I'd very much appreciate any suggestions, pointers, and of course pinpoint solutions!

4

1 に答える 1