Search in sources :

Example 31 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cu-kfs by CU-CommunityApps.

the class PaymentWorksWebServiceCallsServiceImpl method disableRequestChunkingIfNecessary.

private void disableRequestChunkingIfNecessary(Client client, Invocation.Builder requestBuilder) {
    if (client instanceof org.apache.cxf.jaxrs.client.spec.ClientImpl) {
        LOG.info("disableRequestChunkingIfNecessary: Explicitly disabling chunking because KFS is using a JAX-RS client of CXF type " + client.getClass().getName());
        ClientConfiguration cxfConfig = WebClient.getConfig(requestBuilder);
        HTTPConduit conduit = cxfConfig.getHttpConduit();
        HTTPClientPolicy clientPolicy = conduit.getClient();
        clientPolicy.setAllowChunking(false);
    } else {
        LOG.info("disableRequestChunkingIfNecessary: There is no need to explicitly disable chunking for a JAX-RS client of type " + client.getClass().getName());
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration)

Example 32 with HTTPClientPolicy

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

the class Helper method testFailureGZIPServerSideOnlyInterceptorOnClient.

public boolean testFailureGZIPServerSideOnlyInterceptorOnClient() throws Exception {
    HelloWorld port = getPort();
    Client client = ClientProxy.getClient(port);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();
    HTTPClientPolicy policy = conduit.getClient();
    // enable Accept gzip, otherwise the server will not try to reply using gzip
    policy.setAcceptEncoding("gzip;q=1.0, identity; q=0.5, *;q=0");
    try {
        port.echo("foo");
        return false;
    } catch (Exception e) {
        // expected exception, as the client is not able to decode gzip message
        return true;
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client) MalformedURLException(java.net.MalformedURLException)

Example 33 with HTTPClientPolicy

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

the class HTTPConduitTestCase method testWrapperWithMap.

@Test
@RunAsClient
public void testWrapperWithMap() throws Exception {
    Bus bus = BusFactory.newInstance().createBus();
    BusFactory.setThreadDefaultBus(bus);
    try {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(Constants.CXF_CLIENT_ALLOW_CHUNKING, true);
        map.put(Constants.CXF_CLIENT_CHUNKING_THRESHOLD, 8192);
        map.put(Constants.CXF_CLIENT_CONNECTION_TIMEOUT, 16384L);
        map.put(Constants.CXF_CLIENT_RECEIVE_TIMEOUT, 163840L);
        map.put(Constants.CXF_TLS_CLIENT_DISABLE_CN_CHECK, true);
        replaceWrapper(map, bus);
        URL wsdlURL = new URL(baseURL + "/ServiceOne" + "?wsdl");
        Service service = Service.create(wsdlURL, new QName("http://org.jboss.ws.jaxws.cxf/httpConduit", "ServiceOne"));
        EndpointOne port = service.getPort(new QName("http://org.jboss.ws.jaxws.cxf/httpConduit", "EndpointOnePort"), EndpointOne.class);
        HTTPConduit conduit = (HTTPConduit) ClientProxy.getClient(port).getConduit();
        HTTPClientPolicy client = conduit.getClient();
        assertNotNull(client);
        assertEquals(true, client.isAllowChunking());
        assertEquals(8192, client.getChunkingThreshold());
        assertEquals(16384, client.getConnectionTimeout());
        assertEquals(163840, client.getReceiveTimeout());
        assertEquals(true, conduit.getTlsClientParameters().isDisableCNCheck());
        assertEquals("Foo", port.echo("Foo"));
    } finally {
        bus.shutdown(true);
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Service(javax.xml.ws.Service) URL(java.net.URL) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 34 with HTTPClientPolicy

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

the class HTTPProxyTestCaseForked method testHttpProxyUsingHTTPClientPolicy.

@Test
@RunAsClient
public void testHttpProxyUsingHTTPClientPolicy() throws Exception {
    if (checkNativeLibraries()) {
        initProxyServer();
    } else {
        return;
    }
    final String testHost = "unreachable-testHttpProxyUsingHTTPClientPolicy";
    HelloWorld port = getPort(getResourceURL("jaxws/cxf/httpproxy/HelloWorldService.wsdl"), testHost);
    final String hi = "Hi!";
    // first try without setting up the proxy -> request fails because the host is not known/reachable
    try {
        port.echo(hi);
        fail("Exception expected");
    } catch (Exception e) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        e.printStackTrace(new PrintStream(baos));
        assertTrue(baos.toString().contains(testHost));
    }
    // then setup the proxy, but provide no authentication/authorization info -> request fails because of HTTP 407
    Client client = ClientProxy.getClient(port);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();
    HTTPClientPolicy clientPolicy = conduit.getClient();
    clientPolicy.setProxyServerType(ProxyServerType.HTTP);
    clientPolicy.setProxyServer(getServerHost());
    clientPolicy.setProxyServerPort(proxyPort);
    try {
        port.echo(hi);
        fail("Exception expected");
    } catch (Exception e) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        e.printStackTrace(new PrintStream(baos));
        assertTrue(baos.toString().contains("407: Proxy Authentication Required"));
    }
    // finally setup authorization info too
    ProxyAuthorizationPolicy authPolicy = new ProxyAuthorizationPolicy();
    authPolicy.setAuthorizationType("Basic");
    authPolicy.setUserName(PROXY_USER);
    authPolicy.setPassword(PROXY_PWD);
    conduit.setProxyAuthorization(authPolicy);
    assertEquals(hi, port.echo(hi));
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) PrintStream(java.io.PrintStream) ProxyAuthorizationPolicy(org.apache.cxf.configuration.security.ProxyAuthorizationPolicy) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Client(org.apache.cxf.endpoint.Client) MalformedURLException(java.net.MalformedURLException) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 35 with HTTPClientPolicy

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

the class Helper method testGZIPServerSideOnlyInterceptorOnClient.

public boolean testGZIPServerSideOnlyInterceptorOnClient() throws Exception {
    Bus bus = BusFactory.newInstance().createBus();
    try {
        BusFactory.setThreadDefaultBus(bus);
        HelloWorld port = getPort();
        Client client = ClientProxy.getClient(port);
        HTTPConduit conduit = (HTTPConduit) client.getConduit();
        HTTPClientPolicy policy = conduit.getClient();
        // enable Accept gzip, otherwise the server will not try to reply using gzip
        policy.setAcceptEncoding("gzip;q=1.0, identity; q=0.5, *;q=0");
        // add interceptor for decoding gzip message
        ClientConfigurer configurer = ClientConfigUtil.resolveClientConfigurer();
        configurer.setConfigProperties(port, "jaxws-client-config.xml", "Interceptor Client Config");
        return ("foo".equals(port.echo("foo")));
    } finally {
        bus.shutdown(true);
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Bus(org.apache.cxf.Bus) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ClientConfigurer(org.jboss.ws.api.configuration.ClientConfigurer) 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