Package org.apache.cxf.binding.soap

Examples of org.apache.cxf.binding.soap.SoapFault


public class SoapFaultSerializerTest extends AbstractCXFTest {
   
    @Test
    public void testSoap11Out() throws Exception {
        String faultString = "Hadrian caused this Fault!";
        SoapFault fault = new SoapFault(faultString, Soap11.getInstance().getSender());

        SoapMessage m = new SoapMessage(new MessageImpl());
        m.setExchange(new ExchangeImpl());
        m.setContent(Exception.class, fault);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
        writer.writeStartDocument();
        writer.writeStartElement("Body");

        m.setContent(XMLStreamWriter.class, writer);

        Soap11FaultOutInterceptorInternal.INSTANCE.handleMessage(m);

        writer.writeEndElement();
        writer.writeEndDocument();
        writer.close();

        Document faultDoc = StaxUtils.read(new ByteArrayInputStream(out.toByteArray()));
        assertValid("//s:Fault/faultcode[text()='ns1:Client']", faultDoc);
        assertValid("//s:Fault/faultstring[text()='" + faultString + "']", faultDoc);

        XMLStreamReader reader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(out.toByteArray()));
        m.setContent(XMLStreamReader.class, reader);

        reader.nextTag();

        Soap11FaultInInterceptor inInterceptor = new Soap11FaultInInterceptor();
        inInterceptor.handleMessage(m);

        SoapFault fault2 = (SoapFault)m.getContent(Exception.class);
        assertNotNull(fault2);
        assertEquals(fault.getMessage(), fault2.getMessage());
        assertEquals(Soap11.getInstance().getSender(), fault2.getFaultCode());
    }
View Full Code Here


    }
   
    @Test
    public void testSoap12Out() throws Exception {
        String faultString = "Hadrian caused this Fault!";
        SoapFault fault = new SoapFault(faultString, Soap12.getInstance().getSender());
       
        QName qname = new QName("http://cxf.apache.org/soap/fault", "invalidsoap", "cxffaultcode");
        fault.setSubCode(qname);

        SoapMessage m = new SoapMessage(new MessageImpl());
        m.setVersion(Soap12.getInstance());
       
        m.setContent(Exception.class, fault);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
        writer.writeStartDocument();
        writer.writeStartElement("Body");

        m.setContent(XMLStreamWriter.class, writer);

        Soap12FaultOutInterceptorInternal.INSTANCE.handleMessage(m);

        writer.writeEndElement();
        writer.writeEndDocument();
        writer.close();

        Document faultDoc = StaxUtils.read(new ByteArrayInputStream(out.toByteArray()));
       
        assertValid("//soap12env:Fault/soap12env:Code/soap12env:Value[text()='ns1:Sender']",
                    faultDoc);
        assertValid("//soap12env:Fault/soap12env:Code/soap12env:Subcode/"
                    + "soap12env:Value[text()='ns2:invalidsoap']",
                    faultDoc);
        assertValid("//soap12env:Fault/soap12env:Reason/soap12env:Text[@xml:lang='en']",
                    faultDoc);
        assertValid("//soap12env:Fault/soap12env:Reason/soap12env:Text[text()='" + faultString + "']",
                    faultDoc);

        XMLStreamReader reader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(out.toByteArray()));
        m.setContent(XMLStreamReader.class, reader);

        reader.nextTag();

        Soap12FaultInInterceptor inInterceptor = new Soap12FaultInInterceptor();
        inInterceptor.handleMessage(m);

        SoapFault fault2 = (SoapFault)m.getContent(Exception.class);
        assertNotNull(fault2);
        assertEquals(Soap12.getInstance().getSender(), fault2.getFaultCode());
        assertEquals(fault.getMessage(), fault2.getMessage());       
        assertEquals(fault.getSubCode(), fault2.getSubCode());
    }
