Search in sources :

Example 76 with SOAPFaultException

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

the class WSAPureWsdlTest method testDispatchActionMissmatch.

@Test
public void testDispatchActionMissmatch() throws Exception {
    String req = "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<S:Body><addNumbers3 xmlns=\"http://apache.org/cxf/systest/ws/addr_feature/\">" + "<number1>1</number1><number2>2</number2></addNumbers3>" + "</S:Body></S:Envelope>";
    // String base = "http://apache.org/cxf/systest/ws/addr_feature/AddNumbersPortType/";
    String expectedOut = "http://bad.action";
    URL wsdl = getClass().getResource("/wsdl_systest_wsspec/add_numbers.wsdl");
    assertNotNull("WSDL is null", wsdl);
    AddNumbersService service = new AddNumbersService(wsdl, serviceName);
    Dispatch<Source> disp = service.createDispatch(AddNumbersService.AddNumbersPort, Source.class, Mode.MESSAGE);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT + "/jaxws/add");
    // manually set the action
    disp.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, expectedOut);
    disp.getRequestContext().put(ContextUtils.ACTION, expectedOut + "/wsaAction");
    try {
        disp.invoke(new StreamSource(new StringReader(req)));
        fail("no exception");
    } catch (SOAPFaultException f) {
    // expected
    }
}
Also used : AddNumbersService(org.apache.cxf.systest.ws.addr_feature.AddNumbersService) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) URL(java.net.URL) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 77 with SOAPFaultException

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

the class WSSecurityClientTest method testDecoupledFaultFromSecurity.

@Test
public void testDecoupledFaultFromSecurity() throws Exception {
    Dispatch<Source> dispatcher = null;
    java.io.InputStream is = null;
    // 
    // Sending no security headers should result in a Fault
    // 
    dispatcher = createUsernameTokenDispatcher(true, test.getPort());
    is = getClass().getResourceAsStream("test-data/NoHeadersRequest.xml");
    try {
        dispatcher.invoke(new StreamSource(is));
        fail("exception should have been generated");
    } catch (SOAPFaultException ex) {
        assertTrue(ex.getMessage().equals(WSSecurityException.UNIFIED_SECURITY_ERR));
    }
    // 
    // Sending and empty header should result in a Fault
    // 
    dispatcher = createUsernameTokenDispatcher(true, test.getPort());
    is = getClass().getResourceAsStream("test-data/EmptyHeaderRequest.xml");
    try {
        dispatcher.invoke(new StreamSource(is));
        fail("exception should have been generated");
    } catch (SOAPFaultException ex) {
        assertTrue(ex.getMessage().equals(WSSecurityException.UNIFIED_SECURITY_ERR));
    }
    // 
    // Sending and empty security header should result in a Fault
    // 
    dispatcher = createUsernameTokenDispatcher(true, test.getPort());
    is = getClass().getResourceAsStream("test-data/EmptySecurityHeaderRequest.xml");
    try {
        dispatcher.invoke(new StreamSource(is));
        fail("exception should have been generated");
    } catch (SOAPFaultException ex) {
        assertTrue(ex.getMessage().equals(WSSecurityException.UNIFIED_SECURITY_ERR));
    }
}
Also used : StreamSource(javax.xml.transform.stream.StreamSource) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 78 with SOAPFaultException

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

the class JavaFirstPolicyServiceTest method testOperationNoClientCertAlternativePolicy.

