PlayFrameWork 2.6- JAVA WS- send and receive json data

91 views
Skip to first unread message

Rosiene Carvalho

unread,
Oct 16, 2017, 4:04:46 PM10/16/17
to Play Framework

How to send data through a post in the url (using ws (url) .post ()) and how to manipulate that data in the same application

I'm using ws.
and this code to send message via post

        public class WebService implements WSBodyReadables, WSBodyWritables {
         private final WSClient ws;

    @Inject
    public WebService(WSClient ws) {
        this.ws = ws;
        JsonNode json = Json.newObject()
                .put("key1", "value1")
                .put("key2", "value2");

        ws.url("http://localhost:9000/web").post(json);
   

    }


    // ...
}

and I want to receive this data in the controller, I am using this code:


        public class WebServiceController extends Controller{
    @Inject  WSClient ws;
    @Inject
    Materializer materializer;
    private Server server;
    private Content response;




    public CompletionStage<Result> web() {

        return ws.url("http://localhost:9000/web").get().thenApply(response ->
                ok("Feed title: " + response.asJson().findPath("title").asText())
        );
    }

}


But I get this error when accessing the url

'CompletionException: java.lang.RuntimeException: Error parsing JSON from WS response wsBody'



I'm new to playframework, I need to do a webservice where I can give a post with some information, and then access that url and capture that information. Please help me

Reply all
Reply to author
Forward
0 new messages