Search in sources :

Example 1 with StringHeader

use of com.sun.xml.ws.message.StringHeader 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 StringHeader

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

the class SAAJMessageTest method test1.

public void test1() throws Exception {
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();
    Source src = new StreamSource(new ByteArrayInputStream(MESSAGE.getBytes()));
    message.getSOAPPart().setContent(src);
    SAAJMessage saajMsg = new SAAJMessage(message);
    assertEquals("addNumbers", saajMsg.getPayloadLocalPart());
    assertEquals("http://example.com/addNumbers", AddressingUtils.getAction(saajMsg.getHeaders(), AddressingVersion.W3C, SOAPVersion.SOAP_11));
    Header header = new StringHeader(new QName("urn:foo", "header1"), "test header  ");
    saajMsg.getHeaders().add(header);
    SOAPMessage newMsg = saajMsg.readAsSOAPMessage();
    newMsg.writeTo(System.out);
    SAAJMessage saajMsg2 = new SAAJMessage(newMsg);
    assertEquals(2, saajMsg2.getHeaders().asList().size());
    Message saajMsg3 = saajMsg2.copy();
    assertEquals("addNumbers", saajMsg3.getPayloadLocalPart());
    assertEquals("http://example.com/addNumbers", AddressingUtils.getAction(saajMsg3.getHeaders(), AddressingVersion.W3C, SOAPVersion.SOAP_11));
    assertEquals(2, saajMsg2.getHeaders().asList().size());
    XMLStreamWriter writer = XMLStreamWriterFactory.create(System.out);
    saajMsg3.writeTo(writer);
    writer.close();
}
Also used : StringHeader(com.sun.xml.ws.message.StringHeader) MessageFactory(jakarta.xml.soap.MessageFactory) StringHeader(com.sun.xml.ws.message.StringHeader) Header(com.sun.xml.ws.api.message.Header) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) StreamSource(javax.xml.transform.stream.StreamSource) SOAPMessage(jakarta.xml.soap.SOAPMessage) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource)

Example 3 with StringHeader

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

the class Message method getID.

/**
 * Retuns a unique id for the message.
 * <p><p>
 * @see #getID(com.sun.xml.ws.api.WSBinding) for detailed description.
 * @param av WS-Addressing version
 * @param sv SOAP version
 * @return unique id for the message
 * @deprecated
 */
@Deprecated
@NotNull
public String getID(AddressingVersion av, SOAPVersion sv) {
    String uuid = null;
    if (av != null) {
        uuid = AddressingUtils.getMessageID(getHeaders(), av, sv);
    }
    if (uuid == null) {
        uuid = generateMessageID();
        getHeaders().add(new StringHeader(av.messageIDTag, uuid));
    }
    return uuid;
}
Also used : StringHeader(com.sun.xml.ws.message.StringHeader) NotNull(com.sun.istack.NotNull)

Example 4 with StringHeader

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

the class AddressingUtils method fillCommonAddressingHeaders.

/**
 * Creates wsa:To, wsa:Action and wsa:MessageID header on the client
 *
 * @param packet request packet
 * @param av WS-Addressing version
 * @param sv SOAP version
 * @param action Action Message Addressing Property value
 * @throws IllegalArgumentException if any of the parameters is null.
 */
private static void fillCommonAddressingHeaders(MessageHeaders headers, Packet packet, @NotNull AddressingVersion av, @NotNull SOAPVersion sv, @NotNull String action, boolean mustUnderstand) {
    if (packet == null) {
        throw new IllegalArgumentException(AddressingMessages.NULL_PACKET());
    }
    if (av == null) {
        throw new IllegalArgumentException(AddressingMessages.NULL_ADDRESSING_VERSION());
    }
    if (sv == null) {
        throw new IllegalArgumentException(AddressingMessages.NULL_SOAP_VERSION());
    }
    if (action == null && !sv.httpBindingId.equals(SOAPBinding.SOAP12HTTP_BINDING)) {
        throw new IllegalArgumentException(AddressingMessages.NULL_ACTION());
    }
    // wsa:To
    if (headers.get(av.toTag, false) == null) {
        StringHeader h = new StringHeader(av.toTag, packet.endpointAddress.toString());
        headers.add(h);
    }
    // wsa:Action
    if (action != null) {
        packet.soapAction = action;
        if (headers.get(av.actionTag, false) == null) {
            // As per WS-I BP 1.2/2.0, if one of the WSA headers is MU, then all WSA headers should be treated as MU.,
            // so just set MU on action header
            StringHeader h = new StringHeader(av.actionTag, action, sv, mustUnderstand);
            headers.add(h);
        }
    }
}
Also used : StringHeader(com.sun.xml.ws.message.StringHeader)

Example 5 with StringHeader

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

the class AddressingUtils method fillRequestAddressingHeaders.

public static void fillRequestAddressingHeaders(MessageHeaders headers, Packet packet, AddressingVersion av, SOAPVersion sv, boolean oneway, String action, boolean mustUnderstand) {
    fillCommonAddressingHeaders(headers, packet, av, sv, action, mustUnderstand);
    // null or "true" is equivalent to request/response MEP
    if (!oneway) {
        WSEndpointReference epr = av.anonymousEpr;
        if (headers.get(av.replyToTag, false) == null) {
            headers.add(epr.createHeader(av.replyToTag));
        }
        // wsa:FaultTo
        if (headers.get(av.faultToTag, false) == null) {
            headers.add(epr.createHeader(av.faultToTag));
        }
        // wsa:MessageID
        if (packet.getMessage().getHeaders().get(av.messageIDTag, false) == null) {
            if (headers.get(av.messageIDTag, false) == null) {
                Header h = new StringHeader(av.messageIDTag, Message.generateMessageID());
                headers.add(h);
            }
        }
    }
}
Also used : StringHeader(com.sun.xml.ws.message.StringHeader) StringHeader(com.sun.xml.ws.message.StringHeader) RelatesToHeader(com.sun.xml.ws.message.RelatesToHeader) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference)

Aggregations

StringHeader (com.sun.xml.ws.message.StringHeader)11 Header (com.sun.xml.ws.api.message.Header)6 SOAPMessage (jakarta.xml.soap.SOAPMessage)5 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)3 RelatesToHeader (com.sun.xml.ws.message.RelatesToHeader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 QName (javax.xml.namespace.QName)3 MessageHeaders (com.sun.xml.ws.api.message.MessageHeaders)2 SAAJMessageHeaders (com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders)2 MessageFactory (jakarta.xml.soap.MessageFactory)2 NotNull (com.sun.istack.NotNull)1 WsaPropertyBag (com.sun.xml.ws.addressing.WsaPropertyBag)1 Message (com.sun.xml.ws.api.message.Message)1 WSBindingProvider (com.sun.xml.ws.developer.WSBindingProvider)1 StreamHeader11 (com.sun.xml.ws.message.stream.StreamHeader11)1 MimeHeaders (jakarta.xml.soap.MimeHeaders)1 WebServiceException (jakarta.xml.ws.WebServiceException)1 ArrayList (java.util.ArrayList)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1