Java 类org.apache.commons.httpclient.params.HttpClientParams 实例源码

项目:alfresco-core    文件:HttpClientFactory.java   
protected HttpClient constructHttpClient()
{
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpClient httpClient = new HttpClient(connectionManager);
    HttpClientParams params = httpClient.getParams();
    params.setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true);
    params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, true);
    if (socketTimeout != null) 
    {
        params.setSoTimeout(socketTimeout);
    }
    HttpConnectionManagerParams connectionManagerParams = httpClient.getHttpConnectionManager().getParams();
    connectionManagerParams.setMaxTotalConnections(maxTotalConnections);
    connectionManagerParams.setDefaultMaxConnectionsPerHost(maxHostConnections);
    connectionManagerParams.setConnectionTimeout(connectionTimeout);

    return httpClient;
}
项目:lams    文件:HTTPMetadataProvider.java   
/**
 * Constructor.
 * 
 * @param metadataURL the URL to fetch the metadata
 * @param requestTimeout the time, in milliseconds, to wait for the metadata server to respond
 * 
 * @throws MetadataProviderException thrown if the URL is not a valid URL or the metadata can not be retrieved from
 *             the URL
 */
@Deprecated
public HTTPMetadataProvider(String metadataURL, int requestTimeout) throws MetadataProviderException {
    super();
    try {
        metadataURI = new URI(metadataURL);
    } catch (URISyntaxException e) {
        throw new MetadataProviderException("Illegal URL syntax", e);
    }

    HttpClientParams clientParams = new HttpClientParams();
    clientParams.setSoTimeout(requestTimeout);
    httpClient = new HttpClient(clientParams);
    httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(requestTimeout);
    authScope = new AuthScope(metadataURI.getHost(), metadataURI.getPort());

}
项目:lib-commons-httpclient    文件:HttpClient.java   
/**
 * Creates an instance of HttpClient using the given 
 * {@link HttpClientParams parameter set}.
 * 
 * @param params The {@link HttpClientParams parameters} to use.
 * 
 * @see HttpClientParams
 * 
 * @since 3.0
 */
public HttpClient(HttpClientParams params) {
    super();
    if (params == null) {
        throw new IllegalArgumentException("Params may not be null");  
    }
    this.params = params;
    this.httpConnectionManager = null;
    Class clazz = params.getConnectionManagerClass();
    if (clazz != null) {
        try {
            this.httpConnectionManager = (HttpConnectionManager) clazz.newInstance();
        } catch (Exception e) {
            LOG.warn("Error instantiating connection manager class, defaulting to"
                + " SimpleHttpConnectionManager", 
                e);
        }
    }
    if (this.httpConnectionManager == null) {
        this.httpConnectionManager = new SimpleHttpConnectionManager();
    }
    if (this.httpConnectionManager != null) {
        this.httpConnectionManager.getParams().setDefaults(this.params);
    }
}
项目:lib-commons-httpclient    文件:TestRedirects.java   
public void testRelativeRedirect() throws IOException {
    String host = this.server.getLocalAddress();
    int port = this.server.getLocalPort();
    this.server.setHttpService(new RelativeRedirectService());
    this.client.getParams().setBooleanParameter(
            HttpClientParams.REJECT_RELATIVE_REDIRECT, false);
    GetMethod httpget = new GetMethod("/oldlocation/");
    httpget.setFollowRedirects(true);
    try {
        this.client.executeMethod(httpget);
        assertEquals("/relativelocation/", httpget.getPath());
        assertEquals(host, httpget.getURI().getHost());
        assertEquals(port, httpget.getURI().getPort());
        assertEquals(new URI("http://" + host + ":" + port + "/relativelocation/", false), 
                httpget.getURI());
    } finally {
        httpget.releaseConnection();
    }
}
项目:lib-commons-httpclient    文件:TestRedirects.java   
public void testRejectRelativeRedirect() throws IOException {
    String host = this.server.getLocalAddress();
    int port = this.server.getLocalPort();
    this.server.setHttpService(new RelativeRedirectService());
    this.client.getParams().setBooleanParameter(
            HttpClientParams.REJECT_RELATIVE_REDIRECT, true);
    GetMethod httpget = new GetMethod("/oldlocation/");
    httpget.setFollowRedirects(true);
    try {
        this.client.executeMethod(httpget);
        assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, httpget.getStatusCode());
        assertEquals("/oldlocation/", httpget.getPath());
        assertEquals(new URI("/oldlocation/", false), httpget.getURI());
    } finally {
        httpget.releaseConnection();
    }
}
项目:cosmic    文件:ClusterServiceServletImpl.java   
private HttpClient getHttpClient() {

        if (s_client == null) {
            final MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
            mgr.getParams().setDefaultMaxConnectionsPerHost(4);

            // TODO make it configurable
            mgr.getParams().setMaxTotalConnections(1000);

            s_client = new HttpClient(mgr);
            final HttpClientParams clientParams = new HttpClientParams();
            clientParams.setSoTimeout(ClusterServiceAdapter.ClusterMessageTimeOut.value() * 1000);

            s_client.setParams(clientParams);
        }
        return s_client;
    }
