Search in sources :

Example 61 with BindingProvider

use of javax.xml.ws.BindingProvider 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 62 with BindingProvider

use of javax.xml.ws.BindingProvider in project cxf by apache.

the class JettyDigestAuthTest method doTest.

private void doTest(boolean async) throws Exception {
    setupClient(async);
    assertEquals("Hello Alice", greeter.greetMe("Alice"));
    assertEquals("Hello Bob", greeter.greetMe("Bob"));
    try {
        BindingProvider bp = (BindingProvider) greeter;
        if (async) {
            UsernamePasswordCredentials creds = new UsernamePasswordCredentials("blah", "foo");
            bp.getRequestContext().put(Credentials.class.getName(), creds);
        } else {
            bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "blah");
            bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "foo");
        }
        greeter.greetMe("Alice");
        fail("Password was wrong, should have failed");
    } catch (WebServiceException wse) {
    // ignore - expected
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) BindingProvider(javax.xml.ws.BindingProvider) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 63 with BindingProvider

use of javax.xml.ws.BindingProvider in project cxf by apache.

the class CertConstraintsTest method testFailedCall.

public final void testFailedCall(String address) throws Exception {
    URL url = SOAPService.WSDL_LOCATION;
    SOAPService service = new SOAPService(url, SOAPService.SERVICE);
    assertNotNull("Service is null", service);
    final Greeter port = service.getHttpsPort();
    assertNotNull("Port is null", port);
    BindingProvider provider = (BindingProvider) port;
    provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
    try {
        assertEquals(port.greetMe("Kitty"), "Hello Kitty");
        fail("Failure expected");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
    // expected
    } catch (javax.xml.ws.WebServiceException ex) {
    // expected
    }
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) Greeter(org.apache.hello_world.Greeter) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL)

Example 64 with BindingProvider

use of javax.xml.ws.BindingProvider in project cxf by apache.

the class DirectDispatchClientTest method invokeService.

private void invokeService(boolean isDirectDispatch) {
    BusFactory.setThreadDefaultBus(staticBus);
    Service service = Service.create(serviceName);
    service.addPort(localPortName, "http://schemas.xmlsoap.org/soap/", "local://Greeter");
    Greeter greeter = service.getPort(localPortName, Greeter.class);
    if (isDirectDispatch) {
        Client client = ClientProxy.getClient(greeter);
        client.getOutInterceptors().add(new GZIPOutInterceptor(50));
        client.getInInterceptors().add(new GZIPInInterceptor());
        InvocationHandler handler = Proxy.getInvocationHandler(greeter);
        BindingProvider bp = null;
        if (handler instanceof BindingProvider) {
            bp = (BindingProvider) handler;
            Map<String, Object> requestContext = bp.getRequestContext();
            requestContext.put(LocalConduit.DIRECT_DISPATCH, true);
        }
    }
    String reply = greeter.greetMe("test");
    assertEquals("Hello test", reply);
    reply = greeter.sayHi();
    assertNotNull("no response received from service", reply);
    assertEquals("Bonjour", reply);
}
Also used : GZIPOutInterceptor(org.apache.cxf.transport.common.gzip.GZIPOutInterceptor) Greeter(org.apache.hello_world_soap_http.Greeter) Service(javax.xml.ws.Service) GZIPInInterceptor(org.apache.cxf.transport.common.gzip.GZIPInInterceptor) BindingProvider(javax.xml.ws.BindingProvider) Client(org.apache.cxf.endpoint.Client) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 65 with BindingProvider

use of javax.xml.ws.BindingProvider in project cxf by apache.

the class BusShutdownTest method doWork.

private void doWork(URL wsdlUrl, String address) {
    SOAPService service = new SOAPService(wsdlUrl);
    assertNotNull(service);
    Greeter greeter = service.getSoapPort();
    // overwrite client address
    InvocationHandler handler = Proxy.getInvocationHandler(greeter);
    BindingProvider bp = (BindingProvider) handler;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
    Client client = ClientProxy.getClient(greeter);
    HTTPConduit c = (HTTPConduit) client.getConduit();
    c.setClient(new HTTPClientPolicy());
    c.getClient().setConnection(ConnectionType.CLOSE);
    // invoke twoway call
    greeter.sayHi();
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Greeter(org.apache.hello_world_soap_http.Greeter) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) BindingProvider(javax.xml.ws.BindingProvider) Client(org.apache.cxf.endpoint.Client) InvocationHandler(java.lang.reflect.InvocationHandler)

Aggregations

BindingProvider (javax.xml.ws.BindingProvider)147 URL (java.net.URL)87 Test (org.junit.Test)74 Service (javax.xml.ws.Service)65 QName (javax.xml.namespace.QName)41 WebServiceException (javax.xml.ws.WebServiceException)24 Greeter (org.apache.hello_world_soap_http.Greeter)23 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)18 Bus (org.apache.cxf.Bus)17 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)15 InvocationHandler (java.lang.reflect.InvocationHandler)14 SOAPService (org.apache.hello_world_soap_http.SOAPService)14 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)12 STSClient (org.apache.cxf.ws.security.trust.STSClient)11 Greeter (org.apache.cxf.greeter_control.Greeter)10 GreeterService (org.apache.cxf.greeter_control.GreeterService)10 SOAPBinding (javax.xml.ws.soap.SOAPBinding)9 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)9 Client (org.apache.cxf.endpoint.Client)9 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)8