protected String buildRedirectURL(final MessageContext messageContext, final String endpoint, final String message)
        throws MessageEncodingException {
        LOGGER.debug("Building URL to redirect client to");

        final URLBuilder urlBuilder;
        try {
            urlBuilder = new URLBuilder(endpoint);
        } catch (final MalformedURLException e) {
            throw new MessageEncodingException("Endpoint URL " + endpoint + " is not a valid URL", e);
        }

        val queryParams = urlBuilder.getQueryParams();
        // remove the query parameters set below
        queryParams.removeIf(p ->
            p.getFirst().equals("SAMLRequest") ||
                p.getFirst().equals("SAMLResponse") ||
                p.getFirst().equals("RelayState") ||
                p.getFirst().equals("SigAlg") ||
                p.getFirst().equals("Signature"));

        val outboundMessage = (SAMLObject) messageContext.getMessage();

        if (outboundMessage instanceof RequestAbstractType) {
            queryParams.add(new Pair<>("SAMLRequest", message));
        } else if (outboundMessage instanceof StatusResponseType) {
            queryParams.add(new Pair<>("SAMLResponse", message));
        } else {
            throw new MessageEncodingException(
                "SAML message is neither a SAML RequestAbstractType or StatusResponseType");
        }

        val relayState = SAMLBindingSupport.getRelayState(messageContext);
        if (SAMLBindingSupport.checkRelayState(relayState)) {
            queryParams.add(new Pair<>("RelayState", relayState));
        }

        if (isAuthnRequestSigned) {
            val signingParameters =
                SAMLMessageSecuritySupport.getContextSigningParameters(messageContext);
            if (signingParameters != null && signingParameters.getSigningCredential() != null) {
                val sigAlgURI = getSignatureAlgorithmURI(signingParameters);
                val sigAlg = new Pair<>("SigAlg", sigAlgURI);
                queryParams.add(sigAlg);
                val sigMaterial = urlBuilder.buildQueryString();

                queryParams.add(new Pair<>("Signature", generateSignature(
                    signingParameters.getSigningCredential(), sigAlgURI, sigMaterial)));
            } else {
                LOGGER.debug("No signing credential was supplied, skipping HTTP-Redirect DEFLATE signing");
            }
        }

        return urlBuilder.buildURL();
    }
Builds the URL to redirect the client to.

@param messageContext current message context
@param endpoint       endpoint URL to send encoded message to
@param message        Deflated and Base64 encoded message
@return URL to redirect client to
@throws MessageEncodingException thrown if the SAML msg is neither a RequestAbstractType or Response
pac4j-saml/src/main/java/org/pac4j/saml/transport/Pac4jHTTPRedirectDeflateEncoder.java