code: protected void populateVelocityContext(VelocityContext velocityContext, MessageContext<SAMLObject> messageContext,
                                             String endpointURL) throws MessageEncodingException {
  
          String encodedEndpointURL = HTMLEncoder.encodeForHTMLAttribute(endpointURL);
          log.debug("Encoding action url of '{}' with encoded value '{}'", endpointURL, encodedEndpointURL);
          velocityContext.put("action", encodedEndpointURL);
          velocityContext.put("binding", getBindingURI());
  
          SAMLObject outboundMessage = messageContext.getMessage();
  
          log.debug("Marshalling and Base64 encoding SAML message");
          Element domMessage = marshallMessage(outboundMessage);
  
          String messageXML = SerializeSupport.nodeToString(domMessage);
          log.trace("Output XML message: {}", messageXML);
          String encodedMessage = Base64Support.encode(messageXML.getBytes(StandardCharsets.UTF_8), Base64Support.UNCHUNKED);
          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");
          }
  
          String relayState = SAMLBindingSupport.getRelayState(messageContext);
          if (SAMLBindingSupport.checkRelayState(relayState)) {
              String encodedRelayState = HTMLEncoder.encodeForHTMLAttribute(relayState);
              log.debug("Setting RelayState parameter to: '{}', encoded as '{}'", relayState, encodedRelayState);
              velocityContext.put("RelayState", encodedRelayState);
          }
      }
docs: 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