mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: webhook HTTP headers improvements
parent
86540ab3a8
commit
843fdb7b30
|
@ -352,7 +352,6 @@ public class OpenviduConfig {
|
|||
}
|
||||
|
||||
public void initiateOpenViduWebhookHeaders(String headers) throws Exception {
|
||||
if (webhookHeadersList == null) {
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement elem = parser.parse(headers);
|
||||
JsonArray headersJsonArray = elem.getAsJsonArray();
|
||||
|
@ -367,14 +366,20 @@ public class OpenviduConfig {
|
|||
}
|
||||
String headerName = headerSplit[0];
|
||||
String headerValue = headerSplit[1];
|
||||
if (headerName.isEmpty()) {
|
||||
throw new Exception(
|
||||
"HTTP header '" + headerString + "' syntax is not correct. Header name cannot be empty");
|
||||
}
|
||||
if (headerValue.isEmpty()) {
|
||||
throw new Exception(
|
||||
"HTTP header '" + headerString + "' syntax is not correct. Header value cannot be empty");
|
||||
}
|
||||
this.webhookHeadersList.add(new BasicHeader(headerName, headerValue));
|
||||
}
|
||||
log.info("OpenVidu Webhook headers: {}", this.getOpenViduWebhookHeaders().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void initiateOpenViduWebhookEvents(String events) throws Exception {
|
||||
if (webhookEventsList == null) {
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement elem = parser.parse(events);
|
||||
JsonArray eventsJsonArray = elem.getAsJsonArray();
|
||||
|
@ -391,6 +396,5 @@ public class OpenviduConfig {
|
|||
}
|
||||
log.info("OpenVidu Webhook events: {}", this.getOpenViduWebhookEvents().toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.security.KeyStoreException;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -57,27 +58,26 @@ public class HttpWebhookSender {
|
|||
|
||||
private HttpClient httpClient;
|
||||
private String httpEndpoint;
|
||||
private List<Header> headers;
|
||||
private List<Header> customHeaders;
|
||||
private List<CDREventName> events;
|
||||
|
||||
public HttpWebhookSender(String httpEndpoint, List<Header> headers, List<CDREventName> events) {
|
||||
this.httpEndpoint = httpEndpoint;
|
||||
this.headers = headers;
|
||||
|
||||
boolean contentTypeHeaderAdded = false;
|
||||
for (Header header : this.headers) {
|
||||
if (HttpHeaders.CONTENT_TYPE.equals(header.getName()) && "application/json".equals(header.getValue())) {
|
||||
contentTypeHeaderAdded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!contentTypeHeaderAdded) {
|
||||
headers.add(new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"));
|
||||
}
|
||||
|
||||
this.events = events;
|
||||
|
||||
this.customHeaders = new ArrayList<>();
|
||||
boolean contentTypeHeaderAdded = false;
|
||||
for (Header header : headers) {
|
||||
this.customHeaders.add(header);
|
||||
if (!contentTypeHeaderAdded && HttpHeaders.CONTENT_TYPE.equals(header.getName())
|
||||
&& "application/json".equals(header.getValue())) {
|
||||
contentTypeHeaderAdded = true;
|
||||
}
|
||||
}
|
||||
if (!contentTypeHeaderAdded) {
|
||||
this.customHeaders.add(new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"));
|
||||
}
|
||||
|
||||
TrustStrategy trustStrategy = new TrustStrategy() {
|
||||
@Override
|
||||
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||
|
@ -124,7 +124,7 @@ public class HttpWebhookSender {
|
|||
log.error("Cannot create StringEntity from JSON CDREvent. Default HTTP charset is not supported");
|
||||
}
|
||||
|
||||
for (Header header : this.headers) {
|
||||
for (Header header : this.customHeaders) {
|
||||
request.setHeader(header);
|
||||
}
|
||||
request.setEntity(params);
|
||||
|
|
Loading…
Reference in New Issue