Search in sources :

Example 1 with AsyncHTTPConduit

use of org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit 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 2 with AsyncHTTPConduit

use of org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit in project cxf by apache.

the class UndertowDigestAuthTest 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();
    client.setConnectionTimeout(600000);
    client.setReceiveTimeout(600000);
    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)

Aggregations

URL (java.net.URL)2 Map (java.util.Map)2 BindingProvider (javax.xml.ws.BindingProvider)2 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)2 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)2 Fault (org.apache.cxf.interceptor.Fault)2 Message (org.apache.cxf.message.Message)2 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)2 AsyncHTTPConduit (org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit)2 DigestAuthSupplier (org.apache.cxf.transport.http.auth.DigestAuthSupplier)2 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)2 Greeter (org.apache.hello_world_soap_http.Greeter)2 SOAPService (org.apache.hello_world_soap_http.SOAPService)2 Credentials (org.apache.http.auth.Credentials)2 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)2