code: public static void preparePeerEntitySamlEndpointContext(final RequestAbstractType request,
                                                              final MessageContext outboundContext,
                                                              final SamlRegisteredServiceServiceProviderMetadataFacade adaptor,
                                                              final String binding) throws SamlException {
          val entityId = adaptor.getEntityId();
          if (!adaptor.containsAssertionConsumerServices()) {
              throw new SamlException("No assertion consumer service could be found for entity " + entityId);
          }
  
          val peerEntityContext = outboundContext.getSubcontext(SAMLPeerEntityContext.class, true);
          if (peerEntityContext == null) {
              throw new SamlException("SAMLPeerEntityContext could not be defined for entity " + entityId);
          }
          peerEntityContext.setEntityId(entityId);
  
          val endpointContext = peerEntityContext.getSubcontext(SAMLEndpointContext.class, true);
          if (endpointContext == null) {
              throw new SamlException("SAMLEndpointContext could not be defined for entity " + entityId);
          }
  
          val endpoint = determineEndpointForRequest(request, adaptor, binding);
          LOGGER.debug("Configured peer entity endpoint to be [{}] with binding [{}]", endpoint.getLocation(), endpoint.getBinding());
          endpointContext.setEndpoint(endpoint);
      }
docs: Prepare peer entity saml endpoint.
  
  @param request         the authn request
  @param outboundContext the outbound context
  @param adaptor         the adaptor
  @param binding         the binding
  @throws SamlException the saml exception