View Full Code Here

    }
   
    @Test
    public void testSoap12WithMultipleSubCodesOut() throws Exception {
        String faultString = "Hadrian caused this Fault!";
        SoapFault fault = new SoapFault(faultString, Soap12.getInstance().getSender());
       
        fault.addSubCode(new QName("http://cxf.apache.org/soap/fault", "invalidsoap", "cxffaultcode"));
        fault.addSubCode(new QName("http://cxf.apache.org/soap/fault2", "invalidsoap2", "cxffaultcode2"));

        SoapMessage m = new SoapMessage(new MessageImpl());
        m.setVersion(Soap12.getInstance());
       
        m.setContent(Exception.class, fault);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
        writer.writeStartDocument();
        writer.writeStartElement("Body");

        m.setContent(XMLStreamWriter.class, writer);

        Soap12FaultOutInterceptorInternal.INSTANCE.handleMessage(m);

        writer.writeEndElement();
        writer.writeEndDocument();
        writer.close();

        Document faultDoc = StaxUtils.read(new ByteArrayInputStream(out.toByteArray()));
       
        assertValid("//soap12env:Fault/soap12env:Code/soap12env:Value[text()='ns1:Sender']",
                    faultDoc);
        assertValid("//soap12env:Fault/soap12env:Code/soap12env:Subcode/"
                    + "soap12env:Value[text()='ns2:invalidsoap']",
                    faultDoc);
        assertValid("//soap12env:Fault/soap12env:Code/soap12env:Subcode/soap12env:Subcode/"
                    + "soap12env:Value[text()='ns2:invalidsoap2']",
                    faultDoc);
        assertValid("//soap12env:Fault/soap12env:Reason/soap12env:Text[@xml:lang='en']",
                    faultDoc);
        assertValid("//soap12env:Fault/soap12env:Reason/soap12env:Text[text()='" + faultString + "']",
                    faultDoc);

        XMLStreamReader reader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(out.toByteArray()));
        m.setContent(XMLStreamReader.class, reader);

        reader.nextTag();

        Soap12FaultInInterceptor inInterceptor = new Soap12FaultInInterceptor();
        inInterceptor.handleMessage(m);

        SoapFault fault2 = (SoapFault)m.getContent(Exception.class);
        assertNotNull(fault2);
        assertEquals(Soap12.getInstance().getSender(), fault2.getFaultCode());
        assertEquals(fault.getMessage(), fault2.getMessage());       
        assertEquals(fault.getSubCodes(), fault2.getSubCodes());
    }
View Full Code Here

        fault = new Fault(ex, Fault.FAULT_CODE_CLIENT);
        verifyFaultToSoapFault(fault, "fault-two", true, Soap11.getInstance());
    }
   
    private void verifyFaultToSoapFault(Fault fault, String msg, boolean sender, SoapVersion v) {
        SoapFault sf = SoapFault.createFault(fault, v);
        assertEquals(sender ? v.getSender() : v.getReceiver(), sf.getFaultCode());
        assertEquals(msg, sf.getMessage());
    }
View Full Code Here

        reader.nextTag();

        Soap12FaultInInterceptor inInterceptor = new Soap12FaultInInterceptor();
        inInterceptor.handleMessage(m);

        SoapFault fault2 = (SoapFault)m.getContent(Exception.class);
        assertNotNull(fault2);
        assertEquals(Soap12.getInstance().getReceiver(), fault2.getFaultCode());
    }
View Full Code Here

        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());
    }
View Full Code Here

        reader.nextTag(); //fault

        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());
    }
View Full Code Here

                   
                    xtw.flush();
                }
            } catch (XMLStreamException e) {
                SoapVersion soapVersion = message.getVersion();
                throw new SoapFault(new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE), e,
                                    soapVersion.getSender());
            }
        }
View Full Code Here

            xmlReader = StaxUtils.createXMLStreamReader(bodySource);
            xmlReader.nextTag();
            xmlReader.nextTag(); // move past body tag
            message.setContent(XMLStreamReader.class, xmlReader);          
        } catch (SOAPException soape) {
            throw new SoapFault(new org.apache.cxf.common.i18n.Message(
                    "SOAPHANDLERINTERCEPTOR_EXCEPTION", BUNDLE), soape,
                    message.getVersion().getSender());
        } catch (XMLStreamException e) {
            throw new SoapFault(new org.apache.cxf.common.i18n.Message(
                    "SOAPHANDLERINTERCEPTOR_EXCEPTION", BUNDLE), e, message
                    .getVersion().getSender());
        }
    }
View Full Code Here

                message.put(BODY_FILLED_IN, Boolean.FALSE);

            } catch (RuntimeException ex) {
                throw ex;
            } catch (Exception e) {
                throw new SoapFault("XML_STREAM_EXC", BUNDLE, e, message.getVersion().getSender());
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.cxf.binding.soap.SoapFault

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.