项目:anyline    文件:HttpUtil.java   
private synchronized void init() {
    client = new HttpClient(new MultiThreadedHttpConnectionManager());
    HttpClientParams params = client.getParams();
    if (encode != null && !encode.trim().equals("")) {
        params.setParameter("http.protocol.content-charset", encode);
        params.setContentCharset(encode);
    }
    if (timeout > 0) {
        params.setSoTimeout(timeout);
    }
    if (null != proxy) {
        HostConfiguration hc = new HostConfiguration();
        hc.setProxy(proxy.getHost(), proxy.getPort());
        client.setHostConfiguration(hc);
        client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxy.getUser(), proxy.getPassword()));
    }
    initialized = true;
}
项目:bsming    文件:HttpClientUtil.java   
/**
 * 
 * @throws Exception .
 */
private void init() throws Exception {
    httpClientManager = new MultiThreadedHttpConnectionManager();

    HttpConnectionManagerParams params = httpClientManager.getParams();
    params.setStaleCheckingEnabled(true);
    params.setMaxTotalConnections(1000);
    params.setDefaultMaxConnectionsPerHost(500);
    params.setConnectionTimeout(2000);
    params.setSoTimeout(3000);

    /** 设置从连接池中获取连接超时。*/
    HttpClientParams clientParams  = new HttpClientParams();
    clientParams.setConnectionManagerTimeout(1000);
    httpClient = new HttpClient(clientParams, httpClientManager);

}
项目:WordsDetection    文件:HttpClient.java   
public HttpClient(int maxConPerHost, int conTimeOutMs, int soTimeOutMs, int maxSize) {
    connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = connectionManager.getParams();
    params.setDefaultMaxConnectionsPerHost(maxConPerHost);
    params.setConnectionTimeout(conTimeOutMs);
    params.setSoTimeout(soTimeOutMs);

    HttpClientParams clientParams = new HttpClientParams();
    // 忽略cookie 避免 Cookie rejected 警告
    clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
    client = new org.apache.commons.httpclient.HttpClient(clientParams, connectionManager);
    Protocol myhttps = new Protocol("https", new MySSLSocketFactory(), 443);
    Protocol.registerProtocol("https", myhttps);
    this.maxSize = maxSize;
    // 支持proxy
    if (proxyHost != null && !proxyHost.equals("")) {
        client.getHostConfiguration().setProxy(proxyHost, proxyPort);
        client.getParams().setAuthenticationPreemptive(true);
        if (proxyAuthUser != null && !proxyAuthUser.equals("")) {
            client.getState().setProxyCredentials(AuthScope.ANY,
                    new UsernamePasswordCredentials(proxyAuthUser, proxyAuthPassword));
            log("Proxy AuthUser: " + proxyAuthUser);
            log("Proxy AuthPassword: " + proxyAuthPassword);
        }
    }
}
项目:superfly    文件:HttpClientFactoryBean.java   
protected void configureHttpClient() throws IOException, GeneralSecurityException {
    httpClient.getParams().setAuthenticationPreemptive(isAuthenticationPreemptive());
    initCredentials();
    initSocketFactory();
    initProtocolIfNeeded();
    if (httpConnectionManager != null) {
        httpClient.setHttpConnectionManager(httpConnectionManager);
    }

    List<Header> headers = getDefaultHeaders();

    httpClient.getHostConfiguration().getParams().setParameter(HostParams.DEFAULT_HEADERS, headers);
    httpClient.getParams().setParameter(HttpClientParams.USER_AGENT,
            "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/11.04 Chromium/18.0.1025.151 Chrome/18.0.1025.151 Safari/535.19");
    httpClient.getParams().setParameter(HttpClientParams.HTTP_CONTENT_CHARSET, "UTF-8");
    httpClient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);

    httpClient.getParams().setConnectionManagerTimeout(connectionManagerTimeout);
    httpClient.getParams().setSoTimeout(soTimeout);
    if (connectionTimeout >= 0) {
        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeout);
    }
}
项目:realtime-analytics    文件:Simulator.java   
private void init() {
    initList(m_ipList, ipFilePath);
    initList(m_uaList, uaFilePath);
    initList(m_itemList, itmFilePath);
    initList(m_tsList,tsFilePath);
    initList(m_siteList,siteFilePath);
    initList(m_dsList,dsFilePath);
    initGUIDList();

    String finalURL = "";
    if (batchMode) {
        finalURL = BATCH_URL;
    } else {
        finalURL = URL;
    }
    m_payload = readFromResource();
    HttpClientParams clientParams = new HttpClientParams();
    clientParams.setSoTimeout(60000);
    m_client = new HttpClient(clientParams);
    m_method = new PostMethod(NODE + finalURL + EVENTTYPE);
    m_method.setRequestHeader("Connection", "Keep-Alive");
    m_method.setRequestHeader("Accept-Charset", "UTF-8");
}
项目:minxing_java_sdk    文件:HttpClient.java   
public HttpClient(int maxConPerHost, int conTimeOutMs, int soTimeOutMs,
            int maxSize) {

//      MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
        SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager(true);
        HttpConnectionManagerParams params = connectionManager.getParams();
        params.setDefaultMaxConnectionsPerHost(maxConPerHost);
        params.setConnectionTimeout(conTimeOutMs);
        params.setSoTimeout(soTimeOutMs);

        HttpClientParams clientParams = new HttpClientParams();
        clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
        client = new org.apache.commons.httpclient.HttpClient(clientParams,
                connectionManager);
        Protocol myhttps = new Protocol("https", new MySSLSocketFactory(), 443);
        Protocol.registerProtocol("https", myhttps);
    }
