I am new to Jersey. I need to implement a Jersey client to submit data with POST method. The curl command is:
curl -d '{"switch": "00:00:00:00:00:00:00:01", "name":"flow-mod-1", "priority":"32768", "ingress-port":"1","active":"true", "actions":"output=2"}' http://localhost:8080/wm/staticflowentrypusher/json
So I am trying to figure out how to use Jersey client to implement the above curl command.
So far I have done:
public class FLClient {
private static Client client;
private static WebResource webResource;
private static String baseuri = "http://localhost:8080/wm/staticflowentrypusher/json";
private static ClientResponse response;
private static String output = null;
public static void main(String[] args) {
try {
client = Client.create();
webResource = client.resource(baseuri);
// implement POST data
} catch (Exception e) {
e.printStackTrace();
}
}
}
Can someone help me with it?
If you want to post within a JSON body, here is a better approach.
Remember you have to include
jersey-json
Now I figure it out. Here is my solution:
For future users, with the new version of
jersey
things has changed, so the way of doing such POST method is:For versions
1.x
(@Li' answer) :For versions
2.x
:Based on the Migration Guide