code: public HttpEntity<byte[]> getMetadata(HttpServletRequest request, @RequestHeader(name = "Accept", required = false) String acceptHeader) {
  
      logger.debug("Request to download metadata from {}", request.getRemoteAddr());
  
      try {
  
        // Check if the metadata is up-to-date according to how the container was configured.
        //
        if (this.metadataContainer.updateRequired(true)) {
          logger.debug("Metadata needs to be updated ...");
          this.metadataContainer.update(true);
          logger.debug("Metadata was updated and signed");
        }
        else {
          logger.debug("Metadata is up-to-date, using cached metadata");
        }
  
        // Get the DOM for the metadata and serialize it.
        //
        Element dom = this.metadataContainer.marshall();
  
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        SerializeSupport.writeNode(dom, stream);
  
        // Assign the HTTP headers.
        //
        HttpHeaders header = new HttpHeaders();
        if (acceptHeader != null && !acceptHeader.contains(APPLICATION_SAML_METADATA)) {
          header.setContentType(MediaType.APPLICATION_XML);
        }
        else {
          header.setContentType(MediaType.valueOf(APPLICATION_SAML_METADATA));
        }
        // TODO: turn off caching
  
        byte[] documentBody = stream.toByteArray();
        header.setContentLength(documentBody.length);
        return new HttpEntity<byte[]>(documentBody, header);
      }
      catch (SignatureException | MarshallingException e) {
        logger.error("Failed to return valid metadata", e);
        return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);
      }
    }
docs: Returns the metadata for the entity.
  
  @param request
  the HTTP request
  @param acceptHeader
  the Accept header value
  @return an HttpEntity holding the SAML metadata