项目:java-opensaml2    文件:HTTPMetadataProvider.java   
/**
 * Constructor.
 * 
 * @param metadataURL the URL to fetch the metadata
 * @param requestTimeout the time, in milliseconds, to wait for the metadata server to respond
 * 
 * @throws MetadataProviderException thrown if the URL is not a valid URL or the metadata can not be retrieved from
 *             the URL
 */
public HTTPMetadataProvider(String metadataURL, int requestTimeout) throws MetadataProviderException {
    super();
    try {
        metadataURI = new URI(metadataURL);
        maintainExpiredMetadata = true;

        HttpClientParams clientParams = new HttpClientParams();
        clientParams.setSoTimeout(requestTimeout);
        httpClient = new HttpClient(clientParams);
        authScope = new AuthScope(metadataURI.getHost(), metadataURI.getPort());

        // 24 hours
        maxCacheDuration = 60 * 60 * 24;
    } catch (URISyntaxException e) {
        throw new MetadataProviderException("Illegal URL syntax", e);
    }
}
项目:community-edition-old    文件:EmbeddedSolrTest.java   
@Override
public void setUp() throws Exception
{
    KeyStoreParameters keyStoreParameters = new KeyStoreParameters("SSL Key Store", "JCEKS", null, "ssl-keystore-passwords.properties", "ssl.keystore");
    KeyStoreParameters trustStoreParameters = new KeyStoreParameters("SSL Trust Store", "JCEKS", null, "ssl-truststore-passwords.properties", "ssl.truststore");

    SSLEncryptionParameters sslEncryptionParameters = new SSLEncryptionParameters(keyStoreParameters, trustStoreParameters);

    ClasspathKeyResourceLoader keyResourceLoader = new ClasspathKeyResourceLoader();
    HttpClientFactory httpClientFactory = new HttpClientFactory(SecureCommsType.getType("https"), sslEncryptionParameters, keyResourceLoader, null, null, "localhost", 8080,
            8443, 40, 40, 0);

    StringBuilder sb = new StringBuilder();
    sb.append("/solr/admin/cores");
    this.baseUrl = sb.toString();

    httpClient = httpClientFactory.getHttpClient();
    HttpClientParams params = httpClient.getParams();
    params.setBooleanParameter(HttpClientParams.PREEMPTIVE_AUTHENTICATION, true);
    httpClient.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials("admin", "admin"));
}
项目:bitbucket-pullrequest-builder-plugin    文件:ApiClient.java   
public HttpClient getInstanceHttpClient() {
    HttpClient client = new HttpClient();

    HttpClientParams params = client.getParams();
    params.setConnectionManagerTimeout(DEFAULT_TIMEOUT);
    params.setSoTimeout(DEFAULT_TIMEOUT);

    if (Jenkins.getInstance() == null) return client;

    ProxyConfiguration proxy = getInstance().proxy;
    if (proxy == null) return client;

    logger.log(Level.FINE, "Jenkins proxy: {0}:{1}", new Object[]{ proxy.name, proxy.port });
    client.getHostConfiguration().setProxy(proxy.name, proxy.port);
    String username = proxy.getUserName();
    String password = proxy.getPassword();

    // Consider it to be passed if username specified. Sufficient?
    if (username != null && !"".equals(username.trim())) {
        logger.log(Level.FINE, "Using proxy authentication (user={0})", username);
        client.getState().setProxyCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials(username, password));
    }

    return client;
}
项目:jMCS    文件:Http.java   
/**
 * Define client configuration
 * @param httpClient instance to configure
 */
