当前位置: 首页>>代码示例>>Java>>正文


Java HostConfiguration.setHost方法代码示例

本文整理汇总了Java中org.apache.commons.httpclient.HostConfiguration.setHost方法的典型用法代码示例。如果您正苦于以下问题:Java HostConfiguration.setHost方法的具体用法?Java HostConfiguration.setHost怎么用?Java HostConfiguration.setHost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.httpclient.HostConfiguration的用法示例。


在下文中一共展示了HostConfiguration.setHost方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDefaults

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
public void testDefaults() throws IOException {
    this.server.setHttpService(new SimpleService());

    this.client.getParams().setParameter(HttpMethodParams.USER_AGENT, "test");
    HostConfiguration hostconfig = new HostConfiguration();
    hostconfig.setHost(
            this.server.getLocalAddress(), 
            this.server.getLocalPort(),
            Protocol.getProtocol("http"));
    
    GetMethod httpget = new GetMethod("/miss/");
    try {
        this.client.executeMethod(hostconfig, httpget);
    } finally {
        httpget.releaseConnection();
    }
    assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
    assertEquals("test", httpget.getRequestHeader("User-Agent").getValue());
    assertEquals("test", httpget.getParams().
            getParameter(HttpMethodParams.USER_AGENT));
    assertEquals("test", hostconfig.getParams().
            getParameter(HttpMethodParams.USER_AGENT));
    assertEquals("test", client.getParams().
            getParameter(HttpMethodParams.USER_AGENT));
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:26,代码来源:TestHttpParams.java

示例2: initHttpClient

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
protected void initHttpClient() {
    if (MockServer.isTestMode()) {
        return;
    }
    HostConfiguration hostConfiguration = new HostConfiguration();
    hostConfiguration.setHost(diamondConfigure.getDomainNameList().get(this.domainNamePos.get()),
        diamondConfigure.getPort());

    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.closeIdleConnections(diamondConfigure.getPollingIntervalTime() * 4000);

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled());
    params.setMaxConnectionsPerHost(hostConfiguration, diamondConfigure.getMaxHostConnections());
    params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections());
    params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
    // 设置读超时为1分钟,
    // [email protected]
    params.setSoTimeout(60 * 1000);

    connectionManager.setParams(params);
    httpClient = new HttpClient(connectionManager);
    httpClient.setHostConfiguration(hostConfiguration);
}
 
开发者ID:lysu,项目名称:diamond,代码行数:25,代码来源:DefaultDiamondSubscriber.java

