protected void populateVelocityContext(final Context velocityContext, final MessageContext messageContext,
                                           final String endpointURL) throws MessageEncodingException {

        val encodedEndpointURL = HTMLEncoder.encodeForHTMLAttribute(endpointURL);
        LOGGER.debug("Encoding action url of '{}' with encoded value '{}'", endpointURL, encodedEndpointURL);
        velocityContext.put("action", encodedEndpointURL);
        velocityContext.put("binding", getBindingURI());

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

        LOGGER.debug("Marshalling and Base64 encoding SAML message");
        val domMessage = marshallMessage(outboundMessage);

        val messageXML = SerializeSupport.nodeToString(domMessage);
        LOGGER.trace("Output XML message: {}", messageXML);
        final String encodedMessage;
        try {
            encodedMessage = Base64Support.encode(messageXML.getBytes(StandardCharsets.UTF_8), Base64Support.UNCHUNKED);
        } catch (final Exception e) {
            throw new MessageEncodingException(e);
        }

        if (outboundMessage instanceof RequestAbstractType) {
            velocityContext.put("SAMLRequest", encodedMessage);
        } else if (outboundMessage instanceof StatusResponseType) {
            velocityContext.put("SAMLResponse", encodedMessage);
        } else {
            throw new MessageEncodingException("SAML message is neither a SAML RequestAbstractType or StatusResponseType");
        }

        val relayState = SAMLBindingSupport.getRelayState(messageContext);
        if (SAMLBindingSupport.checkRelayState(relayState)) {
            val encodedRelayState = HTMLEncoder.encodeForHTMLAttribute(relayState);
            LOGGER.debug("Setting RelayState parameter to: '{}', encoded as '{}'", relayState, encodedRelayState);
            velocityContext.put("RelayState", encodedRelayState);
        }
    }
Populate the Velocity context instance which will be used to render the POST body.

@param velocityContext the Velocity context instance to populate with data
@param messageContext  the SAML message context source of data
@param endpointURL     endpoint URL to which to encode message
@throws MessageEncodingException thrown if there is a problem encoding the message
pac4j-saml/src/main/java/org/pac4j/saml/transport/Pac4jHTTPPostEncoder.java