Search in sources :

Example 16 with SOAPService

use of org.apache.hello_world_soap_http.SOAPService in project cxf by apache.

the class JettyDigestAuthTest method setupClient.

private HTTPConduit setupClient(boolean async) throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    greeter = new SOAPService(wsdl, SERVICE_NAME).getPort(Greeter.class);
    BindingProvider bp = (BindingProvider) greeter;
    ClientProxy.getClient(greeter).getInInterceptors().add(new LoggingInInterceptor());
    ClientProxy.getClient(greeter).getOutInterceptors().add(new LoggingOutInterceptor());
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ADDRESS);
    HTTPConduit cond = (HTTPConduit) ClientProxy.getClient(greeter).getConduit();
    HTTPClientPolicy client = new HTTPClientPolicy();
    cond.setClient(client);
    if (async) {
        if (cond instanceof AsyncHTTPConduit) {
            UsernamePasswordCredentials creds = new UsernamePasswordCredentials("ffang", "pswd");
            bp.getRequestContext().put(Credentials.class.getName(), creds);
            bp.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);
            client.setAutoRedirect(true);
        } else {
            fail("Not an async conduit");
        }
    } else {
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "ffang");
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd");
        cond.setAuthSupplier(new DigestAuthSupplier());
    }
    ClientProxy.getClient(greeter).getOutInterceptors().add(new AbstractPhaseInterceptor<Message>(Phase.PRE_STREAM_ENDING) {

        public void handleMessage(Message message) throws Fault {
            Map<String, ?> headers = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
            if (headers.containsKey("Proxy-Authorization")) {
                throw new RuntimeException("Should not have Proxy-Authorization");
            }
        }
    });
    client.setAllowChunking(false);
    return cond;
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) DigestAuthSupplier(org.apache.cxf.transport.http.auth.DigestAuthSupplier) Message(org.apache.cxf.message.Message) Fault(org.apache.cxf.interceptor.Fault) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) AsyncHTTPConduit(org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AsyncHTTPConduit(org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) Greeter(org.apache.hello_world_soap_http.Greeter) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Map(java.util.Map) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 17 with SOAPService

use of org.apache.hello_world_soap_http.SOAPService in project cxf by apache.

the class JettyBasicAuthTest method setUp.

@Before
public void setUp() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    greeter = new SOAPService(wsdl, SERVICE_NAME).getPort(Greeter.class);
    BindingProvider bp = (BindingProvider) greeter;
    ClientProxy.getClient(greeter).getInInterceptors().add(new LoggingInInterceptor());
    ClientProxy.getClient(greeter).getOutInterceptors().add(new LoggingOutInterceptor());
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ADDRESS);
    bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "ffang");
    bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd");
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) Greeter(org.apache.hello_world_soap_http.Greeter) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Before(org.junit.Before)

Example 18 with SOAPService

use of org.apache.hello_world_soap_http.SOAPService in project cxf by apache.

the class ProviderClientServerTest method testSOAPMessageModeDocLitWithSchemaValidation.

@Test
public void testSOAPMessageModeDocLitWithSchemaValidation() throws Exception {
    QName serviceName = new QName("http://apache.org/hello_world_soap_http", "SOAPProviderService");
    QName portName = new QName("http://apache.org/hello_world_soap_http", "SoapProviderPort");
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);
    try {
        Greeter greeter = service.getPort(portName, Greeter.class);
        setAddress(greeter, ADDRESS);
        try {
            greeter.greetMe("this is a greetMe message which length is more " + "than 30 so that I wanna a schema validation error");
            fail("Should have thrown an exception");
        } catch (Exception ex) {
            // expected
            assertTrue(ex.getMessage().contains("the length of the value is 96, but the required maximum is 30"));
        }
        try {
            greeter.greetMe("exceed maxLength");
            fail("Should have thrown an exception");
        } catch (Exception ex) {
            // expected
            assertTrue(ex.getMessage().contains("cvc-maxLength-valid"));
        }
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) QName(javax.xml.namespace.QName) Greeter(org.apache.hello_world_soap_http.Greeter) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) URL(java.net.URL) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.junit.Test)

