Search in sources :

Example 16 with HTTPClientPolicy

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

the class HttpConduitConfigurationTest method verifyConduit.

private void verifyConduit(HTTPConduit conduit) {
    AuthorizationPolicy authp = conduit.getAuthorization();
    assertNotNull(authp);
    assertEquals("Betty", authp.getUserName());
    assertEquals("password", authp.getPassword());
    TLSClientParameters tlscps = conduit.getTlsClientParameters();
    assertNotNull(tlscps);
    assertTrue(tlscps.isDisableCNCheck());
    assertEquals(3600000, tlscps.getSslCacheTimeout());
    KeyManager[] kms = tlscps.getKeyManagers();
    assertTrue(kms != null && kms.length == 1);
    assertTrue(kms[0] instanceof X509KeyManager);
    TrustManager[] tms = tlscps.getTrustManagers();
    assertTrue(tms != null && tms.length == 1);
    assertTrue(tms[0] instanceof X509TrustManager);
    FiltersType csfs = tlscps.getCipherSuitesFilter();
    assertNotNull(csfs);
    assertEquals(1, csfs.getInclude().size());
    assertEquals(1, csfs.getExclude().size());
    HTTPClientPolicy clientPolicy = conduit.getClient();
    assertEquals(10240, clientPolicy.getChunkLength());
}
Also used : AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) X509TrustManager(javax.net.ssl.X509TrustManager) X509KeyManager(javax.net.ssl.X509KeyManager) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) FiltersType(org.apache.cxf.configuration.security.FiltersType) X509KeyManager(javax.net.ssl.X509KeyManager) KeyManager(javax.net.ssl.KeyManager) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager)

Example 17 with HTTPClientPolicy

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

the class ClientPolicyCalculatorTest method testCompatibleClientPolicies.

@Test
public void testCompatibleClientPolicies() {
    ClientPolicyCalculator calc = new ClientPolicyCalculator();
    HTTPClientPolicy p1 = new HTTPClientPolicy();
    assertTrue("Policy is not compatible with itself.", calc.compatible(p1, p1));
    HTTPClientPolicy p2 = new HTTPClientPolicy();
    assertTrue("Policies are not compatible.", calc.compatible(p1, p2));
    p1.setBrowserType("browser");
    assertTrue("Policies are not compatible.", calc.compatible(p1, p2));
    p1.setBrowserType(null);
    p1.setConnectionTimeout(10000);
    assertTrue("Policies are not compatible.", calc.compatible(p1, p2));
    p1.setAllowChunking(false);
    p2.setAllowChunking(true);
    assertFalse("Policies are compatible.", calc.compatible(p1, p2));
    p2.setAllowChunking(false);
    assertTrue("Policies are compatible.", calc.compatible(p1, p2));
}
Also used : HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ClientPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator) Test(org.junit.Test)

Example 18 with HTTPClientPolicy

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

the class ClientPolicyCalculatorTest method testLongTimeouts.

@Test
public void testLongTimeouts() {
    ClientPolicyCalculator calc = new ClientPolicyCalculator();
    HTTPClientPolicy p1 = new HTTPClientPolicy();
    HTTPClientPolicy p2 = new HTTPClientPolicy();
    p2.setReceiveTimeout(120000);
    p2.setConnectionTimeout(60000);
    HTTPClientPolicy p = calc.intersect(p1, p2);
    assertEquals(120000, p.getReceiveTimeout());
    assertEquals(60000, p.getConnectionTimeout());
    p1 = new HTTPClientPolicy();
    p2 = new HTTPClientPolicy();
    p1.setReceiveTimeout(120000);
    p1.setConnectionTimeout(60000);
    p = calc.intersect(p1, p2);
    assertEquals(120000, p.getReceiveTimeout());
    assertEquals(60000, p.getConnectionTimeout());
    p2.setReceiveTimeout(50000);
    p2.setConnectionTimeout(20000);
    p = calc.intersect(p1, p2);
    // p1 should have priority
    assertEquals(120000, p.getReceiveTimeout());
    assertEquals(60000, p.getConnectionTimeout());
    // reverse intersect
    p = calc.intersect(p2, p1);
    // p2 should have priority
    assertEquals(50000, p.getReceiveTimeout());
    assertEquals(20000, p.getConnectionTimeout());
}
Also used : HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ClientPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator) Test(org.junit.Test)

Example 19 with HTTPClientPolicy

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

the class HTTPSConduitTest method testHttpsRedirectToHttpFail.

@Test
public void testHttpsRedirectToHttpFail() throws Exception {
    startServer("Mortimer");
    startServer("Poltim");
    URL wsdl = getClass().getResource("greeting.wsdl");
    assertNotNull("WSDL is null", wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull("Service is null", service);
    Greeter poltim = service.getPort(poltimQ, Greeter.class);
    assertNotNull("Port is null", poltim);
    updateAddressPort(poltim, getPort("PORT2"));
    // Okay, I'm sick of configuration files.
    // This also tests dynamic configuration of the conduit.
    Client client = ClientProxy.getClient(poltim);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setAutoRedirect(true);
    http.setClient(httpClientPolicy);
    http.setTlsClientParameters(tlsClientParameters);
    configureProxy(client);
    poltim.sayHi();
    // client -> poltim is https and thus not recorded but then redirected to mortimer
    // client -> mortimer is http and recoreded
    assertProxyRequestCount(1);
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Greeter(org.apache.hello_world.Greeter) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client) URL(java.net.URL) Test(org.junit.Test)

Example 20 with HTTPClientPolicy

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

the class HTTPSConduitTest method verifyBethalClient.

// we just verify the configurations are loaded successfully
private void verifyBethalClient(Greeter bethal) {
    Client client = ClientProxy.getClient(bethal);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = http.getClient();
    assertTrue("the httpClientPolicy's autoRedirect should be true", httpClientPolicy.isAutoRedirect());
    TLSClientParameters tlsParameters = http.getTlsClientParameters();
    assertNotNull("the http conduit's tlsParameters should not be null", tlsParameters);
    // If we set any name, but Edward, Mary, or George,
    // and a password of "password" we will get through
    // Bethal.
    AuthorizationPolicy authPolicy = http.getAuthorization();
    assertEquals("Set the wrong user name from the configuration", "Betty", authPolicy.getUserName());
    assertEquals("Set the wrong pass word form the configuration", "password", authPolicy.getPassword());
    configureProxy(ClientProxy.getClient(bethal));
    String answer = bethal.sayHi();
    answer = bethal.sayHi();
    answer = bethal.sayHi();
    answer = bethal.sayHi();
    answer = bethal.sayHi();
    assertTrue("Unexpected answer: " + answer, "Bonjour from Bethal".equals(answer));
    // With HTTPS, it will just be a CONNECT to the proxy and all the
    // data is encrypted.  Thus, the proxy cannot distinquish the requests
    assertProxyRequestCount(0);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client)

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