in notification/src/main/java/org/opensearch/alerting/destination/message/CustomWebhookMessage.java [33:92]
private CustomWebhookMessage(final DestinationType destinationType,
final String destinationName,
final String url,
final String scheme,
final String host,
final Integer port,
final String path,
final String method,
final Map<String, String> queryParams,
final Map<String, String> headerParams,
final String userName,
final String password,
final String message) {
super(destinationType, destinationName, message);
if (DestinationType.CUSTOMWEBHOOK != destinationType) {
throw new IllegalArgumentException("Channel Type does not match CustomWebhook");
}
if (!Strings.isNullOrEmpty(url)) {
setUrl(url.trim());
}
if (Strings.isNullOrEmpty(message)) {
throw new IllegalArgumentException("Message content is missing");
}
this.scheme = Strings.isNullOrEmpty(scheme) ? "https" : scheme;
this.port = port==null ? -1 : port;
if (!Strings.isNullOrEmpty(path)) {
if (!path.startsWith("/")) {
this.path = "/" + path;
}
}
if(Strings.isNullOrEmpty(url) && Strings.isNullOrEmpty(host)) {
throw new IllegalArgumentException("Either fully qualified URL or host name should be provided");
}
if (Strings.isNullOrEmpty(method)){
// Default to POST for backwards compatibility
this.method = "POST";
} else if (!HttpPost.METHOD_NAME.equals(method) && !HttpPut.METHOD_NAME.equals(method)
&& !HttpPatch.METHOD_NAME.equals(method)) {
throw new IllegalArgumentException("Invalid method supplied. Only POST, PUT and PATCH are allowed");
} else {
this.method = method;
}
this.message = message;
this.url = url;
this.host = host;
this.queryParams = queryParams;
this.headerParams = headerParams;
this.userName = userName;
this.password = password;
}