Example 19 with SOAPService

use of org.apache.hello_world_soap_http.SOAPService in project cxf by apache.

the class ClientServerWebSocketTest method testAsyncSynchronousPolling.

@Test
public void testAsyncSynchronousPolling() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);
    final String expectedString = new String("Hello, finally!");
    class Poller extends Thread {

        Response<GreetMeLaterResponse> response;

        int tid;

        Poller(Response<GreetMeLaterResponse> r, int t) {
            response = r;
            tid = t;
        }

        public void run() {
            if (tid % 2 > 0) {
                while (!response.isDone()) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException ex) {
                    // ignore
                    }
                }
            }
            GreetMeLaterResponse reply = null;
            try {
                reply = response.get();
            } catch (Exception ex) {
                fail("Poller " + tid + " failed with " + ex);
            }
            assertNotNull("Poller " + tid + ": no response received from service", reply);
            String s = reply.getResponseType();
            assertEquals(expectedString, s);
        }
    }
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateGreeterAddress(greeter, PORT);
    long before = System.currentTimeMillis();
    long delay = 3000;
    Response<GreetMeLaterResponse> response = greeter.greetMeLaterAsync(delay);
    long after = System.currentTimeMillis();
    assertTrue("Duration of calls exceeded " + delay + " ms", after - before < delay);
    // first time round, responses should not be available yet
    assertFalse("Response already available.", response.isDone());
    Poller[] pollers = new Poller[4];
    for (int i = 0; i < pollers.length; i++) {
        pollers[i] = new Poller(response, i);
    }
    for (Poller p : pollers) {
        p.start();
    }
    for (Poller p : pollers) {
        p.join();
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) URL(java.net.URL) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ExecutionException(java.util.concurrent.ExecutionException) GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) Response(javax.xml.ws.Response) Greeter(org.apache.hello_world_soap_http.Greeter) Test(org.junit.Test)

Example 20 with SOAPService

use of org.apache.hello_world_soap_http.SOAPService in project cxf by apache.

the class ClientServerWebSocketTest method testBasicConnectionAndOneway.

@Test
public void testBasicConnectionAndOneway() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateGreeterAddress(greeter, PORT);
    String response1 = new String("Hello Milestone-");
    String response2 = new String("Bonjour");
    try {
        for (int idx = 0; idx < 1; idx++) {
            String greeting = greeter.greetMe("Milestone-" + idx);
            assertNotNull("no response received from service", greeting);
            String exResponse = response1 + idx;
            assertEquals(exResponse, greeting);
            String reply = greeter.sayHi();
            assertNotNull("no response received from service", reply);
            assertEquals(response2, reply);
            greeter.greetMeOneWay("Milestone-" + idx);
        }
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Greeter(org.apache.hello_world_soap_http.Greeter) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) URL(java.net.URL) Test(org.junit.Test)

Aggregations

SOAPService (org.apache.hello_world_soap_http.SOAPService)84 URL (java.net.URL)67 Test (org.junit.Test)56 Greeter (org.apache.hello_world_soap_http.Greeter)49 InputStream (java.io.InputStream)20 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)18 SOAPMessage (javax.xml.soap.SOAPMessage)14 Bus (org.apache.cxf.Bus)14 BindingProvider (javax.xml.ws.BindingProvider)13 Endpoint (javax.xml.ws.Endpoint)13 SOAPServiceBogusAddressTest (org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest)13 SOAPServiceMultiPortTypeTest (org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest)13 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)12 TimeoutException (java.util.concurrent.TimeoutException)8 WebServiceException (javax.xml.ws.WebServiceException)8 File (java.io.File)7 ExecutionException (java.util.concurrent.ExecutionException)7 QName (javax.xml.namespace.QName)7 BeforeClass (org.junit.BeforeClass)7 GreetMeLaterResponse (org.apache.hello_world_soap_http.types.GreetMeLaterResponse)6