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!

user2809249
  • 11
  • 1
  • 3

1 Answers1

0

Not sure that replying to my own question is appropriate here, but I have just found a related thread at the floodlight-dev Google group.

Problem with Static Flow Pusher DELETE REST method

So this could be a problem with Floodlight REST API which requires message body for a DELETE request to identify what to be deleted, whereas AHC is simply compliant with RFC2616.

I will follow the thread at Google group, and see how it will conclude among developers.

user2809249
  • 11
  • 1
  • 3
  • Updates: Floodlight dev people appear to have already merged the RFC2616 patches into the master branch. I have just checked it out and modified the code. Now my app can both push and delete flow entries! – user2809249 Sep 26 '13 at 22:23
  • Addendum: As of now the doc at http://www.openflowhub.org/display/floodlightcontroller/Static+Flow+Pusher+API+%28New%29 is still outdated. The correct path to store a static flow is /wm/staticflowentrypusher/json/store. To delete a flow make a POST request to /wm/staticflowentrypusher/json/delete. – user2809249 Sep 26 '13 at 22:40