private static String getMetadataAsString(final EntityDescriptor descriptor)
      throws MarshallingException {

    final MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory();
    final Marshaller marshaller = marshallerFactory.getMarshaller(descriptor);
    final Element element = marshaller.marshall(descriptor);
    return XMLHelper.nodeToString(element);
  }
  @Test
  public void testEncryptedAssertionWithRetrievalMethod() throws Exception {
    EncryptedAssertion encrypted = encryptAssertion(false);
    srt.getAssertions().clear();
    srt.getEncryptedAssertions().add(encrypted);

    System.out.println(XMLHelper.nodeToString(SAMLUtil.marshallObject(encrypted)));

    response.decryptAssertion(credential, false);
    assertNotNull(response.getAssertion());
  }
  /**
   * DEFLATE (RFC1951) compresses the given SAML message.
   *
   * @param message SAML message
   * @return DEFLATE compressed message
   * @throws MessageEncodingException thrown if there is a problem compressing the message
   */
  protected String deflateAndBase64Encode(SAMLObject message) throws MessageEncodingException {
    log.debug("Deflating and Base64 encoding SAML message");
    try {
      String messageStr = XMLHelper.nodeToString(marshallMessage(message));

      ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
      Deflater deflater = new Deflater(Deflater.DEFLATED, true);
      DeflaterOutputStream deflaterStream = new DeflaterOutputStream(bytesOut, deflater);
      deflaterStream.write(messageStr.getBytes());
      deflaterStream.finish();

      return Base64.encodeBytes(bytesOut.toByteArray(), Base64.DONT_BREAK_LINES);
    } catch (IOException e) {
      throw new MessageEncodingException("Unable to DEFLATE and Base64 encode SAML message", e);
    }
  }