Example #1
0
  @Validated
  @Test
  public void testExamineHeaderElements2() throws Exception {
    javax.xml.soap.SOAPMessage soapMessage =
        javax.xml.soap.MessageFactory.newInstance().createMessage();

    javax.xml.soap.SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope();
    javax.xml.soap.SOAPHeader header = soapEnv.getHeader();
    SOAPHeaderElement soapHeaderElement = null;

    try {
      // Add some soap header elements
      SOAPElement se =
          header
              .addHeaderElement(envelope.createName("Header1", "prefix", "http://myuri"))
              .addTextNode("This is Header1");
      soapHeaderElement = (SOAPHeaderElement) se;
      soapHeaderElement.setMustUnderstand(true);

      se =
          header
              .addHeaderElement(envelope.createName("Header2", "prefix", "http://myuri"))
              .addTextNode("This is Header2");
      soapHeaderElement = (SOAPHeaderElement) se;
      soapHeaderElement.setMustUnderstand(false);

      se =
          header
              .addHeaderElement(envelope.createName("Header3", "prefix", "http://myuri"))
              .addTextNode("This is Header3");
      soapHeaderElement = (SOAPHeaderElement) se;
      soapHeaderElement.setMustUnderstand(true);

      se =
          header
              .addHeaderElement(envelope.createName("Header4", "prefix", "http://myuri"))
              .addTextNode("This is Header4");
      soapHeaderElement = (SOAPHeaderElement) se;
      soapHeaderElement.setMustUnderstand(false);

      Iterator iterator = header.examineAllHeaderElements();

      // validating Iterator count .... should be 4");
      int cnt = 0;
      while (iterator.hasNext()) {
        cnt++;
        soapHeaderElement = (SOAPHeaderElement) iterator.next();
      }
      assertEquals(cnt, 4);
      iterator = header.examineHeaderElements(SOAPConstants.URI_SOAP_ACTOR_NEXT);
      cnt = 0;
      while (iterator.hasNext()) {
        cnt++;
        soapHeaderElement = (SOAPHeaderElement) iterator.next();
      }
      assertEquals(cnt, 0);
    } catch (Exception e) {
      fail("Unexpected Exception: " + e);
    }
  }
Example #2
0
  @Validated
  @Test
  public void testExamineHeaderElements() throws Exception {
    javax.xml.soap.SOAPMessage soapMessage =
        javax.xml.soap.MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();

    javax.xml.soap.SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope();
    javax.xml.soap.SOAPHeader header = soapEnv.getHeader();

    SOAPHeaderElement soapHeaderElement =
        header.addHeaderElement(envelope.createName("foo1", "f1", "foo1-URI"));

    Iterator iterator = null;
    soapHeaderElement.setRole("role-URI");

    iterator = header.examineHeaderElements("role1-URI");

    int count = 0;
    while (iterator.hasNext()) {
      count++;
      iterator.next();
    }
    assertEquals(0, count);
  }