Search in sources :

Example 1 with SAAJMessageHeaders

use of com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders in project metro-jax-ws by eclipse-ee4j.

the class SAAJMessageHeadersTest method testMustUnderstand.

public void testMustUnderstand() 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);
    Set<QName> notUnderstoods = hdrs.getNotUnderstoodHeaders(null, null, null);
    assertNotNull(notUnderstoods);
    assertEquals(1, notUnderstoods.size());
    // verify the understood headers list
    Set<QName> understoods = hdrs.getUnderstoodHeaders();
    // none of the headers is marked understood
    assertNull(understoods);
    // assertEquals(1, understoods.size());
    // the new header should not be understood yet
    assertFalse(hdrs.isUnderstood(newHdr));
    // now "understand" the header
    hdrs.understood(newHdr);
    // the new header should be understood now
    assertTrue(hdrs.isUnderstood(newHdr));
    notUnderstoods = hdrs.getNotUnderstoodHeaders(null, null, null);
    assertNotNull(notUnderstoods);
    assertEquals(0, notUnderstoods.size());
    // make sure the newly understood header now shows up in the understoodHeaders
    understoods = hdrs.getUnderstoodHeaders();
    assertNotNull(understoods);
    assertEquals(1, understoods.size());
}
Also used : SAAJMessageHeaders(com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders) StringHeader(com.sun.xml.ws.message.StringHeader) StringHeader(com.sun.xml.ws.message.StringHeader) Header(com.sun.xml.ws.api.message.Header) QName(javax.xml.namespace.QName) SAAJMessageHeaders(com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders) MessageHeaders(com.sun.xml.ws.api.message.MessageHeaders) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 2 with SAAJMessageHeaders

use of com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders in project metro-jax-ws by eclipse-ee4j.

the class SAAJMessageHeadersTest method testGetHeader.

public void testGetHeader() throws Exception {
    // SAAJMessage saajMsg = new SAAJMessage(makeSOAPMessage());
    MessageHeaders hdrs = new SAAJMessageHeaders(makeSOAPMessage(MESSAGE), SOAPVersion.SOAP_11);
    Header actionHdr = hdrs.get(new QName(ADDRESSING_NS, "Action"), false);
    assertNotNull(actionHdr);
    assertTrue(actionHdr instanceof SAAJHeader);
    SOAPHeaderElement hdrElem = ((SAAJHeader) actionHdr).getWrappedNode();
    assertNotNull(hdrElem);
    assertEquals(ACTION_HDR_VALUE, hdrElem.getFirstChild().getNodeValue());
    Iterator<Header> iter = hdrs.getHeaders(ADDRESSING_NS, false);
    assertTrue(iter.hasNext());
    assertEquals(actionHdr, iter.next());
    hdrs.remove(ADDRESSING_NS, "Action");
    // should be gone after remove
    iter = hdrs.getHeaders(ADDRESSING_NS, false);
    assertFalse(iter.hasNext());
}
Also used : SOAPHeaderElement(jakarta.xml.soap.SOAPHeaderElement) SAAJMessageHeaders(com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders) StringHeader(com.sun.xml.ws.message.StringHeader) Header(com.sun.xml.ws.api.message.Header) QName(javax.xml.namespace.QName) SAAJMessageHeaders(com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders) MessageHeaders(com.sun.xml.ws.api.message.MessageHeaders)

Example 3 with SAAJMessageHeaders

use of com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders in project metro-jax-ws by eclipse-ee4j.

the class SAAJMessageHeadersTest method testGetAllHeaders.

