Java Code Examples for org.apache.http.client.HttpClient#getParams()

The following examples show how to use org.apache.http.client.HttpClient#getParams() . 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: ClientUtils.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param request
 * @param payload
 * @return
 */
protected HttpResponse sendRequest(HttpUriRequest request) {
  HttpResponse response = null;
  try {
    HttpClient httpclient = new DefaultHttpClient();
    log(request);
    HttpParams params = httpclient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, timeout);
    HttpConnectionParams.setSoTimeout(params, timeout);
    if(proxy != null) {
      httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    response = httpclient.execute(request);
  } catch(IOException ioe) {
    if (ClientUtils.debugging ) {
      ioe.printStackTrace();
    }
    throw new EFhirClientException("Error sending Http Request: "+ioe.getMessage(), ioe);
  }
  return response;
}
 
Example 2
Source File: ClientUtils.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param request
 * @param payload
 * @return
 */
protected HttpResponse sendRequest(HttpUriRequest request) {
  HttpResponse response = null;
  try {
    HttpClient httpclient = new DefaultHttpClient();
    log(request);
    HttpParams params = httpclient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, timeout);
    HttpConnectionParams.setSoTimeout(params, timeout);
    if(proxy != null) {
      httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    response = httpclient.execute(request);
  } catch(IOException ioe) {
    throw new EFhirClientException("Error sending Http Request: "+ioe.getMessage(), ioe);
  }
  return response;
}
 
Example 3
Source File: ClientUtils.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param request
 * @param payload
 * @return
 */
protected HttpResponse sendRequest(HttpUriRequest request) {
  HttpResponse response = null;
  try {
    HttpClient httpclient = new DefaultHttpClient();
    log(request);
    HttpParams params = httpclient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, timeout);
    HttpConnectionParams.setSoTimeout(params, timeout);
    if(proxy != null) {
      httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    response = httpclient.execute(request);
  } catch(IOException ioe) {
    throw new EFhirClientException("Error sending Http Request: "+ioe.getMessage(), ioe);
  }
  return response;
}
 
Example 4
Source File: ClientUtils.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param request
 * @param payload
 * @return
 */
protected HttpResponse sendRequest(HttpUriRequest request) {
  HttpResponse response = null;
  try {
    HttpClient httpclient = new DefaultHttpClient();
    log(request);
    HttpParams params = httpclient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, timeout);
    HttpConnectionParams.setSoTimeout(params, timeout);
    if(proxy != null) {
      httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    response = httpclient.execute(request);
  } catch(IOException ioe) {
    throw new EFhirClientException("Error sending Http Request: "+ioe.getMessage(), ioe);
  }
  return response;
}
 
Example 5
Source File: ClientUtils.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param request
 * @param payload
 * @return
 */
 protected HttpResponse sendRequest(HttpUriRequest request) {
	HttpResponse response = null;
	try {
		HttpClient httpclient = new DefaultHttpClient();
     log(request);
		HttpParams params = httpclient.getParams();
     HttpConnectionParams.setConnectionTimeout(params, timeout);
     HttpConnectionParams.setSoTimeout(params, timeout);
		if(proxy != null) {
			httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
		}
		response = httpclient.execute(request);
	} catch(IOException ioe) {
     throw new EFhirClientException("Error sending Http Request: "+ioe.getMessage(), ioe);
	}
	return response;
}
 
Example 6
Source File: SolrClientUtils.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private static HttpClient cloneHttpClient(HttpClient sourceClient)
		throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {

	if (sourceClient == null) {
		return null;
	}

	Class<?> clientType = ClassUtils.getUserClass(sourceClient);
	Constructor<?> constructor = ClassUtils.getConstructorIfAvailable(clientType, HttpParams.class);
	if (constructor != null) {

		HttpClient targetClient = (HttpClient) constructor.newInstance(sourceClient.getParams());
		BeanUtils.copyProperties(sourceClient, targetClient);
		return targetClient;
	} else {
		return new DefaultHttpClient(sourceClient.getParams());
	}

}
 
Example 7
Source File: AppUtil.java    From coolreader with MIT License 6 votes vote down vote up
/**
 * 获取网址内容
 * @param url
 * @return
 * @throws Exception
 */
public static String getContent(String url) throws Exception{
    StringBuilder sb = new StringBuilder();
    
    HttpClient client = new DefaultHttpClient();
    HttpParams httpParams = client.getParams();
    //设置网络超时参数
    HttpConnectionParams.setConnectionTimeout(httpParams, 3000);
    HttpConnectionParams.setSoTimeout(httpParams, 5000);
    HttpResponse response = client.execute(new HttpGet(url));
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"), 8192);
        
        String line = null;
        while ((line = reader.readLine())!= null){
            sb.append(line + "/n");
        }
        reader.close();
    }
    return sb.toString();
}
 
