Search in sources :

Example 86 with SOAPFaultException

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

the class ClientServerMiscTest method testDocLitBare.

@Test
public void testDocLitBare() throws Exception {
    QName portName = new QName("http://cxf.apache.org/systest/jaxws/DocLitBareCodeFirstService", "DocLitBareCodeFirstServicePort");
    QName servName = new QName("http://cxf.apache.org/systest/jaxws/DocLitBareCodeFirstService", "DocLitBareCodeFirstService");
    // try without wsdl
    Service service = Service.create(servName);
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, ServerMisc.DOCLITBARE_CODEFIRST_URL);
    DocLitBareCodeFirstService port = service.getPort(portName, DocLitBareCodeFirstService.class);
    DocLitBareCodeFirstService.GreetMeRequest req = new DocLitBareCodeFirstService.GreetMeRequest();
    DocLitBareCodeFirstService.GreetMeResponse resp;
    BigInteger[] i;
    req.setName("Foo");
    resp = port.greetMe(req);
    assertEquals(req.getName(), resp.getName());
    i = port.sayTest(new DocLitBareCodeFirstService.SayTestRequest("Dan"));
    assertEquals(4, i.length);
    assertEquals(0, i[0].intValue());
    assertEquals(1, i[1].intValue());
    assertEquals(2, i[2].intValue());
    assertEquals(3, i[3].intValue());
    // try with wsdl
    service = Service.create(new URL(ServerMisc.DOCLITBARE_CODEFIRST_URL + "?wsdl"), servName);
    port = service.getPort(portName, DocLitBareCodeFirstService.class);
    resp = port.greetMe(req);
    assertEquals(req.getName(), resp.getName());
    // try the fault
    req.setName("fault");
    try {
        resp = port.greetMe(req);
        fail("did not get fault back");
    } catch (SOAPFaultException ex) {
        assertEquals("mr.actor", ex.getFault().getFaultActor());
        assertEquals("test", ex.getFault().getDetail().getFirstChild().getLocalName());
    }
    req.setName("emptyfault");
    try {
        resp = port.greetMe(req);
        fail("did not get fault back");
    } catch (SOAPFaultException ex) {
        assertNull(ex.getFault().getDetail());
    }
// This test will pass/fail completely dependent on the versions of JAXB picked up and what
// version of Xerces is picked up.  Newer versions of JAXB will generate "--11Z" (correct per XMLSchema)
// older version will generate "--11--Z".  Xerces will only parse "--11--Z".  The parser in the JDK
// will depend on the JDK version used.
/*
        GMonthTest gm = new GMonthTest();
        XMLGregorianCalendar dt = DatatypeFactory.newInstance().newXMLGregorianCalendarDate(2010, 11, 16, 0);
        gm.setValue(dt);
        GMonthTest gm2 = port.echoGMonthTest(gm);
        assertEquals(gm.getValue().getMonth(), gm2.getValue().getMonth());
        */
}
Also used : QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) AnonymousComplexTypeService(org.apache.cxf.anonymous_complex_type.AnonymousComplexTypeService) InheritService(org.apache.cxf.tests.inherit.InheritService) JaxbElementTest_Service(org.apache.cxf.jaxb_element_test.JaxbElementTest_Service) OrderedParamHolder_Service(org.apache.cxf.ordered_param_holder.OrderedParamHolder_Service) BigInteger(java.math.BigInteger) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) URL(java.net.URL) JaxbElementTest(org.apache.cxf.jaxb_element_test.JaxbElementTest) Test(org.junit.Test)

Example 87 with SOAPFaultException

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

the class ClientServerRPCLitTest method testComplexType.

@Test
public void testComplexType() throws Exception {
    SOAPServiceRPCLit service = new SOAPServiceRPCLit();
    assertNotNull(service);
    GreeterRPCLit greeter = service.getPort(portName, GreeterRPCLit.class);
    updateAddressPort(greeter, PORT);
    MyComplexStruct in = new MyComplexStruct();
    in.setElem1("elem1");
    in.setElem2("elem2");
    in.setElem3(45);
    try {
        ((BindingProvider) greeter).getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.TRUE);
        MyComplexStruct out = greeter.sendReceiveData(in);
        assertNotNull("no response received from service", out);
        assertEquals(in.getElem1(), out.getElem1());
        assertEquals(in.getElem2(), out.getElem2());
        assertEquals(in.getElem3(), out.getElem3());
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
    try {
        in.setElem2("invalid");
        greeter.sendReceiveData(in);
    } catch (SOAPFaultException f) {
        assertTrue(f.getCause() instanceof UnmarshalException);
    }
}
Also used : SOAPServiceRPCLit(org.apache.hello_world_rpclit.SOAPServiceRPCLit) GreeterRPCLit(org.apache.hello_world_rpclit.GreeterRPCLit) UnmarshalException(javax.xml.bind.UnmarshalException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) MyComplexStruct(org.apache.hello_world_rpclit.types.MyComplexStruct) Test(org.junit.Test)

Example 88 with SOAPFaultException

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

the class DispatchClientServerTest method testTimeout.