private static void setConfiguration(final HttpClient httpClient) {
    final HttpConnectionManagerParams httpParams = httpClient.getHttpConnectionManager().getParams();
    // define connect timeout:
    httpParams.setConnectionTimeout(NetworkSettings.DEFAULT_CONNECT_TIMEOUT);
    // define read timeout:
    httpParams.setSoTimeout(NetworkSettings.DEFAULT_SOCKET_READ_TIMEOUT);

    // define connection parameters:
    httpParams.setMaxTotalConnections(NetworkSettings.DEFAULT_MAX_TOTAL_CONNECTIONS);
    httpParams.setDefaultMaxConnectionsPerHost(NetworkSettings.DEFAULT_MAX_HOST_CONNECTIONS);

    // set content-encoding to UTF-8 instead of default ISO-8859
    final HttpClientParams httpClientParams = httpClient.getParams();
    // define timeout value for allocation of connections from the pool
    httpClientParams.setConnectionManagerTimeout(NetworkSettings.DEFAULT_CONNECT_TIMEOUT);
    // encoding to UTF-8
    httpClientParams.setParameter(HttpClientParams.HTTP_CONTENT_CHARSET, "UTF-8");
    // avoid retries (3 by default):
    httpClientParams.setParameter(HttpMethodParams.RETRY_HANDLER, _httpNoRetryHandler);

    // Customize the user agent:
    httpClientParams.setParameter(HttpMethodParams.USER_AGENT, System.getProperty(NetworkSettings.PROPERTY_USER_AGENT));
}
项目:cloudstack    文件:ClusterServiceServletImpl.java   
private HttpClient getHttpClient() {

        if (s_client == null) {
            final MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
            mgr.getParams().setDefaultMaxConnectionsPerHost(4);

            // TODO make it configurable
            mgr.getParams().setMaxTotalConnections(1000);

            s_client = new HttpClient(mgr);
            final HttpClientParams clientParams = new HttpClientParams();
            clientParams.setSoTimeout(ClusterServiceAdapter.ClusterMessageTimeOut.value() * 1000);

            s_client.setParams(clientParams);
        }
        return s_client;
    }
项目:cloudstack    文件:BigSwitchApiTest.java   
@Before
public void setUp() {
    HttpClientParams hmp = mock(HttpClientParams.class);
    when(_client.getParams()).thenReturn(hmp);
    _api = new BigSwitchBcfApi(){
        @Override
        protected HttpClient createHttpClient() {
            return _client;
        }

        @Override
        protected HttpMethod createMethod(String type, String uri, int port) {
            return _method;
        }
    };
    _api.setControllerAddress("10.10.0.10");
    _api.setControllerUsername("myname");
    _api.setControllerPassword("mypassword");
}
项目:httpclient3-ntml    文件:HttpClient.java   
/**
 * Creates an instance of HttpClient using the given 
 * {@link HttpClientParams parameter set}.
 * 
 * @param params The {@link HttpClientParams parameters} to use.
 * 
 * @see HttpClientParams
 * 
 * @since 3.0
 */
