public final T encode(final RequestAbstractType request, final T samlObject,
                          final String relayState,
                          final MessageContext messageContext) throws SamlException {
        if (httpResponse != null) {
            val encoder = getMessageEncoderInstance();
            encoder.setHttpServletResponseSupplier(() -> httpResponse);

            val ctx = getEncoderMessageContext(request, samlObject, relayState, messageContext);
            encoder.setMessageContext(ctx);
            finalizeEncode(request, encoder, samlObject, relayState, messageContext);
        }
        return samlObject;

    }
Encode.

@param request        the request
@param samlObject     the saml response
@param relayState     the relay state
@param messageContext the message context
@return the response
@throws SamlException the saml exception
support/cas-server-support-saml-idp-web/src/main/java/org/apereo/cas/support/saml/web/idp/profile/builders/enc/encoder/BaseHttpServletAwareSamlObjectEncoder.java