Search in sources :

Example 66 with SOAPFaultException

use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.

the class EmptySOAPBodyTest method testPlaintext.

@org.junit.Test
public void testPlaintext() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = EmptySOAPBodyTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = EmptySOAPBodyTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItPlaintextPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, PORT);
    try {
        port.doubleIt(25);
        fail("Should have thown an exception");
    } catch (SOAPFaultException t) {
        assertTrue("Wrong exception cause " + t.getCause(), t.getCause() instanceof IllegalStateException);
    }
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) URL(java.net.URL)

Example 67 with SOAPFaultException

use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.

the class Soap11ClientServerTest method testFaultMessage.

@Test
public void testFaultMessage() throws Exception {
    Greeter greeter = getGreeter();
    try {
        greeter.sayHi();
        fail("Should throw Exception!");
    } catch (SOAPFaultException ex) {
        assertEquals("sayHiFault Caused by: Get a wrong name <sayHi>", ex.getMessage());
        StackTraceElement[] elements = ex.getCause().getStackTrace();
        assertEquals("org.apache.cxf.systest.soapfault.details.GreeterImpl11", elements[0].getClassName());
    }
    // testing Fault(new NullPointerException())
    try {
        greeter.greetMe("Anya");
        fail("Should throw Exception!");
    } catch (SOAPFaultException ex) {
        assertEquals(NullPointerException.class.getName(), ex.getMessage());
    }
    // testing Fault(new IllegalArgumentException("Get a wrong name for greetMe"))
    try {
        greeter.greetMe("Banya");
        fail("Should throw Exception!");
    } catch (SOAPFaultException ex) {
        assertEquals("Get a wrong name for greetMe", ex.getMessage());
    }
    // testing Fault("unexpected null", LOG, new NullPointerException())
    try {
        greeter.greetMe("Canya");
        fail("Should throw Exception!");
    } catch (SOAPFaultException ex) {
        assertEquals("unexpected null", ex.getMessage());
    }
    // testing Fault("greetMeFault", LOG, new IllegalArgumentException("Get a wrong name greetMe"))
    try {
        greeter.greetMe("Danya");
        fail("Should throw Exception!");
    } catch (SOAPFaultException ex) {
        assertEquals("greetMeFault Caused by: Get a wrong name greetMe", ex.getMessage());
    }
    // testing Fault("invalid", LOG)
    try {
        greeter.greetMe("Eanna");
        fail("Should throw Exception!");
    } catch (SOAPFaultException ex) {
        assertEquals("invalid", ex.getMessage());
    }
}
Also used : Greeter(org.apache.cxf.greeter_control.Greeter) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.junit.Test)

Example 68 with SOAPFaultException

use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.

the class Soap11ClientServerTest method testNewLineInExceptionMessage.

@Test
public void testNewLineInExceptionMessage() throws Exception {
    Greeter greeter = getGreeter();
    try {
        greeter.greetMe("newline");
        fail("Should throw Exception!");
    } catch (SOAPFaultException ex) {
        assertEquals("greetMeFault Caused by: Get a wrong name <greetMe>", ex.getMessage());
        StackTraceElement[] elements = ex.getCause().getStackTrace();
        assertEquals("org.apache.cxf.systest.soapfault.details.GreeterImpl11", elements[0].getClassName());
        assertTrue(ex.getCause().getCause().getMessage().endsWith("Test \n cause."));
    }
}
Also used : Greeter(org.apache.cxf.greeter_control.Greeter) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.junit.Test)

Example 69 with SOAPFaultException

use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.

the class SOAPDocLitClientTypeTest method testValidationFailureOnServerOut.

@Test
public void testValidationFailureOnServerOut() throws Exception {
    FixedArray x = new FixedArray();
    FixedArray yOrig = new FixedArray();
    x.getItem().addAll(Arrays.asList(24, 42, 2008));
    yOrig.getItem().addAll(Arrays.asList(24, 0, 1));
    Holder<FixedArray> y = new Holder<FixedArray>(yOrig);
    Holder<FixedArray> z = new Holder<FixedArray>();
    try {
        docClient.testFixedArray(x, y, z);
        fail("should have thrown exception");
    } catch (SOAPFaultException ex) {
        assertTrue(ex.getMessage(), ex.getMessage().contains("Marshalling"));
    }
}
Also used : FixedArray(org.apache.type_test.types1.FixedArray) Holder(javax.xml.ws.Holder) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.junit.Test)

Example 70 with SOAPFaultException

use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.

the class AbstractJAXWSMethodInvoker method createFault.

@Override
protected Fault createFault(Throwable ex, Method m, List<Object> params, boolean checked) {
    // map the JAX-WS faults
    SOAPFaultException sfe = findSoapFaultException(ex);
    if (sfe != null) {
        SoapFault fault = new SoapFault(sfe.getFault().getFaultString(), ex, sfe.getFault().getFaultCodeAsQName());
        fault.setRole(sfe.getFault().getFaultActor());
        if (sfe.getFault().hasDetail()) {
            fault.setDetail(sfe.getFault().getDetail());
        }
        return fault;
    }
    return super.createFault(ex, m, params, checked);
}
Also used : SoapFault(org.apache.cxf.binding.soap.SoapFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException)

Aggregations

SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)97 Test (org.junit.Test)47 QName (javax.xml.namespace.QName)33 URL (java.net.URL)22 LogfileTestTailer (com.evolveum.midpoint.test.util.LogfileTestTailer)21 Test (org.testng.annotations.Test)21 Holder (javax.xml.ws.Holder)19 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)17 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)17 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)17 SOAPFault (javax.xml.soap.SOAPFault)17 SOAPException (javax.xml.soap.SOAPException)16 Service (javax.xml.ws.Service)11 WebServiceException (javax.xml.ws.WebServiceException)9 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)9 SOAPMessage (javax.xml.soap.SOAPMessage)8 SoapFault (org.apache.cxf.binding.soap.SoapFault)8 Bus (org.apache.cxf.Bus)6 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)6 Fault (org.apache.cxf.interceptor.Fault)6