Search in sources :

Example 91 with SOAPFaultException

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

the class HandlerInvocationTest method testSOAPHandlerHandleMessageThrowsSOAPFaultExceptionServerInbound.

@Test
public void testSOAPHandlerHandleMessageThrowsSOAPFaultExceptionServerInbound() throws PingException {
    try {
        handlerTest.pingWithArgs("soapHandler3 inbound throw SOAPFaultExceptionWDetail");
        fail("did not get expected SOAPFaultException");
    } catch (SOAPFaultException e) {
        assertEquals("HandleMessage throws exception", e.getMessage());
        SOAPFault fault = e.getFault();
        assertNotNull(fault);
        assertEquals(new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, "Server"), fault.getFaultCodeAsQName());
        assertEquals("http://gizmos.com/orders", fault.getFaultActor());
        Detail detail = fault.getDetail();
        assertNotNull(detail);
        QName nn = new QName("http://gizmos.com/orders/", "order");
        Element el = DOMUtils.getFirstChildWithName(detail, nn);
        assertNotNull(el);
        el.normalize();
        assertEquals("Quantity element does not have a value", el.getFirstChild().getNodeValue());
        el = DOMUtils.getNextElement(el);
        el.normalize();
        assertEquals("Incomplete address: no zip code", el.getFirstChild().getNodeValue());
    }
}
Also used : QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPFault(javax.xml.soap.SOAPFault) Detail(javax.xml.soap.Detail) HandlerTest(org.apache.handler_test.HandlerTest) Test(org.junit.Test)

Example 92 with SOAPFaultException

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

the class DispatchSourceClient method main.

public static void main(String[] args) throws Exception {
    Server.main(new String[] { "inProcess" });
    Service service = Service.create(SERVICE_NAME);
    service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, ADDRESS);
    Dispatch<Source> dispatch = service.createDispatch(PORT_NAME, Source.class, Service.Mode.PAYLOAD);
    String resp;
    Source response;
    System.out.println("Invoking sayHi...");
    setOperation(dispatch, SAYHI_OPERATION_NAME);
    response = dispatch.invoke(encodeSource(SAYHI_REQUEST_TEMPLATE, null));
    resp = decodeSource(response, PAYLOAD_NAMESPACE_URI, "responseType");
    System.out.println("Server responded with: " + resp);
    System.out.println();
    System.out.println("Invoking greetMe...");
    setOperation(dispatch, GREETME_OPERATION_NAME);
    response = dispatch.invoke(encodeSource(GREETME_REQUEST_TEMPLATE, System.getProperty("user.name")));
    resp = decodeSource(response, PAYLOAD_NAMESPACE_URI, "responseType");
    System.out.println("Server responded with: " + resp);
    System.out.println();
    try {
        System.out.println("Invoking pingMe, expecting exception...");
        setOperation(dispatch, PINGME_OPERATION_NAME);
        response = dispatch.invoke(encodeSource(PINGME_REQUEST_TEMPLATE, null));
    } catch (SOAPFaultException ex) {
        System.out.println("Expected exception: SoapFault has occurred: " + ex.getMessage());
    }
    System.exit(0);
}
Also used : Service(javax.xml.ws.Service) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Example 93 with SOAPFaultException

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

the class JMSWSSecurityTest method testUnsignedSAML2AudienceRestrictionTokenBadURI.