@Test
public void testTimeout() throws Exception {
    // CXF-2384
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    // pick one of the other service/ports that would have an address
    // without a service running
    QName otherServiceName = new QName("http://apache.org/hello_world_soap_http", "SOAPProviderService");
    QName otherPortName = new QName("http://apache.org/hello_world_soap_http", "SoapProviderPort");
    SOAPService service = new SOAPService(wsdl, otherServiceName);
    assertNotNull(service);
    Dispatch<SOAPMessage> disp = service.createDispatch(otherPortName, SOAPMessage.class, Service.Mode.MESSAGE);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + TestUtil.getPortNumber("fake-port") + "/SOAPDispatchService/SoapDispatchPort");
    DispatchImpl<?> dispImpl = (DispatchImpl<?>) disp;
    HTTPConduit cond = (HTTPConduit) dispImpl.getClient().getConduit();
    cond.getClient().setConnectionTimeout(500);
    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, is);
    assertNotNull(soapReqMsg);
    try {
        disp.invoke(soapReqMsg);
        fail("Should have faulted");
    } catch (SOAPFaultException ex) {
        fail("should not be a SOAPFaultException");
    } catch (WebServiceException ex) {
        // expected
        assertTrue(ex.getCause().getClass().getName(), ex.getCause() instanceof java.net.ConnectException || ex.getCause() instanceof java.net.SocketTimeoutException);
    }
    dispImpl.close();
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) InputStream(java.io.InputStream) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) SocketTimeoutException(java.net.SocketTimeoutException) Test(org.junit.Test)

Example 89 with SOAPFaultException

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

the class DispatchClientServerTest method test404.

@Test
public void test404() throws Exception {
    // CXF-2384
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    // pick one of the other service/ports that would have an address
    // without a service running
    QName otherServiceName = new QName("http://apache.org/hello_world_soap_http", "SOAPProviderService");
    QName otherPortName = new QName("http://apache.org/hello_world_soap_http", "SoapProviderPort");
    SOAPService service = new SOAPService(wsdl, otherServiceName);
    assertNotNull(service);
    Dispatch<SOAPMessage> disp = service.createDispatch(otherPortName, SOAPMessage.class, Service.Mode.MESSAGE);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + greeterPort + "/SomePlaceWithNoServiceRunning/SoapDispatchPort");
    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, is);
    assertNotNull(soapReqMsg);
    try {
        disp.invoke(soapReqMsg);
        fail("Should have faulted");
    } catch (SOAPFaultException ex) {
        fail("should not be a SOAPFaultException");
    } catch (WebServiceException ex) {
        // expected
        assertTrue(ex.getCause().getClass().getName(), ex.getCause() instanceof java.io.IOException);
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) Test(org.junit.Test)

Example 90 with SOAPFaultException

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

the class HandlerInvocationTest method testServerEndpointRemoteFault.

@Test
public void testServerEndpointRemoteFault() throws PingException {
    TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false);
    TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) {

        public boolean handleFault(LogicalMessageContext ctx) {
            super.handleFault(ctx);
            try {
                Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
                if (!outbound) {
                    LogicalMessage msg = ctx.getMessage();
                    String payload = convertDOMToString(msg.getPayload());
                    assertTrue(payload.indexOf("<faultstring>" + "servant throws SOAPFaultException" + "</faultstring>") > -1);
                }
            } catch (Exception e) {
                e.printStackTrace();
                fail(e.toString());
            }
            return true;
        }

        private String convertDOMToString(Source s) throws TransformerException {
            StringWriter stringWriter = new StringWriter();
            StreamResult streamResult = new StreamResult(stringWriter);
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            transformerFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
            Transformer transformer = transformerFactory.newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "no");
            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
            transformer.transform(s, streamResult);
            return stringWriter.toString();
        }
    };
    TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
    TestSOAPHandler soapHandler2 = new TestSOAPHandler(false) {

        public boolean handleFault(SOAPMessageContext ctx) {
            super.handleFault(ctx);
            try {
                Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
                if (!outbound) {
                    SOAPEnvelope env = ctx.getMessage().getSOAPPart().getEnvelope();
                    assertTrue("expected SOAPFault in SAAJ model", env.getBody().hasFault());
                }
            } catch (Exception e) {
                e.printStackTrace();
                fail(e.toString());
            }
            return true;
        }
    };
    addHandlersToChain((BindingProvider) handlerTest, handler1, handler2, soapHandler1, soapHandler2);
    try {
        handlerTest.pingWithArgs("servant throw SOAPFaultException");
        fail("did not get expected Exception");
    } catch (SOAPFaultException sfe) {
    // expected
    }
    assertEquals(1, handler1.getHandleMessageInvoked());
    assertEquals(1, handler2.getHandleMessageInvoked());
    assertEquals(1, soapHandler1.getHandleMessageInvoked());
    assertEquals(1, soapHandler2.getHandleMessageInvoked());
    assertEquals(1, handler2.getHandleFaultInvoked());
    assertEquals(1, handler1.getHandleFaultInvoked());
    assertEquals(1, soapHandler1.getHandleFaultInvoked());
    assertEquals(1, soapHandler2.getHandleFaultInvoked());
    assertEquals(1, handler1.getCloseInvoked());
    assertEquals(1, handler2.getCloseInvoked());
    assertEquals(1, soapHandler1.getCloseInvoked());
    assertEquals(1, soapHandler2.getCloseInvoked());
    assertTrue(handler2.getInvokeOrderOfClose() < handler1.getInvokeOrderOfClose());
}
Also used : LogicalMessageContext(javax.xml.ws.handler.LogicalMessageContext) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) PingException(org.apache.handler_test.PingException) ProtocolException(javax.xml.ws.ProtocolException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) TransformerException(javax.xml.transform.TransformerException) WebServiceException(javax.xml.ws.WebServiceException) Source(javax.xml.transform.Source) StringWriter(java.io.StringWriter) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) LogicalMessage(javax.xml.ws.LogicalMessage) HandlerTest(org.apache.handler_test.HandlerTest) 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