Domanda

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!

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top