public HttpClient(HttpClientParams params) {
    super();
    if (params == null) {
        throw new IllegalArgumentException("Params may not be null");  
    }
    this.params = params;
    this.httpConnectionManager = null;
    Class clazz = params.getConnectionManagerClass();
    if (clazz != null) {
        try {
            this.httpConnectionManager = (HttpConnectionManager) clazz.newInstance();
        } catch (Exception e) {
            LOG.warn("Error instantiating connection manager class, defaulting to"
                + " SimpleHttpConnectionManager", 
                e);
        }
    }
    if (this.httpConnectionManager == null) {
        this.httpConnectionManager = new SimpleHttpConnectionManager();
    }
    if (this.httpConnectionManager != null) {
        this.httpConnectionManager.getParams().setDefaults(this.params);
    }
}
项目:httpclient3-ntml    文件:TestRedirects.java   
public void testRelativeRedirect() throws IOException {
    String host = this.server.getLocalAddress();
    int port = this.server.getLocalPort();
    this.server.setHttpService(new RelativeRedirectService());
    this.client.getParams().setBooleanParameter(
            HttpClientParams.REJECT_RELATIVE_REDIRECT, false);
    GetMethod httpget = new GetMethod("/oldlocation/");
    httpget.setFollowRedirects(true);
    try {
        this.client.executeMethod(httpget);
        assertEquals("/relativelocation/", httpget.getPath());
        assertEquals(host, httpget.getURI().getHost());
        assertEquals(port, httpget.getURI().getPort());
        assertEquals(new URI("http://" + host + ":" + port + "/relativelocation/", false), 
                httpget.getURI());
    } finally {
        httpget.releaseConnection();
    }
}
项目:httpclient3-ntml    文件:TestRedirects.java   
public void testRejectRelativeRedirect() throws IOException {
    String host = this.server.getLocalAddress();
    int port = this.server.getLocalPort();
    this.server.setHttpService(new RelativeRedirectService());
    this.client.getParams().setBooleanParameter(
            HttpClientParams.REJECT_RELATIVE_REDIRECT, true);
    GetMethod httpget = new GetMethod("/oldlocation/");
    httpget.setFollowRedirects(true);
    try {
        this.client.executeMethod(httpget);
        assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, httpget.getStatusCode());
        assertEquals("/oldlocation/", httpget.getPath());
        assertEquals(new URI("/oldlocation/", false), httpget.getURI());
    } finally {
        httpget.releaseConnection();
    }
}
项目:kuali_rice    文件:HttpInvokerConnector.java   
protected void initializeHttpClientParams() {
    synchronized (HttpInvokerConnector.class) {
    if (! this.httpClientInitialized) {
        this.httpClientParams = new HttpClientParams();
        configureDefaultHttpClientParams(this.httpClientParams);
        Properties configProps = ConfigContext.getCurrentContextConfig().getProperties();
        for (Iterator<Object> iterator = configProps.keySet().iterator(); iterator.hasNext();) {
            String paramName = (String) iterator.next();
            if (paramName.startsWith("http.")) {
                HttpClientHelper.setParameter(this.httpClientParams, paramName, (String) configProps.get(paramName));
            }
        }
            runIdleConnectionTimeout();
        this.httpClientInitialized = true;
    }
}
}
项目:kuali_rice    文件:HttpInvokerConnector.java   
protected void configureDefaultHttpClientParams(HttpParams params) {
    params.setParameter(HttpClientParams.CONNECTION_MANAGER_CLASS, MultiThreadedHttpConnectionManager.class);
    params.setParameter(HttpMethodParams.COOKIE_POLICY, CookiePolicy.RFC_2109);
    params.setLongParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, 10000);
    Map<HostConfiguration, Integer> maxHostConnectionsMap = new HashMap<HostConfiguration, Integer>();
    maxHostConnectionsMap.put(HostConfiguration.ANY_HOST_CONFIGURATION, new Integer(20));
    params.setParameter(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, maxHostConnectionsMap);
    params.setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 20);
    params.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 10000);
    params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, 2*60*1000);


    boolean retrySocketException = new Boolean(ConfigContext.getCurrentContextConfig().getProperty(RETRY_SOCKET_EXCEPTION_PROPERTY));
    if (retrySocketException) {
        LOG.info("Installing custom HTTP retry handler to retry requests in face of SocketExceptions");
        params.setParameter(HttpMethodParams.RETRY_HANDLER, new CustomHttpMethodRetryHandler());
    }


}
项目:J2EP    文件:ProxyFilter.java   
/**
 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
 * 
 * Called upon initialization, Will create the ConfigParser and get the
 * RuleChain back. Will also configure the httpclient.
 */