@Test
public void testOperationNoClientCertAlternativePolicy() {
    System.setProperty("testutil.ports.JavaFirstPolicyServer.3", PORT3);
    ClassPathXmlApplicationContext clientContext = new ClassPathXmlApplicationContext(new String[] { "org/apache/cxf/systest/ws/policy/sslnocertclient.xml" });
    OperationSimpleService simpleService = clientContext.getBean("OperationSimpleServiceClient", OperationSimpleService.class);
    // no security on ping!
    simpleService.ping();
    try {
        simpleService.doStuff();
        fail("Expected exception as no credentials");
    } catch (SOAPFaultException e) {
        assertTrue(true);
    }
    WSS4JOutInterceptor wssOut = addToClient(simpleService);
    wssOut.setProperties(getNoPasswordProperties("alice"));
    try {
        simpleService.doStuff();
        fail("Expected exception as no password and no client cert");
    } catch (SOAPFaultException e) {
        assertTrue(true);
    }
    // this is successful because the alternative policy allows a password to be specified.
    wssOut.setProperties(getPasswordProperties("alice", "password"));
    simpleService.doStuff();
    clientContext.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) OperationSimpleService(org.apache.cxf.systest.ws.policy.javafirst.OperationSimpleService) NoAlternativesOperationSimpleService(org.apache.cxf.systest.ws.policy.javafirst.NoAlternativesOperationSimpleService) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Test(org.junit.Test)

Example 79 with SOAPFaultException

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

the class JavaFirstPolicyServiceTest method testNoAltOperationClientCertPolicy.

@Test
public void testNoAltOperationClientCertPolicy() {
    System.setProperty("testutil.ports.JavaFirstPolicyServer.3", PORT3);
    ClassPathXmlApplicationContext clientContext = new ClassPathXmlApplicationContext(new String[] { "org/apache/cxf/systest/ws/policy/sslcertclient.xml" });
    NoAlternativesOperationSimpleService simpleService = clientContext.getBean("NoAlternativesOperationSimpleServiceClient", NoAlternativesOperationSimpleService.class);
    try {
        simpleService.doStuff();
        fail("Expected exception as no credentials");
    } catch (SOAPFaultException e) {
        assertTrue(true);
    }
    WSS4JOutInterceptor wssOut = addToClient(simpleService);
    wssOut.setProperties(getNoPasswordProperties("alice"));
    simpleService.doStuff();
    wssOut.setProperties(getPasswordProperties("alice", "password"));
    try {
        simpleService.doStuff();
        fail("Expected exception as password not allowed");
    } catch (SOAPFaultException e) {
        assertTrue(true);
    }
    wssOut.setProperties(getNoPasswordProperties("alice"));
    try {
        simpleService.ping();
        fail("Expected exception as no password");
    } catch (SOAPFaultException e) {
        assertTrue(true);
    }
    wssOut.setProperties(getPasswordProperties("alice", "password"));
    simpleService.ping();
    clientContext.close();
}
Also used : NoAlternativesOperationSimpleService(org.apache.cxf.systest.ws.policy.javafirst.NoAlternativesOperationSimpleService) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Test(org.junit.Test)

Example 80 with SOAPFaultException

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

the class JavaFirstPolicyServiceTest method testBindingClientCertAlternativePolicy.

@Test
public void testBindingClientCertAlternativePolicy() {
    System.setProperty("testutil.ports.JavaFirstPolicyServer.3", PORT3);
    ClassPathXmlApplicationContext clientContext = new ClassPathXmlApplicationContext(new String[] { "org/apache/cxf/systest/ws/policy/sslcertclient.xml" });
    BindingSimpleService simpleService = clientContext.getBean("BindingSimpleServiceClient", BindingSimpleService.class);
    try {
        simpleService.doStuff();
        fail("Expected exception as no credentials");
    } catch (SOAPFaultException e) {
        assertTrue(true);
    }
    WSS4JOutInterceptor wssOut = addToClient(simpleService);
    wssOut.setProperties(getNoPasswordProperties("alice"));
    simpleService.doStuff();
    wssOut.setProperties(getPasswordProperties("alice", "password"));
    // this is successful because the alternative policy allows a password to be specified.
    simpleService.doStuff();
    clientContext.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BindingSimpleService(org.apache.cxf.systest.ws.policy.javafirst.BindingSimpleService) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) 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