Search in sources :

Example 1 with ClientFaultConverter

use of org.apache.cxf.interceptor.ClientFaultConverter in project cxf by apache.

the class XMLFaultInterceptorsTest method testRuntimeExceptionOfImpl.

@Test
public void testRuntimeExceptionOfImpl() throws Exception {
    String ns = "http://apache.org/hello_world_xml_http/wrapped";
    common("/wsdl/hello_world_xml_wrapped.wsdl", new QName(ns, "XMLPort"), MyComplexStructType.class);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    xmlMessage.setContent(OutputStream.class, baos);
    xmlMessage.setContent(XMLStreamWriter.class, StaxUtils.createXMLStreamWriter(baos));
    xmlMessage.setContent(Exception.class, new Fault(new RuntimeException("dummy exception")));
    XMLFaultOutInterceptor xfo = new XMLFaultOutInterceptor("phase1");
    chain.add(xfo);
    InHelpInterceptor ih = new InHelpInterceptor("phase2");
    ClientFaultConverter cfc = new ClientFaultConverter("phase3");
    XMLFaultInInterceptor xfi = new XMLFaultInInterceptor("phase3");
    chain.add(ih);
    chain.add(cfc);
    chain.add(xfi);
    chain.doIntercept(xmlMessage);
    assertNotNull(xmlMessage.getContent(Exception.class));
    assertTrue(xmlMessage.getContent(Exception.class) instanceof XMLFault);
    XMLFault xfault = (XMLFault) xmlMessage.getContent(Exception.class);
    assertTrue("check message expected - dummy exception", xfault.getMessage().indexOf("dummy exception") >= 0);
}
Also used : XMLFault(org.apache.cxf.binding.xml.XMLFault) QName(javax.xml.namespace.QName) XMLFault(org.apache.cxf.binding.xml.XMLFault) Fault(org.apache.cxf.interceptor.Fault) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ClientFaultConverter(org.apache.cxf.interceptor.ClientFaultConverter) Test(org.junit.Test)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 QName (javax.xml.namespace.QName)1 XMLFault (org.apache.cxf.binding.xml.XMLFault)1 ClientFaultConverter (org.apache.cxf.interceptor.ClientFaultConverter)1 Fault (org.apache.cxf.interceptor.Fault)1 Test (org.junit.Test)1