Search in sources :

Example 46 with SOAPFaultException

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

the class WSAResponsesClientServerTest method testWSAResponses.

@Test
public void testWSAResponses() throws Exception {
    this.setupInLogging();
    this.setupOutLogging();
    URL wsdlURL = new URL("http://localhost:" + PORT + "/wsa/responses?wsdl");
    QName serviceQName = new QName("http://cxf.apache.org/systest/wsa/responses", "HelloService");
    HelloService service = new HelloService(wsdlURL, serviceQName);
    try {
        service.getHelloPort().sayHi("helloWorld");
        fail("Expect exception");
    } catch (Exception e) {
        String expectedDetail = "A header representing a Message Addressing Property is not valid";
        if (e instanceof SOAPFaultException) {
            assertTrue("Expect fault deail : " + expectedDetail, e.getMessage().indexOf(expectedDetail) > -1);
        } else {
            throw e;
        }
    }
}
Also used : QName(javax.xml.namespace.QName) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) URL(java.net.URL) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.junit.Test)

Example 47 with SOAPFaultException

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

the class SecurityPolicyTest method testFault.

@Test
public void testFault() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SecurityPolicyTest.class.getResource("https_config_client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = SecurityPolicyTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItFaultPortSignThenEncrypt");
    DoubleItPortType pt = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(pt, PORT);
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, new KeystorePasswordCallback());
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES, "alice.properties");
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES, "bob.properties");
    // DOM
    try {
        pt.doubleIt(5);
        fail("SOAPFaultException expected!");
    } catch (SOAPFaultException e) {
        assertEquals("Foo", e.getFault().getFaultString());
    } finally {
        ((java.io.Closeable) pt).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) KeystorePasswordCallback(org.apache.cxf.systest.ws.common.KeystorePasswordCallback) Test(org.junit.Test)

Example 48 with SOAPFaultException

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

the class MaxChildTest method tooBig.

@Test
public void tooBig() throws MalformedURLException {
    try {
        final Root root = new Root();
        for (int i = 0; i < 2; i++) {
            root.getChildren().add(new Child());
        }
        javax.xml.ws.Service.create(new URL(this.root.toExternalForm() + "app/ws?wsdl"), new QName("http://cxf.server.openejb.apache.org/", "SimpleContractImplService")).getPort(SimpleContract.class).test(root);
    } catch (final SOAPFaultException e) {
        assertEquals("Unmarshalling Error: Maximum Number of Child Elements limit (1) Exceeded ", e.getMessage());
    }
}
Also used : QName(javax.xml.namespace.QName) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) URL(java.net.URL) Test(org.junit.Test)

Example 49 with SOAPFaultException

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

the class CalculatorTest method call.

@Test
public void call() throws MalformedURLException {
    final EJBContainer container = EJBContainer.createEJBContainer(new Properties() {

        {
            setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true");
            // random port to avoid issue on CI, default is 4204
            setProperty("httpejbd.port", "0");
        }
    });
    // get back the random port
    final int port = Integer.parseInt(SystemInstance.get().getProperty("httpejbd.port"));
    // normal call
    final Service service = Service.create(new URL("http://127.0.0.1:" + port + "/webservice-ws-with-resources-config/CalculatorBean?wsdl"), new QName("http://security.ws.superbiz.org/", "CalculatorBeanService"));
    final Calculator calculator = service.getPort(Calculator.class);
    ClientProxy.getClient(calculator).getOutInterceptors().add(new WSS4JOutInterceptor(new HashMap<String, Object>() {

        {
            put("action", "UsernameToken");
            put("user", "openejb");
            put("passwordType", "PasswordText");
            put("passwordCallbackRef", new CallbackHandler() {

                @Override
                public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                    final WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
                    pc.setPassword("tomee");
                }
            });
        }
    }));
    assertEquals(5, calculator.add(2, 3));
    // bad auth
    final Calculator calculator2 = service.getPort(Calculator.class);
    ClientProxy.getClient(calculator2).getOutInterceptors().add(new WSS4JOutInterceptor(new HashMap<String, Object>() {

        {
            put("action", "UsernameToken");
            put("user", "openejb");
            put("passwordType", "PasswordText");
            put("passwordCallbackRef", new CallbackHandler() {

                @Override
                public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                    final WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
                    pc.setPassword("wrong");
                }
            });
        }
    }));
    try {
        assertEquals(5, calculator2.add(2, 3));
    } catch (SOAPFaultException sfe) {
        assertThat(sfe.getMessage(), CoreMatchers.containsString("A security error was encountered when verifying the message"));
    }
    container.close();
    // valid it passed because all was fine and not because the server config was not here
    assertTrue(PasswordCallbackHandler.wasCalled());
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) IOException(java.io.IOException) Properties(java.util.Properties) URL(java.net.URL) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) Callback(javax.security.auth.callback.Callback) EJBContainer(javax.ejb.embeddable.EJBContainer) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) Test(org.junit.Test)

Example 50 with SOAPFaultException

use of javax.xml.ws.soap.SOAPFaultException in project wildfly by wildfly.

the class EJBEndpoint method helloError.

public String helloError(String input) {
    try {
        SOAPFault fault = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createFault(input, SOAPConstants.SOAP_VERSIONMISMATCH_FAULT);
        fault.setFaultActor("mr.actor");
        fault.addDetail().addChildElement("test");
        fault.appendFaultSubcode(new QName("http://ws.gss.redhat.com/", "NullPointerException"));
        fault.appendFaultSubcode(new QName("http://ws.gss.redhat.com/", "OperatorNotFound"));
        throw new SOAPFaultException(fault);
    } catch (SOAPException ex) {
        ex.printStackTrace();
    }
    return "Failure!";
}
Also used : QName(javax.xml.namespace.QName) SOAPException(javax.xml.soap.SOAPException) SOAPFault(javax.xml.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