public void testGetAllHeaders() throws Exception {
    String soapMsgStr = "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<env:Header>" + "<wsa:Action xmlns:wsa=\"http://www.w3.org/2005/08/addressing\"></wsa:Action>" + "<wsa:MessageID xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">uuid:40a19d86-071d-4d3f-8b1b-8c8b5245b1de</wsa:MessageID>" + "<wsa:RelatesTo xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">uuid:bd2cf21b-d2ad-4dc6-b0ec-2928736b5ae2</wsa:RelatesTo>" + "<wsa:To xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">http://www.w3.org/2005/08/addressing/anonymous</wsa:To>" + "</env:Header>" + "<env:Body xmlns:wsrm11=\"http://docs.oasis-open.org/ws-rx/wsrm/200702\">" + "<wsrm11:CreateSequenceResponse>" + "<wsrm11:Identifier>35599b13-3672-462a-a51a-31e1820ef236</wsrm11:Identifier>" + "<wsrm11:Expires>P1D</wsrm11:Expires>" + "<wsrm11:IncompleteSequenceBehavior>NoDiscard</wsrm11:IncompleteSequenceBehavior>" + "</wsrm11:CreateSequenceResponse>" + "</env:Body></env:Envelope>";
    SOAPMessage msg = makeSOAPMessage(soapMsgStr);
    int numHdrs = 0;
    MessageHeaders mh = new SAAJMessageHeaders(msg, SOAPVersion.SOAP_11);
    // assertTrue(mh instanceof SAAJMessageHeaders);
    Iterator<Header> iter = mh.getHeaders();
    while (iter.hasNext()) {
        iter.next();
        numHdrs++;
    }
    assertEquals(4, numHdrs);
}
Also used : SAAJMessageHeaders(com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders) StringHeader(com.sun.xml.ws.message.StringHeader) Header(com.sun.xml.ws.api.message.Header) SAAJMessageHeaders(com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders) MessageHeaders(com.sun.xml.ws.api.message.MessageHeaders) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 4 with SAAJMessageHeaders

use of com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders 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)

Example 5 with SAAJMessageHeaders

use of com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders in project metro-jax-ws by eclipse-ee4j.

the class SAAJMessageHeadersTest method testUnderstandingOfHeadersInSoapMessage.

