Search in sources :

Example 1 with StreamHeader11

use of com.sun.xml.ws.message.stream.StreamHeader11 in project metro-jax-ws by eclipse-ee4j.

the class SAAJMessageHeadersTest method testMustUnderstand2.

/**
 * Tests mustUnderstand using the getHeaders call with boolean rather than the "understood(..)" call
 */
public void testMustUnderstand2() throws Exception {
    SOAPMessage sm = makeSOAPMessage(MESSAGE);
    // SAAJMessage saajMsg = new SAAJMessage(sm);
    MessageHeaders hdrs = new SAAJMessageHeaders(sm, SOAPVersion.SOAP_11);
    // new must understand header
    Header newHdr = new StringHeader(new QName("myNs", "stringHeader1"), "stringHeaderValue1", SOAPVersion.SOAP_11, true);
    hdrs.add(newHdr);
    String hdrTxt = "<streamHeader1 S:mustUnderstand=\"true\" xmlns=\"myNs\" xmlns:S=\"" + SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE + "\">streamHeaderValue1</streamHeader1>";
    ByteArrayInputStream bis = new ByteArrayInputStream(hdrTxt.getBytes());
    XMLStreamReader rdr = XMLInputFactory.newInstance().createXMLStreamReader(bis);
    while (rdr.getEventType() != XMLStreamReader.START_ELEMENT) rdr.next();
    newHdr = new StreamHeader11(rdr);
    hdrs.add(newHdr);
    hdrTxt = "<streamHeader2 S:mustUnderstand=\"true\" xmlns=\"mySecondNs\" xmlns:S=\"" + SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE + "\">streamHeaderValue2</streamHeader2>";
    bis = new ByteArrayInputStream(hdrTxt.getBytes());
    rdr = XMLInputFactory.newInstance().createXMLStreamReader(bis);
    while (rdr.getEventType() != XMLStreamReader.START_ELEMENT) rdr.next();
    newHdr = new StreamHeader11(rdr);
    hdrs.add(newHdr);
    // now add a non-must understand string header
    newHdr = new StringHeader(new QName("myNs", "stringHeader2"), "stringHeaderValue2", SOAPVersion.SOAP_11, false);
    hdrs.add(newHdr);
    Set<QName> notUnderstoods = hdrs.getNotUnderstoodHeaders(null, null, null);
    assertNotNull(notUnderstoods);
    assertEquals(3, notUnderstoods.size());
    // mark hte headers in "myNs" namespace as understood when retrieving them
    Iterator<Header> myNsHeaders = hdrs.getHeaders("myNs", true);
    notUnderstoods = hdrs.getNotUnderstoodHeaders(null, null, null);
    assertNotNull(notUnderstoods);
    // should be only one header left that is not understood, and it should be the
    // mySecondNs header
    assertEquals(1, notUnderstoods.size());
    QName q = notUnderstoods.iterator().next();
    assertEquals(new QName("mySecondNs", "streamHeader2"), q);
    // Now examine the headers we marked as understood and make sure they are the right ones
    int myNsCount = 0;
    while (myNsHeaders.hasNext()) {
        Header h = myNsHeaders.next();
        assertNotNull(h);
        assertTrue(h instanceof SAAJHeader);
        assertEquals("myNs", h.getNamespaceURI());
        assertTrue("Unexpected header local name: " + h.getLocalPart() + " - must be streamHeader1 or stringHeader1 or stringHeader2", "streamHeader1".equals(h.getLocalPart()) || "stringHeader1".equals(h.getLocalPart()) || "stringHeader2".equals(h.getLocalPart()));
        myNsCount++;
    }
    assertEquals(3, myNsCount);
    Header h = hdrs.get("myNs", "stringHeader2", false);
    // this should be the non-must understand header, still there
    assertNotNull(h);
}
Also used : StringHeader(com.sun.xml.ws.message.StringHeader) XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) SOAPMessage(jakarta.xml.soap.SOAPMessage) SAAJMessageHeaders(com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders) StringHeader(com.sun.xml.ws.message.StringHeader) Header(com.sun.xml.ws.api.message.Header) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamHeader11(com.sun.xml.ws.message.stream.StreamHeader11) SAAJMessageHeaders(com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders) MessageHeaders(com.sun.xml.ws.api.message.MessageHeaders)

Aggregations

Header (com.sun.xml.ws.api.message.Header)1 MessageHeaders (com.sun.xml.ws.api.message.MessageHeaders)1 SAAJMessageHeaders (com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders)1 StringHeader (com.sun.xml.ws.message.StringHeader)1 StreamHeader11 (com.sun.xml.ws.message.stream.StreamHeader11)1 SOAPMessage (jakarta.xml.soap.SOAPMessage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 QName (javax.xml.namespace.QName)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1