Search in sources :

Example 1 with SAAJMessage

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

the class GenerateToElementTest method testCorrectToFromResMsg.

public void testCorrectToFromResMsg() throws Exception {
    String reqMsgStr = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:a=\"http://www.w3.org/2005/08/addressing\">" + "<s:Header>" + "<a:Action s:mustUnderstand=\"1\">http://example.org/action/echoIn</a:Action>" + "<a:ReplyTo s:actor=\"http://www.w3.org/2003/05/soap-envelope/role/none\"><a:Address>http://www.microsoft.com/</a:Address></a:ReplyTo>" + "<a:MessageID>urn:uuid:d715800d-67e2-4254-a86e-e31a1bfaecab</a:MessageID>" + "<a:ReplyTo><a:Address>http://10.244.13.245:8000/2eaddcdf-e10b-41c5-9f1f-a7ac50853fc3/4b1de783-1499-4419-9634-465f8797a0a8</a:Address></a:ReplyTo>" + "<a:To s:mustUnderstand=\"1\">http://scl58353.us.oracle.com:9902/WSAddressingCR_Service_WCF/WSAddressing10.svc/Echo4</a:To>" + "</s:Header>" + "<s:Body>" + "<echoIn xmlns=\"http://example.org/echo\">test1151</echoIn>" + "</s:Body>" + "</s:Envelope>";
    String respMsgStr = "<?xml version='1.0' encoding='UTF-8'?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<S:Body>" + "<ns0:echoOut xmlns:ns0=\"http://example.org/echo\">test1151</ns0:echoOut>" + "</S:Body>" + "</S:Envelope>";
    String finalToFromResponseMsg = "";
    WSEndpointReference originalReplyToFromRequestMsg = null;
    AddressingVersion av = AddressingVersion.W3C;
    SOAPVersion sv = SOAPVersion.SOAP_11;
    String action = "http://example.org/action/echoOut";
    SAAJMessage reqMsg = new SAAJMessage(makeSOAPMessage(reqMsgStr));
    SAAJMessage respMsg = new SAAJMessage(makeSOAPMessage(respMsgStr));
    HeaderList requestHdrs = (HeaderList) reqMsg.getHeaders();
    originalReplyToFromRequestMsg = requestHdrs.getReplyTo(av, sv);
    Packet responsePacket = null;
    try {
        responsePacket = new Packet(reqMsg).createServerResponse(respMsg, av, sv, action);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // check toHeader
    finalToFromResponseMsg = AddressingUtils.getTo(responsePacket.getHeaderList(), av, sv);
    assertEquals(finalToFromResponseMsg, originalReplyToFromRequestMsg.getAddress());
}
Also used : AddressingVersion(com.sun.xml.ws.api.addressing.AddressingVersion) SOAPVersion(com.sun.xml.ws.api.SOAPVersion) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference)

Example 2 with SAAJMessage

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

the class SAAJFactory method read.

/**
 * Reads the message within the Packet to a SAAJMessage.  After this call message is consumed.
 * @param packet Packet
 * @return Created SAAJPMessage
 * @throws SOAPException if SAAJ processing fails
 */
public static SAAJMessage read(Packet packet) throws SOAPException {
    SAAJFactory saajfac = packet.getSAAJFactory();
    if (saajfac != null) {
        SAAJMessage msg = saajfac.readAsSAAJ(packet);
        if (msg != null)
            return msg;
    }
    // Use the Component from the Packet if it exists.  Note the logic
    // in the ServiceFinder is such that find(Class) is not equivalent
    // to find (Class, null), so the ternary operator is needed.
    ServiceFinder<SAAJFactory> factories = (packet.component != null ? ServiceFinder.find(SAAJFactory.class, packet.component) : ServiceFinder.find(SAAJFactory.class));
    for (SAAJFactory s : factories) {
        SAAJMessage msg = s.readAsSAAJ(packet);
        if (msg != null)
            return msg;
    }
    return instance.readAsSAAJ(packet);
}
Also used : SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage)

Example 3 with SAAJMessage

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

the class SOAPFaultBuilder1Test method testFault1.

