blogger templates blogger widgets
This is part of a list of blog posts.
To browse the contents go to

JAX-RS: Sending/Receiving JSON data

Server code,
public class HelloResource {
    public JSONObject helloPost(JSONObject jsonRequest) {
        JSONObject jsonResponse = new JSONObject();
        jsonResponse.put("ab",  jsonRequest.get("a").toString()+jsonRequest.get("b"));
     return jsonResponse;


Client code,
String lsUrl = "http://localhost:9080/RSServer/HelloApp/hello";
RestClient client = new RestClient();

Resource resource = client.resource(lsUrl);

JSONObject json = new JSONObject();

json.put("a", "hello");
json.put("b", " world");

System.out.println("JSON input: "+json);

String result = (String) resource.contentType(MediaType.APPLICATION_JSON).post(String.class, json);
{"ab":"hello world"}

No comments:

Post a Comment