public void init(FilterConfig filterConfig) throws ServletException {
    log = LogFactory.getLog(ProxyFilter.class);
    AllowedMethodHandler.setAllowedMethods("OPTIONS,GET,HEAD,POST,PUT,DELETE,TRACE");

    httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    httpClient.getParams().setBooleanParameter(HttpClientParams.USE_EXPECT_CONTINUE, false);
    httpClient.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);

    String data = filterConfig.getInitParameter("dataUrl");
    if (data == null) {
        serverChain = null;
    } else {
        try {
            File dataFile = new File(filterConfig.getServletContext().getRealPath(data));
            ConfigParser parser = new ConfigParser(dataFile);
            serverChain = parser.getServerChain();               
        } catch (Exception e) {
            throw new ServletException(e);
        } 
    }
}
项目:j2ep    文件:ProxyFilter.java   
/**
 * Called upon initialization, Will create the ConfigParser and get the
 * RuleChain back. Will also configure the httpclient.
 * 
 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
 */
public void init(FilterConfig filterConfig) throws ServletException {
    log = LogFactory.getLog(ProxyFilter.class);
    AllowedMethodHandler.setAllowedMethods("OPTIONS,GET,HEAD,POST,PUT,DELETE,TRACE");

    httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    httpClient.getParams().setBooleanParameter(HttpClientParams.USE_EXPECT_CONTINUE, false);
    httpClient.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);

    String data = filterConfig.getInitParameter("dataUrl");
    if (data == null) {
        serverChain = null;
    } else {
        try {
            File dataFile = new File(filterConfig.getServletContext().getRealPath(data));
            ConfigParser parser = new ConfigParser(dataFile);
            serverChain = parser.getServerChain();               
        } catch (Exception e) {
            throw new ServletException(e);
        } 
    }
}
项目:alfresco-repository    文件:SolrAdminHTTPClient.java   
public void init()
{
    ParameterCheck.mandatory("baseUrl", baseUrl);

    StringBuilder sb = new StringBuilder();
    sb.append(baseUrl + "/admin/cores");
    this.adminUrl = sb.toString();

    httpClient = httpClientFactory.getHttpClient();
    HttpClientParams params = httpClient.getParams();
    params.setBooleanParameter(HttpClientParams.PREEMPTIVE_AUTHENTICATION, true);
    httpClient.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials("admin", "admin"));
}
项目:alfresco-repository    文件:BaseWebScriptTest.java   
@Override
protected void setUp() throws Exception
{
    super.setUp();

    if (remoteServer != null)
    {
        httpClient = new HttpClient();
        httpClient.getParams().setBooleanParameter(HttpClientParams.PREEMPTIVE_AUTHENTICATION, true);
        if (remoteServer.username != null)
        {
            httpClient.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(remoteServer.username, remoteServer.password));
        }
    }
}
项目:oscm    文件:ServerStatusChecker.java   
/**
 * Basic constructor sets the listener to notify when
 * servers goes down/up. Also sets the polling time
 * which decides how long we wait between doing checks.
 * 
 * @param listener The listener
 * @param pollingTime The time we wait between checks, in milliseconds
 */
public ServerStatusChecker(ServerStatusListener listener, long pollingTime) {
    this.listener = listener;
    this.pollingTime = Math.max(30*1000, pollingTime);
    setPriority(Thread.NORM_PRIORITY-1);
    setDaemon(true);

    online = new LinkedList();
    offline = new LinkedList();
    httpClient = new HttpClient(); 
    httpClient.getParams().setBooleanParameter(HttpClientParams.USE_EXPECT_CONTINUE, false);
    httpClient.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
}
项目:dlface    文件:DownloadClient.java   
@Override
public void initClient(final ConnectionSettings settings) {
    if (settings == null)
        throw new NullPointerException("Internet connection settings cannot be null");
    this.settings = settings;
    final HttpClientParams clientParams = client.getParams();
    clientParams.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
    clientParams.setParameter(HttpMethodParams.SINGLE_COOKIE_HEADER, true);
    clientParams.setSoTimeout(timeout);
    clientParams.setConnectionManagerTimeout(timeout);
    clientParams.setHttpElementCharset("UTF-8");
    this.client.setHttpConnectionManager(new SimpleHttpConnectionManager(/*true*/));
    this.client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout);

    HttpState initialState = new HttpState();
    HostConfiguration configuration = new HostConfiguration();
    if (settings.getProxyType() == Proxy.Type.SOCKS) { // Proxy stuff happens here

        configuration = new HostConfigurationWithStickyProtocol();

        Proxy proxy = new Proxy(settings.getProxyType(), // create custom Socket factory
                new InetSocketAddress(settings.getProxyURL(), settings.getProxyPort())
        );
        protocol = new Protocol("http", new ProxySocketFactory(proxy), 80);

    } else if (settings.getProxyType() == Proxy.Type.HTTP) { // we use build in HTTP Proxy support          
        configuration.setProxy(settings.getProxyURL(), settings.getProxyPort());
        if (settings.getUserName() != null)
            initialState.setProxyCredentials(AuthScope.ANY, new NTCredentials(settings.getUserName(), settings.getPassword(), "", ""));
    }
    client.setHostConfiguration(configuration);

    clientParams.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);

    client.setState(initialState);
}
项目:Equella    文件:BlackboardConnectorServiceImpl.java   
public Stubs(ConfigurationContext ctx, String bbUrl) throws AxisFault
{
    this.ctx = ctx;
    this.bbUrl = bbUrl;

    /*
     * Must use deprecated class of setting up security because the SOAP
     * response doesn't include a security header. Using the deprecated
     * OutflowConfiguration class we can specify that the security
     * header is only for the outgoing SOAP message.
     */
    ofc = new OutflowConfiguration();
    ofc.setActionItems("UsernameToken Timestamp");
    ofc.setUser("session");
    ofc.setPasswordType("PasswordText");

    final MultiThreadedHttpConnectionManager conMan = new MultiThreadedHttpConnectionManager();
    final HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setMaxTotalConnections(1000);
    params.setDefaultMaxConnectionsPerHost(100);
    params.setSoTimeout(60000);
    params.setConnectionTimeout(30000);
    conMan.setParams(params);

    httpClient = new HttpClient(conMan);
    final HttpClientParams clientParams = httpClient.getParams();
    clientParams.setAuthenticationPreemptive(false);
    clientParams.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
    ctx.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);

    contextWebservice = new ContextWSStub(ctx, PathUtils.filePath(bbUrl, "webapps/ws/services/Context.WS"));
    initStub(contextWebservice);
}
项目:lams    文件:HttpClientBuilder.java   
/**
 * Builds an HTTP client with the given settings. Settings are NOT reset to their default values after a client has
 * been created.
 * 
 * @return the created client.
 */