public void testFault1() throws Throwable {
    SOAPMessage msg = SOAPVersion.SOAP_11.getMessageFactory().createMessage(null, new ByteArrayInputStream(fault1.getBytes()));
    SOAPFaultBuilder sfb = SOAPFaultBuilder.create(new SAAJMessage(msg));
    Throwable t = sfb.createException(null);
    assertTrue(t instanceof SOAPFaultException);
    assertTrue(t.getMessage().contains("Client received SOAP Fault from server:"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException)

Example 4 with SAAJMessage

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

the class ReferenceParametersTest method testReferenceParameters1.

public void testReferenceParameters1() throws Exception {
    String xmlRefParam1 = "<myns:MyParam1 wsa:IsReferenceParameter='true' xmlns:myns=\"http://cptestservice.org/wsdl\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">Hello</myns:MyParam1>";
    String xmlRefParam2 = "<myns:MyParam2 wsa:IsReferenceParameter='true' xmlns:myns=\"http://cptestservice.org/wsdl\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">There</myns:MyParam2>";
    String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"><S:Header>" + xmlRefParam1 + xmlRefParam2 + "</S:Header><S:Body><DataType xmlns=\"http://cptestservice.org/xsd\"><param>foo bar</param></DataType></S:Body></S:Envelope>";
    MessageFactory messageFactory = MessageFactory.newInstance();
    MimeHeaders headers = new MimeHeaders();
    headers.addHeader("Content-Type", "text/xml");
    SOAPMessage soapMsg = messageFactory.createMessage(headers, new ByteArrayInputStream(request.getBytes()));
    // soapMsg.writeTo(System.out);
    Packet p = new Packet(new SAAJMessage(soapMsg));
    List<Element> refParams = p.getReferenceParameters();
    assertEquals("Did n't get expected ReferenceParameters", 2, refParams.size());
    for (Element e : refParams) {
        assertTrue("isReferenceParameter attribute not present on header", e.getAttributeNodeNS(W3CAddressingConstants.WSA_NAMESPACE_NAME, "IsReferenceParameter") != null);
    }
}
Also used : MimeHeaders(jakarta.xml.soap.MimeHeaders) Packet(com.sun.xml.ws.api.message.Packet) MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) Element(org.w3c.dom.Element) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 5 with SAAJMessage

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

the class ReferenceParametersTest method testReferenceParametersNsDecl.

/**
 * Test where NS decl for ReferenceParameters is on the SOAP envelope
 * @throws Exception
 */
public void testReferenceParametersNsDecl() throws Exception {
    String xmlRefParam1 = "<myns:MyParam1 wsa:IsReferenceParameter='true' xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">Hello</myns:MyParam1>";
    String xmlRefParam2 = "<myns:MyParam2 wsa:IsReferenceParameter='true' xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">There</myns:MyParam2>";
    String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:myns=\"http://cptestservice.org/wsdl\"><S:Header>" + xmlRefParam1 + xmlRefParam2 + "</S:Header><S:Body><DataType xmlns=\"http://cptestservice.org/xsd\"><param>foo bar</param></DataType></S:Body></S:Envelope>";
    MessageFactory messageFactory = MessageFactory.newInstance();
    MimeHeaders headers = new MimeHeaders();
    headers.addHeader("Content-Type", "text/xml");
    SOAPMessage soapMsg = messageFactory.createMessage(headers, new ByteArrayInputStream(request.getBytes()));
    // soapMsg.writeTo(System.out);
    Packet p = new Packet(new SAAJMessage(soapMsg));
    List<Element> refParams = p.getReferenceParameters();
    assertEquals("Did n't get expected ReferenceParameters", 2, refParams.size());
    for (Element e : refParams) {
        assertTrue("isReferenceParameter attribute not present on header", e.getAttributeNodeNS(W3CAddressingConstants.WSA_NAMESPACE_NAME, "IsReferenceParameter") != null);
        assertEquals("NS Decl did not match", "http://cptestservice.org/wsdl", e.getNamespaceURI());
    }
}
Also used : MimeHeaders(jakarta.xml.soap.MimeHeaders) Packet(com.sun.xml.ws.api.message.Packet) MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) Element(org.w3c.dom.Element) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Aggregations

SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)27 SOAPMessage (jakarta.xml.soap.SOAPMessage)19 ByteArrayInputStream (java.io.ByteArrayInputStream)18 MessageFactory (jakarta.xml.soap.MessageFactory)16 MimeHeaders (jakarta.xml.soap.MimeHeaders)12 Packet (com.sun.xml.ws.api.message.Packet)10 Element (org.w3c.dom.Element)10 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)7 Message (com.sun.xml.ws.api.message.Message)5 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)5 QName (javax.xml.namespace.QName)4 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)4 Node (org.w3c.dom.Node)4 SOAPVersion (com.sun.xml.ws.api.SOAPVersion)3 SOAPBody (jakarta.xml.soap.SOAPBody)3 AddressingVersion (com.sun.xml.ws.api.addressing.AddressingVersion)2 SOAPFaultBuilder (com.sun.xml.ws.fault.SOAPFaultBuilder)2 ByteArrayBuffer (com.sun.xml.ws.util.ByteArrayBuffer)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2