Search in sources :

Example 31 with SOAPFaultException

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

the class ClientServerMiscTest method testExceptionCases.

private void testExceptionCases(DocLitWrappedCodeFirstService port) throws Exception {
    /*   CXF-926 test case */
    try {
        port.throwException(10);
        fail("Expected exception not found");
    } catch (ServiceTestFault ex) {
        assertEquals(10L, ex.getFaultInfo().getId());
    }
    // CXF-1131 testcase
    try {
        port.throwException(-1);
        fail("Expected exception not found");
    } catch (ServiceTestFault ex) {
        assertNull(ex.getFaultInfo());
    }
    // CXF-1136 testcase
    try {
        port.throwException(-2);
        fail("Expected exception not found");
    } catch (CustomException ex) {
        assertEquals("CE: -2", ex.getMessage());
        assertEquals("A Value", ex.getA());
        assertEquals("B Value", ex.getB());
    }
    // CXF-1407
    try {
        port.throwException(-3);
        fail("Expected exception not found");
    } catch (ComplexException ex) {
        assertEquals("Throw user fault -3", ex.getMessage());
        assertEquals(3, ex.getInts().length);
    }
    try {
        port.throwException(-3);
        fail("Expected exception not found");
    } catch (ComplexException ex) {
        assertEquals("Throw user fault -3", ex.getMessage());
    }
    try {
        port.throwException(-4);
        fail("Expected exception not found");
    } catch (WebServiceException ex) {
        assertEquals("RuntimeException!!", ex.getMessage());
    }
    try {
        Foo foo = new Foo();
        foo.setNameIgnore("DoNoName");
        port.modifyFoo(foo);
        fail("Expected exception not found");
    } catch (SOAPFaultException ex) {
        assertTrue(ex.getMessage(), ex.getMessage().contains("NoName is not a valid name"));
    }
    try {
        Foo foo = new Foo();
        foo.setNameIgnore("NoName");
        port.modifyFoo(foo);
        fail("Expected exception not found");
    } catch (SOAPFaultException ex) {
        assertTrue(ex.getMessage().contains("NoName is not a valid name"));
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Foo(org.apache.cxf.systest.jaxws.DocLitWrappedCodeFirstService.Foo) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException)

Example 32 with SOAPFaultException

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

the class DocLitBareCodeFirstServiceImpl method greetMe.

public GreetMeResponse greetMe(GreetMeRequest gmr) {
    if ("fault".equals(gmr.getName())) {
        try {
            SOAPFactory factory = SOAPFactory.newInstance();
            SOAPFault fault = factory.createFault("this is a fault string!", new QName("http://foo", "FooCode"));
            fault.setFaultActor("mr.actor");
            fault.addDetail().addChildElement("test").addTextNode("TestText");
            throw new SOAPFaultException(fault);
        } catch (SOAPException ex) {
            throw new WebServiceException(ex);
        }
    } else if ("emptyfault".equals(gmr.getName())) {
        throw new RuntimeException("Empty!");
    }
    GreetMeResponse resp = new GreetMeResponse();
    resp.setName(gmr.getName());
    return resp;
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) SOAPException(javax.xml.soap.SOAPException) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPFactory(javax.xml.soap.SOAPFactory)

Example 33 with SOAPFaultException

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

the class JAXRSClientServerValidationSpringTest method testHelloSoapValidationFailsIfNameIsNull.

@Test
public void testHelloSoapValidationFailsIfNameIsNull() throws Exception {
    final QName serviceName = new QName("http://bookworld.com", "BookWorld");
    final QName portName = new QName("http://bookworld.com", "BookWorldPort");
    final String address = "http://localhost:" + PORT + "/bwsoap";
    Service service = Service.create(serviceName);
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address);
    BookWorld bwService = service.getPort(BookWorld.class);
    BookWithValidation bw = bwService.echoBook(new BookWithValidation("WS", "123"));
    assertEquals("123", bw.getId());
    try {
        bwService.echoBook(new BookWithValidation(null, "123"));
        fail("Validation failure expected");
    } catch (SOAPFaultException ex) {
    // complete
    }
}
Also used : QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) BookWithValidation(org.apache.cxf.systest.jaxrs.validation.BookWithValidation) AbstractJAXRSValidationTest(org.apache.cxf.systest.jaxrs.validation.AbstractJAXRSValidationTest) Test(org.junit.Test)

Example 34 with SOAPFaultException

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

the class DispatchHandlerInvocationTest method testInvokeWithSOAPMessagePayloadMode.

@Test
public void testInvokeWithSOAPMessagePayloadMode() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    assertNotNull(wsdl);
    AddNumbersService service = new AddNumbersService(wsdl, serviceName);
    assertNotNull(service);
    Dispatch<SOAPMessage> disp = service.createDispatch(portName, SOAPMessage.class, Mode.PAYLOAD);
    setAddress(disp, addNumbersAddress);
    TestHandler handler = new TestHandler();
    TestSOAPHandler soapHandler = new TestSOAPHandler();
    addHandlersProgrammatically(disp, handler, soapHandler);
    InputStream is2 = this.getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage soapReq = factory.createMessage(null, is2);
    try {
        disp.invoke(soapReq);
        fail("Did not get expected exception");
    } catch (SOAPFaultException e) {
        assertTrue("Did not get expected exception message: " + e.getMessage(), e.getMessage().indexOf("is not valid in PAYLOAD mode with SOAP/HTTP binding") > -1);
    }
}
Also used : AddNumbersService(org.apache.handlers.AddNumbersService) MessageFactory(javax.xml.soap.MessageFactory) InputStream(java.io.InputStream) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) Test(org.junit.Test)

Example 35 with SOAPFaultException

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

the class InterceptorFaultTest method testRobustFailWithoutAddressingInUserLogicalPhase.

@Test
public void testRobustFailWithoutAddressingInUserLogicalPhase() throws Exception {
    setupGreeter("org/apache/cxf/systest/interceptor/no-addr.xml", false);
    control.setRobustInOnlyMode(true);
    // behaviour is identicial for all phases
    FaultLocation location = new org.apache.cxf.greeter_control.types.ObjectFactory().createFaultLocation();
    location.setPhase("user-logical");
    control.setFaultLocation(location);
    try {
        // writer to grab the content of soap fault.
        // robust is not yet used at client's side, but I think it should
        StringWriter writer = new StringWriter();
        ((Client) greeter).getInInterceptors().add(new LoggingInInterceptor(new PrintWriterEventSender(new PrintWriter(writer))));
        // it should tell CXF to convert one-way robust out faults into real SoapFaultException
        ((Client) greeter).getEndpoint().put(Message.ROBUST_ONEWAY, true);
        greeter.greetMeOneWay("oneway");
        fail("Oneway operation unexpectedly succeded for phase " + location.getPhase());
    } catch (SOAPFaultException ex) {
    // expected
    }
}
Also used : StringWriter(java.io.StringWriter) PrintWriterEventSender(org.apache.cxf.ext.logging.event.PrintWriterEventSender) FaultLocation(org.apache.cxf.greeter_control.types.FaultLocation) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

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