Search in sources :

Example 71 with HTTPClientPolicy

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

the class CECXFClient method configHttpConduit.

private void configHttpConduit(Object port) {
    // 设置客户端的配置信息,超时等.
    Client proxy = ClientProxy.getClient(port);
    HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
    HTTPClientPolicy policy = new HTTPClientPolicy();
    // 连接服务器超时时间
    policy.setConnectionTimeout(this.connectTimeout);
    // 等待服务器响应超时时间
    policy.setReceiveTimeout(this.receiveTimeout);
    conduit.setClient(policy);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client)

Example 72 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
        client.getInInterceptors().add(new GZIPEnforcingInInterceptor());
        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) Client(org.apache.cxf.endpoint.Client)

Example 73 with HTTPClientPolicy

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

the class DefaultHTTPConduitFactoryWrapper method configureHTTPClientPolicy.

private void configureHTTPClientPolicy(HTTPConduit conduit) {
    boolean set = false;
    final Boolean allowChunking = (Boolean) configuration.get(Constants.CXF_CLIENT_ALLOW_CHUNKING);
    set = set || (allowChunking != null);
    final Integer chunkingThreshold = (Integer) configuration.get(Constants.CXF_CLIENT_CHUNKING_THRESHOLD);
    set = set || (chunkingThreshold != null);
    final Long connectionTimeout = (Long) configuration.get(Constants.CXF_CLIENT_CONNECTION_TIMEOUT);
    set = set || (connectionTimeout != null);
    final Long receiveTimeout = (Long) configuration.get(Constants.CXF_CLIENT_RECEIVE_TIMEOUT);
    set = set || (receiveTimeout != null);
    final String connection = (String) configuration.get(Constants.CXF_CLIENT_CONNECTION);
    set = set || (connection != null);
    if (set) {
        HTTPClientPolicy httpClientPolicy = conduit.getClient();
        if (httpClientPolicy == null) {
            httpClientPolicy = new HTTPClientPolicy();
            conduit.setClient(httpClientPolicy);
        }
        if (allowChunking != null) {
            httpClientPolicy.setAllowChunking(allowChunking);
        }
        if (chunkingThreshold != null) {
            httpClientPolicy.setChunkingThreshold(chunkingThreshold);
        }
        if (connectionTimeout != null) {
            httpClientPolicy.setConnectionTimeout(connectionTimeout);
        }
        if (receiveTimeout != null) {
            httpClientPolicy.setReceiveTimeout(receiveTimeout);
        }
        if (connection != null) {
            httpClientPolicy.setConnection(ConnectionType.fromValue(connection));
        }
    }
}
Also used : HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy)

Example 74 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 75 with HTTPClientPolicy

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

the class RestJiraDownloader method setupWebClient.

private WebClient setupWebClient(String jiraUrl) {
    WebClient client = WebClient.create(jiraUrl);
    ClientConfiguration clientConfiguration = WebClient.getConfig(client);
    HTTPConduit http = clientConfiguration.getHttpConduit();
    // MCHANGES-324 - Maintain the client session
    clientConfiguration.getRequestContext().put(Message.MAINTAIN_SESSION, Boolean.TRUE);
    if (getLog().isDebugEnabled()) {
        clientConfiguration.getInInterceptors().add(new LoggingInInterceptor());
        clientConfiguration.getOutInterceptors().add(new LoggingOutInterceptor());
    }
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    // MCHANGES-341 Externalize JIRA server timeout values to the configuration section
    getLog().debug("RestJiraDownloader: connectionTimeout: " + connectionTimeout);
    httpClientPolicy.setConnectionTimeout(connectionTimeout);
    httpClientPolicy.setAllowChunking(false);
    getLog().debug("RestJiraDownloader: receiveTimout: " + receiveTimout);
    httpClientPolicy.setReceiveTimeout(receiveTimout);
    // MCHANGES-334 RestJiraDownloader doesn't honor proxy settings
    getProxyInfo(jiraUrl);
    if (proxyHost != null) {
        getLog().debug("Using proxy: " + proxyHost + " at port " + proxyPort);
        httpClientPolicy.setProxyServer(proxyHost);
        httpClientPolicy.setProxyServerPort(proxyPort);
        httpClientPolicy.setProxyServerType(ProxyServerType.HTTP);
        if (proxyUser != null) {
            ProxyAuthorizationPolicy proxyAuthorizationPolicy = new ProxyAuthorizationPolicy();
            proxyAuthorizationPolicy.setAuthorizationType("Basic");
            proxyAuthorizationPolicy.setUserName(proxyUser);
            proxyAuthorizationPolicy.setPassword(proxyPass);
            http.setProxyAuthorization(proxyAuthorizationPolicy);
        }
    }
    if (webUser != null) {
        AuthorizationPolicy authPolicy = new AuthorizationPolicy();
        authPolicy.setAuthorizationType("Basic");
        authPolicy.setUserName(webUser);
        authPolicy.setPassword(webPassword);
        http.setAuthorization(authPolicy);
    }
    http.setClient(httpClientPolicy);
    return client;
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) ProxyAuthorizationPolicy(org.apache.cxf.configuration.security.ProxyAuthorizationPolicy) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) ProxyAuthorizationPolicy(org.apache.cxf.configuration.security.ProxyAuthorizationPolicy) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) WebClient(org.apache.cxf.jaxrs.client.WebClient) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration)

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