Example 8
Source File: Curl.java    From UAF with Apache License 2.0 5 votes vote down vote up
private static HttpClient createHttpsClient() {
	HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
	SchemeRegistry registry = new SchemeRegistry();
	SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
	socketFactory
			.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
	registry.register(new Scheme("https", socketFactory, 443));
	HttpClient client = new DefaultHttpClient();
	SingleClientConnManager mgr = new SingleClientConnManager(
			client.getParams(), registry);
	DefaultHttpClient httpClient = new DefaultHttpClient(mgr,
			client.getParams());
	return httpClient;
}
 
Example 9
Source File: HttpClientFactory.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * HTTPClientオブジェクトを作成.
 * @param type 通信タイプ
 * @return 作成したHttpClientクラスインスタンス
 */
public static HttpClient create(final String type) {
    if (TYPE_DEFAULT.equalsIgnoreCase(type)) {
        return new DefaultHttpClient();
    }

    SSLSocketFactory sf = null;
    try {
        if (TYPE_INSECURE.equalsIgnoreCase(type)) {
            sf = createInsecureSSLSocketFactory();
        }
    } catch (Exception e) {
        return null;
    }

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("https", PORTHTTPS, sf));
    schemeRegistry.register(new Scheme("http", PORTHTTP, PlainSocketFactory.getSocketFactory()));
    HttpParams params = new BasicHttpParams();
    ClientConnectionManager cm = new SingleClientConnManager(schemeRegistry);
    // ClientConnectionManager cm = new
    // ThreadSafeClientConnManager(schemeRegistry);
    HttpClient hc = new DefaultHttpClient(cm, params);

    HttpParams params2 = hc.getParams();
    int timeout = TIMEOUT;
    HttpConnectionParams.setConnectionTimeout(params2, timeout); // 接続のタイムアウト
    HttpConnectionParams.setSoTimeout(params2, timeout); // データ取得のタイムアウト
    return hc;
}
 
Example 10
Source File: HttpClientFactory.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * HTTPClientオブジェクトを作成.
 * @param type 通信タイプ
 * @param connectionTimeout タイムアウト値(ミリ秒)。0の場合はデフォルト値を利用する。
 * @return 作成したHttpClientクラスインスタンス
 */
public static HttpClient create(final String type, final int connectionTimeout) {
    if (TYPE_DEFAULT.equalsIgnoreCase(type)) {
        return new DefaultHttpClient();
    }

    SSLSocketFactory sf = null;
    try {
        if (TYPE_INSECURE.equalsIgnoreCase(type)) {
            sf = createInsecureSSLSocketFactory();
        }
    } catch (Exception e) {
        return null;
    }

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("https", PORTHTTPS, sf));
    schemeRegistry.register(new Scheme("http", PORTHTTP, PlainSocketFactory.getSocketFactory()));
    HttpParams params = new BasicHttpParams();
    ClientConnectionManager cm = new SingleClientConnManager(schemeRegistry);
    // ClientConnectionManager cm = new
    // ThreadSafeClientConnManager(schemeRegistry);
    HttpClient hc = new DefaultHttpClient(cm, params);

    HttpParams params2 = hc.getParams();
    int timeout = TIMEOUT;
    if (connectionTimeout != 0) {
        timeout = connectionTimeout;
    }
    HttpConnectionParams.setConnectionTimeout(params2, timeout); // 接続のタイムアウト
    HttpConnectionParams.setSoTimeout(params2, timeout); // データ取得のタイムアウト
    return hc;
}
 
Example 11
Source File: ApacheHttpTransport.java    From google-http-java-client with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor that allows an alternative Apache HTTP client to be used.
 *
 * <p>Note that a few settings are overridden:
 *
 * <ul>
 *   <li>HTTP version is set to 1.1 using {@link HttpProtocolParams#setVersion} with {@link
 *       HttpVersion#HTTP_1_1}.
 *   <li>Redirects are disabled using {@link ClientPNames#HANDLE_REDIRECTS}.
 *   <li>{@link ConnManagerParams#setTimeout} and {@link
 *       HttpConnectionParams#setConnectionTimeout} are set on each request based on {@link
 *       HttpRequest#getConnectTimeout()}.
 *   <li>{@link HttpConnectionParams#setSoTimeout} is set on each request based on {@link
 *       HttpRequest#getReadTimeout()}.
 * </ul>
 *
 * <p>Use {@link Builder} for a more user-friendly way to modify the HTTP client options.
 *
 * @param httpClient Apache HTTP client to use
 * @since 1.6
 */
public ApacheHttpTransport(HttpClient httpClient) {
  this.httpClient = httpClient;
  HttpParams params = httpClient.getParams();
  if (params == null) {
    params = newDefaultHttpClient().getParams();
  }
  HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
  params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);
}