private LegacyCustomWebhookMessage()

in src/main/java/org/opensearch/commons/destination/message/LegacyCustomWebhookMessage.java [55:104]


    private LegacyCustomWebhookMessage(
        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 message
    ) {
        super(LegacyDestinationType.LEGACY_CUSTOM_WEBHOOK, destinationName, message);

        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;
    }