@Override
  public Object encode(SoapResponse objectToEncode, Map<HelperValues, String> additionalValues)
      throws EncodingException {
    AbstractServiceResponse bodyContent = objectToEncode.getBodyContent();

    /*
     * Special case: NoContent
     */
    if (bodyContent instanceof NoContentResponse) {
      return new NoContent();
    }

    EnvelopeDocument envDoc = EnvelopeDocument.Factory.newInstance();
    Envelope env = envDoc.addNewEnvelope();

    Body body = env.addNewBody();

    OwsExceptionReport exception = null;
    if (bodyContent != null) {
      try {
        body.set(encodeBody(bodyContent));
      } catch (OwsExceptionReport e) {
        exception = e;
        LOG.warn(exception.getMessage(), exception);
      }
    } else {
      exception = objectToEncode.getException();
    }

    if (exception != null) {
      body.set(encodeException(exception));
    }

    return envDoc;
  }
  @Test
  public void shouldCreateValidLevel1SubscribeRequest() throws OXFException, XmlException {
    String consumer = "http://*****:*****@xlink:href='urn:ogc:object:procedure:CITE:WeatherService:LGA'";

    ParameterContainer parameter = new ParameterContainer();
    parameter.addParameterShell(ISESRequestBuilder.SUBSCRIBE_SES_URL, host);
    parameter.addParameterShell(ISESRequestBuilder.SUBSCRIBE_CONSUMER_REFERENCE_ADDRESS, consumer);
    parameter.addParameterShell(ISESRequestBuilder.SUBSCRIBE_FILTER_TOPIC, topicString);
    parameter.addParameterShell(
        ISESRequestBuilder.SUBSCRIBE_FILTER_MESSAGE_CONTENT_DIALECT, dialect);
    parameter.addParameterShell(ISESRequestBuilder.SUBSCRIBE_FILTER_MESSAGE_CONTENT, xpath);

    SESRequestBuilder_00 request = new SESRequestBuilder_00();
    String asText = request.buildSubscribeRequest(parameter);
    EnvelopeDocument envelope = EnvelopeDocument.Factory.parse(asText);

    Collection<XmlError> errors = XMLBeansParser.validate(envelope);
    Assert.assertTrue("SubscribeRequest is not valid: " + errors, errors.isEmpty());

    Body body = envelope.getEnvelope().getBody();
    XmlCursor cur = body.newCursor();
    cur.toFirstChild();
    XmlObject subscribeRequestObject = cur.getObject();
    cur.dispose();

    if (!(subscribeRequestObject instanceof Subscribe))
      throw new IllegalStateException("Body does not contain a Subscribe request.");

    Subscribe subscribeRequest = (Subscribe) subscribeRequestObject;
    Assert.assertTrue(
        subscribeRequest
            .getConsumerReference()
            .getAddress()
            .getStringValue()
            .trim()
            .equals(consumer.trim()));

    cur = subscribeRequest.getFilter().newCursor();
    cur.toFirstChild();
    do {
      XmlObject filterElement = cur.getObject();
      if (filterElement instanceof QueryExpressionType) {
        QueryExpressionType qet = (QueryExpressionType) filterElement;
        Assert.assertTrue(qet.getDialect().trim().equals(dialect.trim()));
        XmlCursor tmpCur = qet.newCursor();
        Assert.assertTrue(tmpCur.toFirstContentToken() == TokenType.TEXT);
        Assert.assertTrue(tmpCur.getChars().trim().equals(xpath.trim()));
      } else if (filterElement instanceof TopicExpressionType) {
        TopicExpressionType tet = (TopicExpressionType) filterElement;
        Assert.assertTrue(
            tet.getDialect().trim().equals(SESRequestBuilder_00.DEFAULT_TOPIC_DIALECT));
        XmlCursor tmpCur = tet.newCursor();
        Assert.assertTrue(tmpCur.toFirstContentToken() == TokenType.TEXT);
        Assert.assertTrue(tmpCur.getChars().trim().equals(topicString.trim()));
      }
    } while (cur.toNextSibling());
  }