public HttpClient buildClient() {
    if (httpsProtocolSocketFactory != null) {
        Protocol.registerProtocol("https", new Protocol("https", httpsProtocolSocketFactory, 443));
    }

    HttpClientParams clientParams = new HttpClientParams();
    clientParams.setAuthenticationPreemptive(isPreemptiveAuthentication());
    clientParams.setContentCharset(getContentCharSet());
    clientParams.setParameter(HttpClientParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(
            connectionRetryAttempts, false));

    HttpConnectionManagerParams connMgrParams = new HttpConnectionManagerParams();
    connMgrParams.setConnectionTimeout(getConnectionTimeout());
    connMgrParams.setDefaultMaxConnectionsPerHost(getMaxConnectionsPerHost());
    connMgrParams.setMaxTotalConnections(getMaxTotalConnections());
    connMgrParams.setReceiveBufferSize(getReceiveBufferSize());
    connMgrParams.setSendBufferSize(getSendBufferSize());
    connMgrParams.setTcpNoDelay(isTcpNoDelay());

    MultiThreadedHttpConnectionManager connMgr = new MultiThreadedHttpConnectionManager();
    connMgr.setParams(connMgrParams);

    HttpClient httpClient = new HttpClient(clientParams, connMgr);

    if (proxyHost != null) {
        HostConfiguration hostConfig = new HostConfiguration();
        hostConfig.setProxy(proxyHost, proxyPort);
        httpClient.setHostConfiguration(hostConfig);

        if (proxyUsername != null) {
            AuthScope proxyAuthScope = new AuthScope(proxyHost, proxyPort);
            UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials(proxyUsername,
                    proxyPassword);
            httpClient.getState().setProxyCredentials(proxyAuthScope, proxyCredentials);
        }
    }

    return httpClient;
}
项目:lib-commons-httpclient    文件:ProxyClient.java   
/**
 * Assigns {@link HttpClientParams HTTP protocol parameters} for this ProxyClient.
 * 
 * @see HttpClientParams
 */
public synchronized void setParams(final HttpClientParams params) {
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }
    this.params = params;
}
项目:lib-commons-httpclient    文件:HttpClient.java   
/**
 * Creates an instance of HttpClient with a user specified 
 * {@link HttpClientParams parameter set} and 
 * {@link HttpConnectionManager HTTP connection manager}.
 * 
 * @param params The {@link HttpClientParams parameters} to use.
 * @param httpConnectionManager The {@link HttpConnectionManager connection manager}
 * to use.
 * 
 * @since 3.0
 */
