Client to receive data from a Server-Push

Asked

Viewed 22 times

1

I’m trying to create a client to consume data from an interface that receives data from a gateway. This interface implements a server-push that needs to be started from a client-made PUT request. After the request returns 200, the interface should start sending the data to the path /Rest/callback/payloads/ul as soon as the data reaches her.

In the request are sent log data of my application so that the interface directs the push to the registered application, the file Requisicao.java is as follows:

JsonObject json = new JsonObject();

json.addProperty("host", "http://myhost");
json.addProperty("port", 443);
json.addProperty("path_prefix", "/Omni/servlet");
json.addProperty("auth_string", "Basic " + "user:pass");
json.addProperty("retry_policy", 0);
json.addProperty("data_format", "base64");

Gson gson = new Gson();
String json_string = gson.toJson(json);

URL url = new URL("https://server.orbiwise.com/rest/pushmode/start");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestMethod("PUT");
conn.setRequestProperty("Authorization", "Basic " + "user:pass");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Access-Control-Allow-Origin", "*");

conn.setDoInput(true);
conn.setDoOutput(true);
conn.connect();

OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
out.write(json_string);
out.close();

if (conn.getResponseCode() == 200) {
    System.out.println("SUCCESS!: " + conn.getResponseCode());
} else {
    System.out.println("ERROR: " + conn.getErrorStream() + conn.getResponseCode() );
}

The request is already returning OK and to receive the data from the push I used a Servlet with the same path as the interface documentation requests (/Rest/callback/payloads/ul). But the data isn’t getting to him. If you can help me or give me tips in a simpler way to receive this data, I would appreciate it very much.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.