Change your curl to:
curl -X POST -d '{"symbol": "GOOG","name": "Google Inc.","high":
190.23,"low": 187.45}' "http://localhost:8080/hello2/2"InputStream doesn't work like that in MSF4J. Check the streaming sample for details https://github.com/wso2/msf4j/tree/master/samples/fileserver On Tue, May 3, 2016 at 4:53 PM, Yasith Lokuge <[email protected]> wrote: > Hi, > > I tried to send a json post request to the sample microservice I built > using wso2 ms4j framework. > > It works with the pojo class as in the below example (POST service/1) but > doesn't work with the String type and InputStream type. > > Please refer the following java code / curl request and the error I > received. > > > package org.example.service; > import java.io.BufferedReader;import java.io.InputStream;import > java.io.InputStreamReader; > import javax.ws.rs.Consumes;import javax.ws.rs.GET;import > javax.ws.rs.POST;import javax.ws.rs.Path;import javax.ws.rs.core.MediaType; > @Path("/service")public class HelloService { > > @GET > @Path("/") > public String get() { > System.out.println("GET invoked"); > return "Hello from WSO2 MSF4J"; > } > > @POST > @Path("/1") > @Consumes(MediaType.APPLICATION_JSON) > public void postOne(Stock stock) { > > System.out.println("POST_1 invoked"); > System.out.println(stock.getName()); > } > > @POST > @Path("/2") > @Consumes(MediaType.APPLICATION_JSON) > public void postTwo(String jsonbody) { > > System.out.println("POST_2 invoked"); > System.out.println(jsonbody); > } > > @POST > @Path("/3") > @Consumes(MediaType.APPLICATION_JSON) > public void postThree(InputStream jsonData) { > StringBuilder stringData = new StringBuilder(); > try { > BufferedReader in = new BufferedReader(new > InputStreamReader(jsonData)); > String line = null; > while ((line = in.readLine()) != null) { > stringData.append(line); > } > } catch (Exception e) { > e.printStackTrace(); > } > System.out.println("POST_3 invoked"); > System.out.println(stringData.toString()); > } > } > > > > curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" > -d '{"symbol": "GOOG","name": "Google Inc.","high": 190.23,"low": 187.45}' > "http://localhost:8080/service/2" > > Error in executing request: POST /service/2 > > curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" > -d '{"symbol": "GOOG","name": "Google Inc.","high": 190.23,"low": 187.45}' > "http://localhost:8080/service/3" > > Error in executing request: POST /service/3 > > *Plain Text* > > > > curl -X POST -H "Content-Type: text/plain" -H "Cache-Control: no-cache" -d > '{"symbol": "GOOG","name": "Google Inc.","high": 190.23,"low": 187.45}' > "http://localhost:8080/service/2" > > Problem accessing: /service/2. Reason: Unsupported Media Type > > curl -X POST -H "Content-Type: text/plain" -H "Cache-Control: no-cache" -d > '{"symbol": "GOOG","name": "Google Inc.","high": 190.23,"low": 187.45}' > "http://localhost:8080/service/3" > > Problem accessing: /service/3. Reason: Unsupported Media Type > > -- > *Regards,* > *-Yasith Kanchana Lokuge-* > > website : http://www.techsurgeinnovations.com/ > facebook : https://www.facebook.com/yasithlokuge > linkedin : http://lk.linkedin.com/pub/yasith-lokuge/1b/713/229/ > Mobile : +94771353682 > Skype : yasith11 > Twitter : @YasithLokuge > > _______________________________________________ > Dev mailing list > [email protected] > http://wso2.org/cgi-bin/mailman/listinfo/dev > > -- *Afkham Azeez* Director of Architecture; WSO2, Inc.; http://wso2.com Member; Apache Software Foundation; http://www.apache.org/ * <http://www.apache.org/>* *email: **[email protected]* <[email protected]> * cell: +94 77 3320919blog: **http://blog.afkham.org* <http://blog.afkham.org> *twitter: **http://twitter.com/afkham_azeez* <http://twitter.com/afkham_azeez> *linked-in: **http://lk.linkedin.com/in/afkhamazeez <http://lk.linkedin.com/in/afkhamazeez>* *Lean . Enterprise . Middleware*
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
