Java Code Examples for org.apache.cxf.transports.http.configuration.HTTPClientPolicy#setConnection()

The following examples show how to use org.apache.cxf.transports.http.configuration.HTTPClientPolicy#setConnection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConnectionHelper.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void setKeepAliveConnection(Object proxy, boolean keepAlive, boolean force) {
    if (force || "HP-UX".equals(System.getProperty("os.name"))
        || "Windows XP".equals(System.getProperty("os.name"))) {
        Client client = ClientProxy.getClient(proxy);
        HTTPConduit hc = (HTTPConduit)client.getConduit();
        HTTPClientPolicy cp = hc.getClient();
        cp.setConnection(keepAlive ? ConnectionType.KEEP_ALIVE : ConnectionType.CLOSE);
    }
}
 
Example 2
Source File: ConnectionHelper.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void setKeepAliveConnection(Object proxy, boolean keepAlive, boolean force) {
    if (force || "HP-UX".equals(System.getProperty("os.name"))
        || "Windows XP".equals(System.getProperty("os.name"))) {
        Client client = ClientProxy.getClient(proxy);
        HTTPConduit hc = (HTTPConduit)client.getConduit();
        HTTPClientPolicy cp = hc.getClient();
        cp.setConnection(keepAlive ? ConnectionType.KEEP_ALIVE : ConnectionType.CLOSE);
    }
}
 
Example 3
Source File: BatchEEJAXRS1CxfClient.java    From incubator-batchee with Apache License 2.0 5 votes vote down vote up
private static HTTPClientPolicy defaultClientPolicy() {
    final HTTPClientPolicy client = new HTTPClientPolicy();
    client.setConnection(ConnectionType.CLOSE);
    client.setAllowChunking(false);
    client.setConnectionTimeout(0);
    client.setReceiveTimeout(0);
    return client;
}
 
Example 4
Source File: ClientPolicyCalculator.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a new HTTPClientPolicy that is compatible with the two specified
 * policies or null if no compatible policy can be determined.
 *
 * @param p1 one policy
 * @param p2 another policy
 * @return the compatible policy
 */
public HTTPClientPolicy intersect(HTTPClientPolicy p1, HTTPClientPolicy p2) {

    // incompatibilities

    if (!compatible(p1, p2)) {
        return null;
    }

    // ok - compute compatible policy

    HTTPClientPolicy p = new HTTPClientPolicy();
    p.setAccept(StringUtils.combine(p1.getAccept(), p2.getAccept()));
    p.setAcceptEncoding(StringUtils.combine(p1.getAcceptEncoding(), p2.getAcceptEncoding()));
    p.setAcceptLanguage(StringUtils.combine(p1.getAcceptLanguage(), p2.getAcceptLanguage()));
    if (p1.isSetAllowChunking()) {
        p.setAllowChunking(p1.isAllowChunking());
    } else if (p2.isSetAllowChunking()) {
        p.setAllowChunking(p2.isAllowChunking());
    }
    if (p1.isSetAutoRedirect()) {
        p.setAutoRedirect(p1.isAutoRedirect());
    } else if (p2.isSetAutoRedirect()) {
        p.setAutoRedirect(p2.isAutoRedirect());
    }
    p.setBrowserType(StringUtils.combine(p1.getBrowserType(), p2.getBrowserType()));
    if (p1.isSetCacheControl()) {
        p.setCacheControl(p1.getCacheControl());
    } else if (p2.isSetCacheControl()) {
        p.setCacheControl(p2.getCacheControl());
    }
    if (p1.isSetConnection()) {
        p.setConnection(p1.getConnection());
    } else if (p2.isSetConnection()) {
        p.setConnection(p2.getConnection());
    }
    if (p1.isSetContentType()) {
        p.setContentType(p1.getContentType());
    } else if (p2.isSetContentType()) {
        p.setContentType(p2.getContentType());
    }
    p.setCookie(StringUtils.combine(p1.getCookie(), p2.getCookie()));
    p.setDecoupledEndpoint(StringUtils.combine(p1.getDecoupledEndpoint(), p2.getDecoupledEndpoint()));
    p.setHost(StringUtils.combine(p1.getHost(), p2.getHost()));
    p.setProxyServer(StringUtils.combine(p1.getProxyServer(), p2.getProxyServer()));
    if (p1.isSetProxyServerPort()) {
        p.setProxyServerPort(p1.getProxyServerPort());
    } else if (p2.isSetProxyServerPort()) {
        p.setProxyServerPort(p2.getProxyServerPort());
    }
    if (p1.isSetProxyServerType()) {
        p.setProxyServerType(p1.getProxyServerType());
    } else if (p2.isSetProxyServerType()) {
        p.setProxyServerType(p2.getProxyServerType());
    }
    p.setReferer(StringUtils.combine(p1.getReferer(), p2.getReferer()));
    if (p1.isSetConnectionTimeout()) {
        p.setConnectionTimeout(p1.getConnectionTimeout());
    } else if (p2.isSetConnectionTimeout()) {
        p.setConnectionTimeout(p2.getConnectionTimeout());
    }
    if (p1.isSetConnectionRequestTimeout()) {
        p.setConnectionRequestTimeout(p1.getConnectionRequestTimeout());
    } else if (p2.isSetConnectionRequestTimeout()) {
        p.setConnectionRequestTimeout(p2.getConnectionRequestTimeout());
    }
    if (p1.isSetReceiveTimeout()) {
        p.setReceiveTimeout(p1.getReceiveTimeout());
    } else if (p2.isSetReceiveTimeout()) {
        p.setReceiveTimeout(p2.getReceiveTimeout());
    }

    return p;
}