@Test
public void testUnsignedSAML2AudienceRestrictionTokenBadURI() throws Exception {
    QName serviceName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldService");
    QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldPort");
    URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
    HelloWorldService service = new HelloWorldService(wsdl, serviceName);
    HelloWorldPortType greeter = service.getPort(portName, HelloWorldPortType.class);
    SamlCallbackHandler callbackHandler = new SamlCallbackHandler();
    callbackHandler.setSignAssertion(true);
    callbackHandler.setConfirmationMethod(SAML2Constants.CONF_BEARER);
    ConditionsBean conditions = new ConditionsBean();
    conditions.setTokenPeriodMinutes(5);
    List<String> audiences = new ArrayList<>();
    audiences.add("jms:jndi:dynamicQueues/test.jmstransport.text.bad");
    AudienceRestrictionBean audienceRestrictionBean = new AudienceRestrictionBean();
    audienceRestrictionBean.setAudienceURIs(audiences);
    conditions.setAudienceRestrictions(Collections.singletonList(audienceRestrictionBean));
    callbackHandler.setConditions(conditions);
    Map<String, Object> outProperties = new HashMap<>();
    outProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED);
    outProperties.put(ConfigurationConstants.SAML_CALLBACK_REF, callbackHandler);
    WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(outProperties);
    Client client = ClientProxy.getClient(greeter);
    client.getOutInterceptors().add(outInterceptor);
    try {
        greeter.sayHi();
        fail("Failure expected on a bad audience restriction");
    } catch (SOAPFaultException ex) {
    // expected
    }
    ((java.io.Closeable) greeter).close();
}
Also used : AudienceRestrictionBean(org.apache.wss4j.common.saml.bean.AudienceRestrictionBean) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) HelloWorldService(org.apache.cxf.hello_world_jms.HelloWorldService) ConditionsBean(org.apache.wss4j.common.saml.bean.ConditionsBean) ArrayList(java.util.ArrayList) HelloWorldPortType(org.apache.cxf.hello_world_jms.HelloWorldPortType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) URL(java.net.URL) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Example 94 with SOAPFaultException

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

the class BraveTracingTest method testThatNewSpanIsCreatedInCaseOfFault.

@Test
public void testThatNewSpanIsCreatedInCaseOfFault() throws MalformedURLException {
    final BookStoreService service = createJaxWsService();
    try {
        service.removeBooks();
        fail("Expected SOAPFaultException to be raised");
    } catch (final SOAPFaultException ex) {
    /* expected exception */
    }
    assertThat(TestSpanReporter.getAllSpans().size(), equalTo(1));
    assertThat(TestSpanReporter.getAllSpans().get(0).name, equalTo("post /bookstore"));
    final Map<String, List<String>> headers = getResponseHeaders(service);
    assertFalse(headers.containsKey(TRACE_ID_NAME));
    assertFalse(headers.containsKey(SAMPLED_NAME));
    assertFalse(headers.containsKey(PARENT_SPAN_ID_NAME));
    assertFalse(headers.containsKey(SPAN_ID_NAME));
}
Also used : BookStoreService(org.apache.cxf.systest.jaxws.tracing.BookStoreService) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) List(java.util.List) Test(org.junit.Test)

Example 95 with SOAPFaultException

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

the class OpenTracingTracingTest method testThatNewChildSpanIsCreatedWhenParentIsProvidedInCaseOfFault.

@Test
public void testThatNewChildSpanIsCreatedWhenParentIsProvidedInCaseOfFault() throws MalformedURLException {
    final BookStoreService service = createJaxWsService(new Configurator() {

        @Override
        public void configure(final JaxWsProxyFactoryBean factory) {
            factory.getFeatures().add(new OpenTracingClientFeature(tracer));
            factory.getOutInterceptors().add(new LoggingOutInterceptor());
            factory.getInInterceptors().add(new LoggingInInterceptor());
        }
    });
    try {
        service.removeBooks();
        fail("Expected SOAPFaultException to be raised");
    } catch (final SOAPFaultException ex) {
    /* expected exception */
    }
    assertThat(TestSender.getAllSpans().size(), equalTo(2));
    assertThat(TestSender.getAllSpans().get(0).getOperationName(), equalTo("POST /BookStore"));
    assertThat(TestSender.getAllSpans().get(1).getOperationName(), equalTo("POST http://localhost:" + PORT + "/BookStore"));
}
Also used : OpenTracingClientFeature(org.apache.cxf.tracing.opentracing.OpenTracingClientFeature) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) BookStoreService(org.apache.cxf.systest.jaxws.tracing.BookStoreService) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) 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