Search in sources :

Example 21 with SAAJMessage

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

the class SOAPFaultBuilderTest method testCreateException_14504957.

public void testCreateException_14504957() throws Exception {
    MessageFactory f = MessageFactory.newInstance();
    SOAPMessage soapMsg = f.createMessage(null, new ByteArrayInputStream(NPE_FAULT.getBytes()));
    Message m = new SAAJMessage(soapMsg);
    SOAPFaultBuilder builder = SOAPFaultBuilder.create(m);
    try {
        SOAPFaultException sex = (SOAPFaultException) builder.createException(null);
    } catch (Throwable t) {
        t.printStackTrace(System.out);
        fail("Got unexpected exception: " + t.getClass().getName());
    }
}
Also used : MessageFactory(jakarta.xml.soap.MessageFactory) Message(com.sun.xml.ws.api.message.Message) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) SOAPMessage(jakarta.xml.soap.SOAPMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 22 with SAAJMessage

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

the class FaultTester method testFault1.

public void testFault1() throws Throwable {
    SOAPMessage msg = SOAPVersion.SOAP_11.saajMessageFactory.createMessage(null, new ByteArrayInputStream(fault1.getBytes()));
    SOAPFaultBuilder sfb = SOAPFaultBuilder.create(new SAAJMessage(msg));
    Throwable t = sfb.createException(null);
    assertTrue(t instanceof SOAPFaultException);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPFaultBuilder(com.sun.xml.ws.fault.SOAPFaultBuilder) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException)

Example 23 with SAAJMessage

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

the class FaultTester method testFault2.

public void testFault2() throws Throwable {
    InputStream is = this.getClass().getClassLoader().getResourceAsStream("fault2.xml");
    FileOutputStream fos = new FileOutputStream("fault2.xml");
    fos.write(fault2.trim().getBytes());
    fos.close();
    SOAPMessage msg = SOAPVersion.SOAP_12.saajMessageFactory.createMessage(null, new ByteArrayInputStream(fault2.trim().getBytes()));
    SOAPFaultBuilder sfb = SOAPFaultBuilder.create(new SAAJMessage(msg));
    Throwable t = sfb.createException(null);
    assertTrue(t instanceof SOAPFaultException);
    SOAPFaultException sfe = (SOAPFaultException) t;
    Detail detail = sfe.getFault().getDetail();
    assertTrue(detail != null);
    Iterator iter = detail.getDetailEntries();
    // there should be two detail entries
    assertTrue(iter.hasNext());
    DetailEntry de = (DetailEntry) iter.next();
    assertTrue(de.getElementQName().equals(new QName("http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", "FaultDetail")));
    Node n = de.getFirstChild();
    assertTrue(n.getNodeValue().equals("http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/InvalidValues"));
    assertTrue(iter.hasNext());
    de = (DetailEntry) iter.next();
    assertTrue(de.getElementQName().equals(new QName("http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", "FaultDetail2")));
    n = de.getFirstChild();
    assertTrue(n.getNodeValue().equals("http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/InvalidValues1"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPFaultBuilder(com.sun.xml.ws.fault.SOAPFaultBuilder) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) FileOutputStream(java.io.FileOutputStream) Iterator(java.util.Iterator)

Example 24 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)

Example 25 with SAAJMessage

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

the class ReferenceParametersTest method testFaultToReferenceParameters.

/**
 * See if the ReferenceParamaters get added proeprly from FaultToEPR to fault response
 * @throws Exception
 */
public void testFaultToReferenceParameters() throws Exception {
    String requestStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:user=\"http://foo.bar\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">" + "<S:Header>" + "<wsa:Action>http://example.org/action/echoIn</wsa:Action>" + "<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>" + "<wsa:MessageID>urn:uuid:1234567890</wsa:MessageID>" + "<wsa:FaultTo>" + "<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>" + "<wsa:ReferenceParameters>" + "<user:foo wsa:IsReferenceParameter='true'>bar</user:foo>" + "<user:bar>" + "<user:foobar>barfoo</user:foobar>" + "</user:bar>" + "</wsa:ReferenceParameters>" + "</wsa:FaultTo>" + "</S:Header>" + "<S:Body><DataType xmlns=\"http://foo.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(requestStr.getBytes()));
    Message message = new SAAJMessage(soapMsg);
    WSEndpointReference wsepr = message.getHeaders().getFaultTo(AddressingVersion.W3C, SOAPVersion.SOAP_11);
    String responseStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"><S:Body><S:Fault>" + "<faultcode>echo:EmptyEchoString</faultcode>" + "<faultstring>The echo string was empty.</faultstring>" + "</S:Fault></S:Body></S:Envelope>";
    MimeHeaders headers1 = new MimeHeaders();
    headers1.addHeader("Content-Type", "text/xml");
    SOAPMessage soapMsg1 = messageFactory.createMessage(headers1, new ByteArrayInputStream(responseStr.getBytes()));
    Message m2 = new SAAJMessage(soapMsg1);
    wsepr.addReferenceParametersToList(m2.getHeaders());
    Packet response = new Packet(m2);
    List<Element> refParams = response.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://foo.bar", e.getNamespaceURI());
    }
}
Also used : MimeHeaders(jakarta.xml.soap.MimeHeaders) Packet(com.sun.xml.ws.api.message.Packet) MessageFactory(jakarta.xml.soap.MessageFactory) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) 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