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.