1

I've used to MSF4J to get a response by a post request. The code for post request handler is as below.

@Path("/psi")
public class HelloService {

   @POST
   @Path("/send")
   @Consumes(MediaType.APPLICATION_JSON)
   @Produces(MediaType.APPLICATION_JSON)
   public JSONObject postWithParams(AppParams params) {

      String imsi = params.getImsi();

      JSONObject json = new JSONObject();

      json.put("imsi", imsi);

      return json;
   } 
}

This service is called by another application.It's shown below

String url = "http://localhost:8080/psi/send";
    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();

    con.setConnectTimeout(5000);
    con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
    con.setDoOutput(true);
    con.setDoInput(true);
    con.setRequestMethod("POST");

    JSONObject msisdn = new JSONObject();

    msisdn.put("msisdn", "94773336050");

    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.write(msisdn.toString().getBytes("UTF-8"));
    wr.flush();
    wr.close();

    BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);

    }
    in.close();

When I run both application together the post request gives required out put but same time it shows ERROR MSF4JHttpConnectorListener and that error console output like below.

Error in console ERROR MSF4JHttpConnectorListener

  • Please don't put any text in images. Attach your stack trace as a block of code instead. – SeverityOne Apr 10 '18 at 07:38
  • hm my gut feeling is that you are closing the input stream from client side before the response fully get write. Can you comment out the in.close(); and check if that is the case? If that is the case – Thusitha Thilina Dayaratne Apr 10 '18 at 20:38

0 Answers0