Search in sources :

Example 21 with HTTPClientPolicy

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

the class HTTPSConduitTest method testHttpsTrust.

@Test
public void testHttpsTrust() throws Exception {
    startServer("Bethal");
    URL wsdl = getClass().getResource("greeting.wsdl");
    assertNotNull("WSDL is null", wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull("Service is null", service);
    Greeter bethal = service.getPort(bethalQ, Greeter.class);
    assertNotNull("Port is null", bethal);
    updateAddressPort(bethal, getPort("PORT4"));
    // Okay, I'm sick of configuration files.
    // This also tests dynamic configuration of the conduit.
    Client client = ClientProxy.getClient(bethal);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setAutoRedirect(false);
    // If we set any name, but Edward, Mary, or George,
    // and a password of "password" we will get through
    // Bethal.
    AuthorizationPolicy authPolicy = new AuthorizationPolicy();
    authPolicy.setUserName("Betty");
    authPolicy.setPassword("password");
    http.setClient(httpClientPolicy);
    http.setTlsClientParameters(tlsClientParameters);
    http.setAuthorization(authPolicy);
    // Our expected server should be OU=Bethal
    http.setTrustDecider(new MyHttpsTrustDecider("Bethal"));
    configureProxy(client);
    String answer = bethal.sayHi();
    assertTrue("Unexpected answer: " + answer, "Bonjour from Bethal".equals(answer));
    assertProxyRequestCount(0);
    // Nobody will not equal OU=Bethal
    MyHttpsTrustDecider trustDecider = new MyHttpsTrustDecider("Nobody");
    http.setTrustDecider(trustDecider);
    try {
        answer = bethal.sayHi();
        fail("Unexpected answer from Bethal: " + answer);
    } catch (Exception e) {
    // e.printStackTrace();
    // assertTrue("Trust Decider was not called",
    // 0 > trustDecider.wasCalled());
    }
    assertProxyRequestCount(0);
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Greeter(org.apache.hello_world.Greeter) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client) URL(java.net.URL) GeneralSecurityException(java.security.GeneralSecurityException) UntrustedURLConnectionIOException(org.apache.cxf.transport.http.UntrustedURLConnectionIOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 22 with HTTPClientPolicy

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

the class HTTPSProxyConduitTest 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 23 with HTTPClientPolicy

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

the class CXF6655Test method testConnectionWithProxy.

@Test
public void testConnectionWithProxy() throws Exception {
    QName serviceName = new QName("http://cxf.apache.org/systest/jaxws/", "HelloService");
    HelloService service = new HelloService(null, serviceName);
    assertNotNull(service);
    Hello hello = service.getHelloPort();
    Client client = ClientProxy.getClient(hello);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setAllowChunking(false);
    httpClientPolicy.setReceiveTimeout(0);
    httpClientPolicy.setProxyServerType(ProxyServerType.HTTP);
    httpClientPolicy.setProxyServer("localhost");
    httpClientPolicy.setProxyServerPort(PROXY_PORT);
    http.setClient(httpClientPolicy);
    ((BindingProvider) hello).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT + "/hello");
    assertEquals("getSayHi", hello.sayHi("SayHi"));
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) QName(javax.xml.namespace.QName) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Example 24 with HTTPClientPolicy

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

the class JAXRSAsyncClientTest method testPatchBookTimeout.

@Test
public void testPatchBookTimeout() throws Exception {
    String address = "http://localhost:" + PORT + "/bookstore/patch";
    WebClient wc = WebClient.create(address).type("application/xml");
    ClientConfiguration clientConfig = WebClient.getConfig(wc);
    clientConfig.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, true);
    HTTPClientPolicy clientPolicy = clientConfig.getHttpConduit().getClient();
    clientPolicy.setReceiveTimeout(500);
    clientPolicy.setConnectionTimeout(500);
    try {
        Book book = wc.invoke("PATCH", new Book("Timeout", 123L), Book.class);
        fail("should throw an exception due to timeout, instead got " + book);
    } catch (javax.ws.rs.ProcessingException e) {
    // expected!!!
    }
}
Also used : HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ProcessingException(javax.ws.rs.ProcessingException) WebClient(org.apache.cxf.jaxrs.client.WebClient) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration) Test(org.junit.Test)

Example 25 with HTTPClientPolicy

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

the class InterceptorFaultTest method setupGreeter.

private void setupGreeter(String cfgResource, boolean useDecoupledEndpoint) throws NumberFormatException, MalformedURLException {
    SpringBusFactory bf = new SpringBusFactory();
    controlBus = bf.createBus();
    BusFactory.setDefaultBus(controlBus);
    ControlService cs = new ControlService();
    control = cs.getControlPort();
    updateAddressPort(control, PORT);
    assertTrue("Failed to start greeter", control.startGreeter(cfgResource));
    greeterBus = bf.createBus(cfgResource);
    BusFactory.setDefaultBus(greeterBus);
    LOG.fine("Initialised greeter bus with configuration: " + cfgResource);
    if (null == comparator) {
        comparator = new PhaseComparator();
    }
    if (null == inPhases) {
        inPhases = new ArrayList<>();
        inPhases.addAll(greeterBus.getExtension(PhaseManager.class).getInPhases());
        Collections.sort(inPhases, comparator);
    }
    if (null == postUnMarshalPhase) {
        postUnMarshalPhase = getPhase(Phase.POST_UNMARSHAL);
    }
    GreeterService gs = new GreeterService();
    greeter = gs.getGreeterPort();
    updateAddressPort(greeter, PORT);
    LOG.fine("Created greeter client.");
    if (!useDecoupledEndpoint) {
        return;
    }
    // programatically configure decoupled endpoint that is guaranteed to
    // be unique across all test cases
    decoupledEndpointPort++;
    decoupledEndpoint = "http://localhost:" + allocatePort("decoupled-" + decoupledEndpointPort) + "/decoupled_endpoint";
    Client c = ClientProxy.getClient(greeter);
    HTTPConduit hc = (HTTPConduit) (c.getConduit());
    HTTPClientPolicy cp = hc.getClient();
    cp.setDecoupledEndpoint(decoupledEndpoint);
    LOG.fine("Using decoupled endpoint: " + cp.getDecoupledEndpoint());
}
Also used : PhaseComparator(org.apache.cxf.phase.PhaseComparator) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) ControlService(org.apache.cxf.greeter_control.ControlService) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) GreeterService(org.apache.cxf.greeter_control.GreeterService) 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