Event name is now sent as part of the URI

This commit is contained in:
Mauro Mugnaini 2020-06-24 09:52:51 +02:00
parent 159da23f7b
commit 9f56248a54
1 changed files with 15 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import org.gcube.oidc.rest.JWTToken;
@ -32,15 +33,22 @@ public class HTTPEventSender implements EventSender {
if (log.isDebugEnabled()) {
log.debug("Starting HTTP POST thread to: " + endpoint);
}
new Thread(new HTTPost(event.toJSONString())).start();
try {
URL eventEndpoint = new URL(endpoint, event.getName());
new Thread(new HTTPost(eventEndpoint, event.toJSONString())).start();
} catch (MalformedURLException e) {
log.error("Cannot compute event endpoint URL. Event name: " + event.getName() + ", base endpoint: "
+ endpoint, e);
}
}
public class HTTPost implements Runnable {
private String json;
private URL endpoint;
private String jsonString;
public HTTPost(String json) {
this.json = json;
public HTTPost(URL endpoint, String jsonString) {
this.jsonString = jsonString;
}
@Override
@ -64,7 +72,7 @@ public class HTTPEventSender implements EventSender {
if (log.isTraceEnabled()) {
log.trace("Sending event JSON");
}
os.write(json.getBytes("UTF-8"));
os.write(jsonString.getBytes("UTF-8"));
os.close();
StringBuilder sb = new StringBuilder();
@ -101,4 +109,5 @@ public class HTTPEventSender implements EventSender {
}
}
}
}
}