Search in sources :

Example 1 with SAAJPreInInterceptor

use of org.apache.cxf.binding.soap.saaj.SAAJInInterceptor.SAAJPreInInterceptor in project cxf by apache.

the class SoapFaultSerializerTest method testCXF4181.

@Test
public void testCXF4181() throws Exception {
    // Try WITH SAAJ
    SoapMessage m = new SoapMessage(new MessageImpl());
    m.put(Message.HTTP_REQUEST_METHOD, "POST");
    m.setVersion(Soap12.getInstance());
    XMLStreamReader reader = StaxUtils.createXMLStreamReader(this.getClass().getResourceAsStream("cxf4181.xml"));
    m.setContent(XMLStreamReader.class, reader);
    new SAAJPreInInterceptor().handleMessage(m);
    new ReadHeadersInterceptor(null).handleMessage(m);
    new StartBodyInterceptor().handleMessage(m);
    new SAAJInInterceptor().handleMessage(m);
    new Soap12FaultInInterceptor().handleMessage(m);
    Node nd = m.getContent(Node.class);
    SOAPPart part = (SOAPPart) nd;
    assertEquals("S", part.getEnvelope().getPrefix());
    assertEquals("S2", part.getEnvelope().getHeader().getPrefix());
    assertEquals("S3", part.getEnvelope().getBody().getPrefix());
    SOAPFault fault = part.getEnvelope().getBody().getFault();
    assertEquals("S", fault.getPrefix());
    assertEquals("Authentication Failure", fault.getFaultString());
    SoapFault fault2 = (SoapFault) m.getContent(Exception.class);
    assertNotNull(fault2);
    assertEquals(Soap12.getInstance().getSender(), fault2.getFaultCode());
    assertEquals(new QName("http://schemas.xmlsoap.org/ws/2005/02/trust", "FailedAuthentication"), fault2.getSubCode());
    Element el = part.getEnvelope().getBody();
    nd = el.getFirstChild();
    int count = 0;
    while (nd != null) {
        if (nd instanceof Element) {
            count++;
        }
        nd = nd.getNextSibling();
    }
    assertEquals(1, count);
    // Try WITHOUT SAAJ
    m = new SoapMessage(new MessageImpl());
    m.setVersion(Soap12.getInstance());
    reader = StaxUtils.createXMLStreamReader(this.getClass().getResourceAsStream("cxf4181.xml"));
    m.setContent(XMLStreamReader.class, reader);
    m.put(Message.HTTP_REQUEST_METHOD, "POST");
    new ReadHeadersInterceptor(null).handleMessage(m);
    new StartBodyInterceptor().handleMessage(m);
    new Soap12FaultInInterceptor().handleMessage(m);
    // nd = m.getContent(Node.class);
    fault2 = (SoapFault) m.getContent(Exception.class);
    assertNotNull(fault2);
    assertEquals(Soap12.getInstance().getSender(), fault2.getFaultCode());
    assertEquals(new QName("http://schemas.xmlsoap.org/ws/2005/02/trust", "FailedAuthentication"), fault2.getSubCode());
}
Also used : SAAJPreInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor.SAAJPreInInterceptor) SoapFault(org.apache.cxf.binding.soap.SoapFault) XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) SOAPPart(javax.xml.soap.SOAPPart) SOAPFault(javax.xml.soap.SOAPFault) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 2 with SAAJPreInInterceptor

use of org.apache.cxf.binding.soap.saaj.SAAJInInterceptor.SAAJPreInInterceptor in project cxf by apache.

the class SoapFaultSerializerTest method testCXF5493.

@Test
public void testCXF5493() throws Exception {
    SoapMessage m = new SoapMessage(new MessageImpl());
    m.setVersion(Soap11.getInstance());
    XMLStreamReader reader = StaxUtils.createXMLStreamReader(this.getClass().getResourceAsStream("cxf5493.xml"));
    m.setContent(XMLStreamReader.class, reader);
    // env
    reader.nextTag();
    // body
    reader.nextTag();
    // fault
    reader.nextTag();
    Soap11FaultInInterceptor inInterceptor = new Soap11FaultInInterceptor();
    inInterceptor.handleMessage(m);
    SoapFault fault2 = (SoapFault) m.getContent(Exception.class);
    assertNotNull(fault2);
    assertEquals(Soap11.getInstance().getReceiver(), fault2.getFaultCode());
    assertEquals("some text containing a xml tag <xml-tag>", fault2.getMessage());
    m = new SoapMessage(new MessageImpl());
    m.put(Message.HTTP_REQUEST_METHOD, "POST");
    m.setVersion(Soap11.getInstance());
    reader = StaxUtils.createXMLStreamReader(this.getClass().getResourceAsStream("cxf5493.xml"));
    m.setContent(XMLStreamReader.class, reader);
    new SAAJPreInInterceptor().handleMessage(m);
    new ReadHeadersInterceptor(null).handleMessage(m);
    new StartBodyInterceptor().handleMessage(m);
    new SAAJInInterceptor().handleMessage(m);
    new Soap11FaultInInterceptor().handleMessage(m);
    fault2 = (SoapFault) m.getContent(Exception.class);
    assertNotNull(fault2);
    assertEquals(Soap11.getInstance().getReceiver(), fault2.getFaultCode());
    assertEquals("some text containing a xml tag <xml-tag>", fault2.getMessage());
}
Also used : SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) SAAJPreInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor.SAAJPreInInterceptor) SoapFault(org.apache.cxf.binding.soap.SoapFault) XMLStreamReader(javax.xml.stream.XMLStreamReader) MessageImpl(org.apache.cxf.message.MessageImpl) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) Test(org.junit.Test)

Aggregations

XMLStreamReader (javax.xml.stream.XMLStreamReader)2 SoapFault (org.apache.cxf.binding.soap.SoapFault)2 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)2 SAAJInInterceptor (org.apache.cxf.binding.soap.saaj.SAAJInInterceptor)2 SAAJPreInInterceptor (org.apache.cxf.binding.soap.saaj.SAAJInInterceptor.SAAJPreInInterceptor)2 MessageImpl (org.apache.cxf.message.MessageImpl)2 Test (org.junit.Test)2 QName (javax.xml.namespace.QName)1 SOAPFault (javax.xml.soap.SOAPFault)1 SOAPPart (javax.xml.soap.SOAPPart)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1