Search in sources :

Example 11 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.

the class HTTPConduit method getClient.

public HTTPClientPolicy getClient(Message message) {
    ClientPolicyCalculator cpc = new ClientPolicyCalculator();
    HTTPClientPolicy pol = message.get(HTTPClientPolicy.class);
    updateClientPolicy(message);
    if (pol != null) {
        pol = cpc.intersect(pol, clientSidePolicy);
    } else {
        pol = clientSidePolicy;
    }
    PolicyDataEngine policyDataEngine = bus.getExtension(PolicyDataEngine.class);
    if (policyDataEngine == null) {
        return pol;
    }
    return policyDataEngine.getPolicy(message, pol, cpc);
}
Also used : HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) PolicyDataEngine(org.apache.cxf.policy.PolicyDataEngine) ClientPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator)

Example 12 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.

the class HTTPProxyAuthConduitTest method configureProxy.

public void configureProxy(Client client) {
    HTTPConduit cond = (HTTPConduit) client.getConduit();
    HTTPClientPolicy pol = cond.getClient();
    if (pol == null) {
        pol = new HTTPClientPolicy();
        cond.setClient(pol);
    }
    pol.setProxyServer("localhost");
    pol.setProxyServerPort(PROXY_PORT);
    ProxyAuthorizationPolicy auth = new ProxyAuthorizationPolicy();
    auth.setUserName("CXF");
    auth.setPassword("password");
    cond.setProxyAuthorization(auth);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) ProxyAuthorizationPolicy(org.apache.cxf.configuration.security.ProxyAuthorizationPolicy) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy)

Example 13 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy 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 14 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.

the class HTTPProxyConduitTest method configureProxy.

public void configureProxy(Client client) {
    HTTPConduit cond = (HTTPConduit) client.getConduit();
    HTTPClientPolicy pol = cond.getClient();
    if (pol == null) {
        pol = new HTTPClientPolicy();
        cond.setClient(pol);
    }
    pol.setProxyServer("localhost");
    pol.setProxyServerPort(PROXY_PORT);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy)

Example 15 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.

the class SignatureWhitespaceTest method testTrailingWhitespaceInSOAPBody.

@org.junit.Test
public void testTrailingWhitespaceInSOAPBody() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SignatureWhitespaceTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = SignatureWhitespaceTest.class.getResource("DoubleItAction.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSignaturePort2");
    Dispatch<StreamSource> dispatch = service.createDispatch(portQName, StreamSource.class, Service.Mode.MESSAGE);
    Client client = ((DispatchImpl<StreamSource>) dispatch).getClient();
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(0);
    httpClientPolicy.setReceiveTimeout(0);
    http.setClient(httpClientPolicy);
    // Creating a DOMSource Object for the request
    URL requestFile = SignatureWhitespaceTest.class.getResource("request-with-trailing-whitespace.xml");
    StreamSource request = new StreamSource(new File(requestFile.getPath()));
    updateAddressPort(dispatch, test.getPort());
    // Make a successful request
    StreamSource response = dispatch.invoke(request);
    assertNotNull(response);
    Document doc = StaxUtils.read(response.getInputStream());
    assertEquals("50", doc.getElementsByTagNameNS(null, "doubledNumber").item(0).getTextContent());
    ((java.io.Closeable) dispatch).close();
}
Also used : Bus(org.apache.cxf.Bus) QName(javax.xml.namespace.QName) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) StreamSource(javax.xml.transform.stream.StreamSource) Service(javax.xml.ws.Service) Document(org.w3c.dom.Document) URL(java.net.URL) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client) File(java.io.File)

Aggregations

HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)78 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)53 Client (org.apache.cxf.endpoint.Client)31 Test (org.junit.Test)27 URL (java.net.URL)12 Bus (org.apache.cxf.Bus)10 IOException (java.io.IOException)8 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)8 WebClient (org.apache.cxf.jaxrs.client.WebClient)7 ClientPolicyCalculator (org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator)7 QName (javax.xml.namespace.QName)6 ProxyAuthorizationPolicy (org.apache.cxf.configuration.security.ProxyAuthorizationPolicy)6 ClientConfiguration (org.apache.cxf.jaxrs.client.ClientConfiguration)6 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)5 Greeter (org.apache.hello_world.Greeter)5 SOAPService (org.apache.hello_world.services.SOAPService)5 Map (java.util.Map)4 BindingProvider (javax.xml.ws.BindingProvider)4 Endpoint (org.apache.cxf.endpoint.Endpoint)4 HashMap (java.util.HashMap)3