public void testUnderstandingOfHeadersInSoapMessage() throws Exception {
    // this message has one header NOT marked as mustUnderstand
    SOAPMessage sm = makeSOAPMessage(MESSAGE);
    String hdrLocalName = "Action";
    MessageHeaders hdrs = new SAAJMessageHeaders(sm, SOAPVersion.SOAP_11);
    Set<QName> understood = hdrs.getUnderstoodHeaders();
    // header has not been explicity understood so it shoud
    // not be treated as understood
    assertNull(understood);
    assertFalse(hdrs.isUnderstood(ADDRESSING_NS, hdrLocalName));
    hdrs.understood(ADDRESSING_NS, hdrLocalName);
    // now it should be understood
    assertTrue(hdrs.isUnderstood(ADDRESSING_NS, hdrLocalName));
    understood = hdrs.getUnderstoodHeaders();
    assertNotNull(understood);
    assertEquals(1, understood.size());
    QName actionHdrName = understood.iterator().next();
    assertEquals(ADDRESSING_NS, actionHdrName.getNamespaceURI());
    assertEquals(hdrLocalName, actionHdrName.getLocalPart());
    // now a more complex SOAPMessage with 2 mustUnderstand=true headers,
    // one mustUnderstand=false and one with no mustUnderstand specified
    String soapMsgStr = "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<env:Header>" + "<wsa:Action xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" env:mustUnderstand=\"true\"></wsa:Action>" + "<wsa:MessageID xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">uuid:40a19d86-071d-4d3f-8b1b-8c8b5245b1de</wsa:MessageID>" + "<wsa:RelatesTo xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" env:mustUnderstand=\"false\">uuid:bd2cf21b-d2ad-4dc6-b0ec-2928736b5ae2</wsa:RelatesTo>" + "<wsa:To xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" env:mustUnderstand=\"true\">http://www.w3.org/2005/08/addressing/anonymous</wsa:To>" + "</env:Header>" + "<env:Body xmlns:wsrm11=\"http://docs.oasis-open.org/ws-rx/wsrm/200702\">" + "<wsrm11:CreateSequenceResponse>" + "<wsrm11:Identifier>35599b13-3672-462a-a51a-31e1820ef236</wsrm11:Identifier>" + "<wsrm11:Expires>P1D</wsrm11:Expires>" + "<wsrm11:IncompleteSequenceBehavior>NoDiscard</wsrm11:IncompleteSequenceBehavior>" + "</wsrm11:CreateSequenceResponse>" + "</env:Body></env:Envelope>";
    sm = makeSOAPMessage(soapMsgStr);
    hdrs = new SAAJMessageHeaders(sm, SOAPVersion.SOAP_11);
    // check understood headers - none are marked understood yet
    // mustUnderstand = false headers, NOT yet marked as understood
    understood = hdrs.getUnderstoodHeaders();
    assertNull(understood);
    assertFalse(hdrs.isUnderstood(ADDRESSING_NS, "MessageID"));
    assertFalse(hdrs.isUnderstood(ADDRESSING_NS, "RelatesTo"));
    // mark NON-mustUnderstand header MessageID as understood
    // it should now be "understood"
    hdrs.understood(ADDRESSING_NS, "MessageID");
    assertTrue(hdrs.isUnderstood(ADDRESSING_NS, "MessageID"));
    assertFalse(hdrs.isUnderstood(ADDRESSING_NS, "RelatesTo"));
    understood = hdrs.getUnderstoodHeaders();
    assertNotNull(understood);
    assertEquals(1, understood.size());
    QName understoodQName = understood.iterator().next();
    assertEquals(ADDRESSING_NS, understoodQName.getNamespaceURI());
    assertEquals("MessageID", understoodQName.getLocalPart());
    // mark NON-mustUnderstand header RelatesTo as understood
    // it should also now be "understood"
    hdrs.understood(ADDRESSING_NS, "RelatesTo");
    assertTrue(hdrs.isUnderstood(ADDRESSING_NS, "MessageID"));
    assertTrue(hdrs.isUnderstood(ADDRESSING_NS, "RelatesTo"));
    assertEquals(2, understood.size());
    for (QName nextHdrName : understood) {
        assertEquals(ADDRESSING_NS, nextHdrName.getNamespaceURI());
        assertTrue("Unexpected header name " + nextHdrName.getLocalPart(), "MessageID".equals(nextHdrName.getLocalPart()) || "RelatesTo".equals(nextHdrName.getLocalPart()));
    }
    // NOW TEST the mustUnderstand=true headers
    // initially they should be in the notUnderstood list (and nothing
    // else should be in that list)
    // check not understood headers
    assertFalse(hdrs.isUnderstood(ADDRESSING_NS, "Action"));
    assertFalse(hdrs.isUnderstood(ADDRESSING_NS, "To"));
    Set<QName> notUnderstood = hdrs.getNotUnderstoodHeaders(null, null, null);
    assertNotNull(notUnderstood);
    assertEquals(2, notUnderstood.size());
    for (QName nextHdrName : notUnderstood) {
        assertEquals(ADDRESSING_NS, nextHdrName.getNamespaceURI());
        assertTrue("Action".equals(nextHdrName.getLocalPart()) || "To".equals(nextHdrName.getLocalPart()));
    }
    int prevSizeOfUnderstood = understood.size();
    // add understood calls for mustUnderstand=true headers
    // i.e. Action and To headers and make sure they are understood
    hdrs.understood(ADDRESSING_NS, "Action");
    assertTrue(hdrs.isUnderstood(ADDRESSING_NS, "Action"));
    understood = hdrs.getUnderstoodHeaders();
    assertNotNull(understood);
    assertEquals(prevSizeOfUnderstood + 1, understood.size());
    assertTrue(understood.contains(new QName(ADDRESSING_NS, "Action")));
    prevSizeOfUnderstood = understood.size();
    hdrs.understood(ADDRESSING_NS, "To");
    understood = hdrs.getUnderstoodHeaders();
    assertNotNull(understood);
    assertEquals(prevSizeOfUnderstood + 1, understood.size());
    assertTrue(understood.contains(new QName(ADDRESSING_NS, "To")));
    // make sure marking a header understood a second time doesn't
    // add to size of understood
    prevSizeOfUnderstood = understood.size();
    hdrs.understood(ADDRESSING_NS, "To");
    understood = hdrs.getUnderstoodHeaders();
    assertNotNull(understood);
    assertEquals(prevSizeOfUnderstood, understood.size());
    // make sure no more notUnderstood headers exist
    notUnderstood = hdrs.getNotUnderstoodHeaders(null, null, null);
    assertTrue(notUnderstood == null || notUnderstood.size() == 0);
}
Also used : SAAJMessageHeaders(com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders) QName(javax.xml.namespace.QName) SAAJMessageHeaders(com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders) MessageHeaders(com.sun.xml.ws.api.message.MessageHeaders) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Aggregations

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