示例3: HTTPNotificationStrategy

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
public HTTPNotificationStrategy(PushNotificationConfig config) {
    this.config = config;
    if (this.config == null) {
        throw new InvalidConfigurationException("Properties Cannot be found");
    }
    endpoint = config.getProperties().get(URL_PROPERTY);
    if (endpoint == null || endpoint.isEmpty()) {
        throw new InvalidConfigurationException("Property - 'url' cannot be found");
    }
    try {
        this.uri = endpoint;
        URL url = new URL(endpoint);
        hostConfiguration = new HostConfiguration();
        hostConfiguration.setHost(url.getHost(), url.getPort(), url.getProtocol());
        this.authorizationHeaderValue = config.getProperties().get(AUTHORIZATION_HEADER_PROPERTY);
        executorService = Executors.newFixedThreadPool(1);
        httpClient = new HttpClient();
    } catch (MalformedURLException e) {
        throw new InvalidConfigurationException("Property - 'url' is malformed.", e);
    }
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:22,代码来源:HTTPNotificationStrategy.java

示例4: getHostConfig

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
/**
 * @param target TransferTarget
 * @return HostConfiguration
 */
private HostConfiguration getHostConfig(TransferTarget target)
{
    String requiredProtocol = target.getEndpointProtocol();
    if (requiredProtocol == null)
    {
        throw new TransferException(MSG_UNSUPPORTED_PROTOCOL, new Object[] {target.getEndpointProtocol()});
    }

    Protocol protocol = protocolMap.get(requiredProtocol.toLowerCase().trim());
    if (protocol == null) {
        log.error("Unsupported protocol: " + target.getEndpointProtocol());
        throw new TransferException(MSG_UNSUPPORTED_PROTOCOL, new Object[] {target.getEndpointProtocol()});
    }

    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost(target.getEndpointHost(), target.getEndpointPort(), protocol);
    return hostConfig;
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:23,代码来源:HttpClientTransmitterImpl.java

示例5: connectHTTP

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
/**
 *
 * Public Section
 *
 */
public void connectHTTP(String strUser, String strPass, String strHost, boolean insecure) {
    //Connect WebDAV with credentials
    hostConfig = new HostConfiguration();
    hostConfig.setHost(strHost);
    connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManagerParams = new HttpConnectionManagerParams();
    connectionManagerParams.setMaxConnectionsPerHost(hostConfig, this.intMaxConnections);
    connectionManager.setParams(connectionManagerParams);
    client = new HttpClient(connectionManager);
    creds = new UsernamePasswordCredentials(strUser, strPass);
    client.getState().setCredentials(AuthScope.ANY, creds);
    client.setHostConfiguration(hostConfig);

    if (insecure) {
        Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
        Protocol.registerProtocol("https", easyhttps);
    }

    Status.print("WebDav Connection generated");
}
 
开发者ID:somedevelopment,项目名称:CardDAVSyncOutlook,代码行数:26,代码来源:ManageWebDAVContacts.java

示例6: hostConfig

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
@Test
public void hostConfig() throws Exception {
    HttpClient client = new HttpClient();
    client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT);
    client.getParams().setSoTimeout(SO_TIMEOUT);

    HostConfiguration config = new HostConfiguration();
    config.setHost("weather.naver.com", 80, "http");
    GetMethod method = new GetMethod("/rgn/cityWetrMain.nhn");

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
    method.setQueryString(new NameValuePair[] { new NameValuePair("key2", "value2") });

    try {
        // Execute the method.
        client.executeMethod(config, method);
    } catch (Exception ignored) {
    } finally {
        method.releaseConnection();
    }

    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
}
 
开发者ID:naver,项目名称:pinpoint,代码行数:26,代码来源:HttpClientIT.java

示例7: handleCertificateExceptionAndRetry

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
@Nullable
private static HttpMethod handleCertificateExceptionAndRetry(@NotNull IOException e, @NotNull String host,
                                                             @NotNull HttpClient client, @NotNull URI uri,
                                                             @NotNull ThrowableConvertor<String, HttpMethod, IOException> methodCreator)
                                                             throws IOException {
  if (!isCertificateException(e)) {
    throw e;
  }

  if (isTrusted(host)) {
    // creating a special configuration that allows connections to non-trusted HTTPS hosts
    // see the javadoc to EasySSLProtocolSocketFactory for details
    Protocol easyHttps = new Protocol("https", (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443);
    HostConfiguration hc = new HostConfiguration();
    hc.setHost(host, 443, easyHttps);
    String relativeUri = new URI(uri.getPathQuery(), false).getURI();
    // it is important to use relative URI here, otherwise our custom protocol won't work.
    // we have to recreate the method, because HttpMethod#setUri won't overwrite the host,
    // and changing host by hands (HttpMethodBase#setHostConfiguration) is deprecated.
    HttpMethod method = methodCreator.convert(relativeUri);
    client.executeMethod(hc, method);
    return method;
  }
  throw e;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:26,代码来源:GithubSslSupport.java

示例8: initHttpClient

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
protected void initHttpClient() {
	if (MockServer.isTestMode()) {
		return;
	}
	HostConfiguration hostConfiguration = new HostConfiguration();
	hostConfiguration.setHost(
			diamondConfigure.getDomainNameList().get(
					this.domainNamePos.get()), diamondConfigure.getPort());

	MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
	connectionManager.closeIdleConnections(diamondConfigure
			.getPollingIntervalTime() * 4000);

	HttpConnectionManagerParams params = new HttpConnectionManagerParams();
	params.setStaleCheckingEnabled(diamondConfigure
			.isConnectionStaleCheckingEnabled());
	params.setMaxConnectionsPerHost(hostConfiguration,
			diamondConfigure.getMaxHostConnections());
	params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections());
	params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
	// ���ö���ʱΪ1����,
	// [email protected]
	params.setSoTimeout(60 * 1000);

	connectionManager.setParams(params);
	httpClient = new HttpClient(connectionManager);
	httpClient.setHostConfiguration(hostConfiguration);
}
 
开发者ID:weijiahao001,项目名称:tb_diamond,代码行数:29,代码来源:DefaultDiamondSubscriber.java

示例9: getHostConfig

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
/**
 * @param target TransferTarget
 * @return HostConfiguration
 */
private HostConfiguration getHostConfig(TransferTarget target)
{
    String requiredProtocol = target.getEndpointProtocol();
    if (requiredProtocol == null)
    {
        throw new TransferException(MSG_UNSUPPORTED_PROTOCOL, new Object[] {requiredProtocol});
    }

    Protocol protocol = protocolMap.get(requiredProtocol.toLowerCase().trim());
    if (protocol == null) 
    {
        log.error("Unsupported protocol: " + target.getEndpointProtocol());
        throw new TransferException(MSG_UNSUPPORTED_PROTOCOL, new Object[] {requiredProtocol});
    }

    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost(target.getEndpointHost(), target.getEndpointPort(), protocol);
    
    // Use the appropriate Proxy Host if required
    if (httpProxyHost != null && HTTP_SCHEME_NAME.equals(protocol.getScheme()) && HttpClientHelper.requiresProxy(target.getEndpointHost()))
    {
        hostConfig.setProxyHost(httpProxyHost);

        if (log.isDebugEnabled())
        {
            log.debug("Using HTTP proxy host for: " + target.getEndpointHost());
        }
    }
    else if (httpsProxyHost != null && HTTPS_SCHEME_NAME.equals(protocol.getScheme()) && HttpClientHelper.requiresProxy(target.getEndpointHost()))
    {
        hostConfig.setProxyHost(httpsProxyHost);

        if (log.isDebugEnabled())
        {
            log.debug("Using HTTPS proxy host for: " + target.getEndpointHost());
        }
    } 
    return hostConfig;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:44,代码来源:HttpClientTransmitterImpl.java

示例10: BitlyUrlShortenerImpl

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
public BitlyUrlShortenerImpl()
{
    httpClient = new HttpClient();
    httpClient.setHttpConnectionManager(new MultiThreadedHttpConnectionManager());
    HostConfiguration hostConfiguration = new HostConfiguration();
    hostConfiguration.setHost("api-ssl.bitly.com", 443, Protocol.getProtocol("https"));
    httpClient.setHostConfiguration(hostConfiguration);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:9,代码来源:BitlyUrlShortenerImpl.java

示例11: testDefaultHeaders

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
public void testDefaultHeaders() throws IOException {
    this.server.setHttpService(new SimpleService());

    ArrayList defaults = new ArrayList();
    defaults.add(new Header("this-header", "value1"));
    defaults.add(new Header("that-header", "value1"));
    defaults.add(new Header("that-header", "value2"));
    defaults.add(new Header("User-Agent", "test"));

    HostConfiguration hostconfig = new HostConfiguration();
    hostconfig.setHost(
            this.server.getLocalAddress(), 
            this.server.getLocalPort(),
            Protocol.getProtocol("http"));
    hostconfig.getParams().setParameter(HostParams.DEFAULT_HEADERS, defaults);
    
    GetMethod httpget = new GetMethod("/miss/");
    try {
        this.client.executeMethod(hostconfig, httpget);
    } finally {
        httpget.releaseConnection();
    }
    assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
    Header[] thisheader = httpget.getRequestHeaders("this-header");
    assertEquals(1, thisheader.length);
    Header[] thatheader = httpget.getRequestHeaders("that-header");
    assertEquals(2, thatheader.length);
    assertEquals("test", httpget.getRequestHeader("User-Agent").getValue());
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:30,代码来源:TestHttpParams.java

示例12: Confluence

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
protected Confluence(String endpoint, ConfluenceProxy proxyInfo ) throws URISyntaxException, MalformedURLException {
       this(new XmlRpcClient());
if (endpoint.endsWith("/")) {
           endpoint = endpoint.substring(0, endpoint.length() - 1);
       }

       endpoint = ConfluenceService.Protocol.XMLRPC.addTo(endpoint);
   
       final java.net.URI serviceURI = new java.net.URI(endpoint);

       XmlRpcClientConfigImpl clientConfig = new XmlRpcClientConfigImpl();
       clientConfig.setServerURL(serviceURI.toURL() );

       clientConfig.setEnabledForExtensions(true); // add this to support attachment upload

       client.setConfig( clientConfig );

       if( isProxyEnabled(proxyInfo, serviceURI) ) {
           
           final XmlRpcCommonsTransportFactory transportFactory = new XmlRpcCommonsTransportFactory( client );

           final HttpClient httpClient = new HttpClient();
           final HostConfiguration hostConfiguration = httpClient.getHostConfiguration();
           hostConfiguration.setProxy( proxyInfo.host, proxyInfo.port );
           hostConfiguration.setHost(serviceURI.getHost(), serviceURI.getPort(), serviceURI.toURL().getProtocol());

           if( !isNullOrEmpty(proxyInfo.userName) && !isNullOrEmpty(proxyInfo.password) ) {
               Credentials cred = new UsernamePasswordCredentials(proxyInfo.userName,proxyInfo.password);
               httpClient.getState().setProxyCredentials(AuthScope.ANY, cred);
           }

           transportFactory.setHttpClient( httpClient );
           client.setTransportFactory( transportFactory );
       }
   }
 
开发者ID:bsorrentino,项目名称:maven-confluence-plugin,代码行数:36,代码来源:Confluence.java

示例13: postNew

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
/**
 * 
 * @param httpUrl
 * @return
 * @throws Exception .
 */
public PostMethod postNew(HttpUrl httpUrl) throws Exception {
    if (httpUrl == null)
        return null;

    HostConfiguration config = new HostConfiguration();
    config.setHost(httpUrl.getHost(), httpUrl.getPort());

    PostMethod post = new PostMethod(httpUrl.getPath());

    post.setRequestHeader("User-Agent", "SOHUSnsBot");
    String encoding = httpUrl.getEncoding();
    if (encoding != null) {
        post.getParams().setContentCharset(encoding);
        
    }

    StringRequestEntity requestEntity = new StringRequestEntity(httpUrl.getRequetsBody(), httpUrl.getContentType(),
            encoding);
    post.setRequestEntity(requestEntity);

    int result = httpClient.executeMethod(config, post);

    if (log.isDebugEnabled()) {
        log.debug("HttpClient.executeMethod returns result = [" + result + "]");
    }
    if (result != 200)
        throw new Exception("wrong HttpClient.executeMethod post method !");

    return post;
}
 
开发者ID:magenm,项目名称:bsming,代码行数:37,代码来源:HttpClientUtil.java

示例14: postXML

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
/**
 * 
 * @param host
 * @param port
 * @param path
 * @param xml
 * @return
 * @throws Exception
 */
public String postXML(String host, int port, String path,String xml) throws Exception {
	//log.debug("start post");
    HttpUrl httpUrl = new HttpUrl();		
    httpUrl.setHost(host);
    httpUrl.setPath(path);
    httpUrl.setPort(port);  
    HostConfiguration config = new HostConfiguration();
    config.setHost(httpUrl.getHost(), httpUrl.getPort());

    PostMethod post = new PostMethod(httpUrl.getPath());
    setParams(httpUrl.getParams(), post);

    StringRequestEntity requestEntity = new StringRequestEntity(xml, null, "utf-8");
    post.setRequestEntity(requestEntity);
    Cookie[] cookies = httpClient.getState().getCookies();
    if (cookies != null && cookies.length > 0) {
       // log.debug("Present cookies : ");
        for (int i = 0; i < cookies.length; i++) {
            log.debug(i + " : " + cookies[i].toExternalForm() + " - domain :" + cookies[i].getDomain()
                    + " - value :" + cookies[i].getValue());
        }
    }
    
    int result = httpClient.executeMethod(config, post);
  //  log.info("postMethod.getResponseBodyAsString : " + post.getResponseBodyAsString());

    //log.debug("HttpClient.executeMethod returns result = [" + result + "]");
   // log.debug("HttpClient.executeMethod returns :");
   // log.debug(post.getResponseBodyAsString());

    if (result != 200)
        throw new Exception("wrong HttpClient.executeMethod post method !");

    return getResponseAsString(post.getResponseBodyAsStream(), DefaultEncoding);
}
 
开发者ID:magenm,项目名称:bsming,代码行数:45,代码来源:HttpClientUtil.java

示例15: clone

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
/**
 * FUNKTIONIERT NICHT, HOST WIRD NICHT UEBERNOMMEN
 * Clones a http method and sets a new url
 * @param src
 * @param url
 * @return
 */
private static HttpMethod clone(HttpMethod src, URL url) {
    HttpMethod trg = HttpMethodCloner.clone(src);
    HostConfiguration trgConfig = trg.getHostConfiguration();
    trgConfig.setHost(url.getHost(),url.getPort(),url.getProtocol());
    trg.setPath(url.getPath());
    trg.setQueryString(url.getQuery());
    
    return trg;
}
 
开发者ID:lucee,项目名称:Lucee4,代码行数:17,代码来源:HTTPEngine3Impl.java


注:本文中的org.apache.commons.httpclient.HostConfiguration.setHost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。