public HttpClient(HttpClientParams params, HttpConnectionManager httpConnectionManager) {
    super();
    if (httpConnectionManager == null) {
        throw new IllegalArgumentException("httpConnectionManager cannot be null");  
    }
    if (params == null) {
        throw new IllegalArgumentException("Params may not be null");  
    }
    this.params = params; 
    this.httpConnectionManager = httpConnectionManager;
    this.httpConnectionManager.getParams().setDefaults(this.params);
}
项目:lib-commons-httpclient    文件:HttpMethodDirector.java   
public HttpMethodDirector(
    final HttpConnectionManager connectionManager,
    final HostConfiguration hostConfiguration,
    final HttpClientParams params,
    final HttpState state
) {
    super();
    this.connectionManager = connectionManager;
    this.hostConfiguration = hostConfiguration;
    this.params = params;
    this.state = state;
    this.authProcessor = new AuthChallengeProcessor(this.params);
}
项目:lib-commons-httpclient    文件:TestRedirects.java   
public void testMaxRedirectCheck() throws IOException {
    this.server.setHttpService(new CircularRedirectService());
    GetMethod httpget = new GetMethod("/circular-oldlocation/");
    try {
        this.client.getParams().setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
        this.client.getParams().setIntParameter(HttpClientParams.MAX_REDIRECTS, 5);
        this.client.executeMethod(httpget);
        fail("RedirectException exception should have been thrown");
    }
    catch (RedirectException e) {
        // expected
    } finally {
        httpget.releaseConnection();
    }
}
项目:lib-commons-httpclient    文件:TestRedirects.java   
public void testCircularRedirect() throws IOException {
    this.server.setHttpService(new CircularRedirectService());
    GetMethod httpget = new GetMethod("/circular-oldlocation/");
    try {
        this.client.getParams().setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, false);
        this.client.executeMethod(httpget);
        fail("CircularRedirectException exception should have been thrown");
    } catch (CircularRedirectException expected) {
    } finally {
        httpget.releaseConnection();
    }
}
项目:ditb    文件:Client.java   
private void initialize(Cluster cluster, boolean sslEnabled) {
  this.cluster = cluster;
  this.sslEnabled = sslEnabled;
  MultiThreadedHttpConnectionManager manager =
    new MultiThreadedHttpConnectionManager();
  HttpConnectionManagerParams managerParams = manager.getParams();
  managerParams.setConnectionTimeout(2000); // 2 s
  managerParams.setDefaultMaxConnectionsPerHost(10);
  managerParams.setMaxTotalConnections(100);
  extraHeaders = new ConcurrentHashMap<String, String>();
  this.httpClient = new HttpClient(manager);
  HttpClientParams clientParams = httpClient.getParams();
  clientParams.setVersion(HttpVersion.HTTP_1_1);

}
项目:watchoverme-server    文件:BaseRestWorker.java   
protected void initHttpClient() {
    if (httpClient == null) {
        httpClient = new HttpClient();
    }
    params = new HttpClientParams();
    myCookie = new Cookie(".secq.me", "mycookie", "stuff",
            "/", null, false);
    initialState = new HttpState();
    initialState.addCookie(myCookie);
    httpClient.setParams(params);
    httpClient.setState(initialState);
    httpClient.getParams().setCookiePolicy(CookiePolicy.RFC_2109);

}
项目:spring-boot-security-saml    文件:SAMLProcessorConfigurer.java   
@VisibleForTesting
protected HTTPArtifactBinding createDefaultArtifactBinding(ServiceProviderBuilder builder) {
    HttpClientParams params = new HttpClientParams();
    params.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 60000);
    HttpClient httpClient = new HttpClient(params, new MultiThreadedHttpConnectionManager());
    ArtifactResolutionProfileImpl artifactResolutionProfile = new ArtifactResolutionProfileImpl(httpClient);
    builder.setSharedObject(ArtifactResolutionProfile.class, artifactResolutionProfile);
    HTTPSOAP11Binding soapBinding = new HTTPSOAP11Binding(parserPool);
    artifactResolutionProfile.setProcessor(new SAMLProcessorImpl(soapBinding));
    return new HTTPArtifactBinding(parserPool, getVelocityEngine(), artifactResolutionProfile);
}
项目:core    文件:TrackerHttpSender.java   
private static void setupHttpClientParams(HttpClient client,
        String userAgent) {
    client.getParams().setBooleanParameter(
            HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
    client.getHttpConnectionManager().getParams()
            .setSoTimeout(SOCKET_TIMEOUT);
    client.getHttpConnectionManager().getParams()
            .setConnectionTimeout(CONNNECT_TIMEOUT);
}