Beispiel #1
0
  static {
    HttpConnectionManagerParams params = loadHttpConfFromFile();

    connectionManager = new MultiThreadedHttpConnectionManager();

    connectionManager.setParams(params);

    client = new HttpClient(connectionManager);
  }
Beispiel #2
0
  /*     */ static
  /*     */ {
    /*  39 */ HttpConnectionManagerParams params = loadHttpConfFromFile();
    /*     */
    /*  41 */ connectionManager = new MultiThreadedHttpConnectionManager();
    /*     */
    /*  43 */ connectionManager.setParams(params);

    client = new HttpClient(connectionManager);
    /*     */ }
Beispiel #3
0
 static {
   HostConfiguration hostConfiguration = new HostConfiguration();
   HttpConnectionManagerParams params = new HttpConnectionManagerParams();
   params.setConnectionTimeout(3000);
   params.setMaxTotalConnections(2000);
   params.setStaleCheckingEnabled(true);
   params.setTcpNoDelay(true);
   params.setSoTimeout(10000);
   params.setMaxConnectionsPerHost(hostConfiguration, 1000);
   HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
   connectionManager.setParams(params);
   httpClient = new HttpClient(connectionManager);
   httpClient.setHostConfiguration(hostConfiguration);
 }
Beispiel #4
0
  /** Factory method used by producers and consumers to create a new {@link HttpClient} instance */
  public static HttpClient createHttpClient() {
    HttpClientParams clientParams = new HttpClientParams();
    HttpConnectionManagerParams managerParams = new HttpConnectionManagerParams();
    managerParams.setConnectionTimeout(1000); // 设置连接超时时间
    managerParams.setDefaultMaxConnectionsPerHost(2);
    managerParams.setSoTimeout(1000); // 设置读取数据超时时间
    HttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
    httpConnectionManager.setParams(managerParams);

    HttpClient answer = new HttpClient(clientParams);
    answer.setHttpConnectionManager(httpConnectionManager);

    return answer;
  }
Beispiel #5
0
  private String send(HttpMethod method, boolean sslExceptionIgnore) throws HttpNetAgentException {
    String responseBody = null;
    HttpClient hc = null;

    try {
      this.hashCode();
      String reqLog =
          ">> " + (method instanceof PostMethod ? "POST" : "GET") + " [" + method.getURI() + "]";

      if (method instanceof PostMethod) {
        NameValuePair[] params = ((PostMethod) method).getParameters();
        for (int i = 0; i < params.length; i++) {
          NameValuePair param = params[i];
          reqLog += "\n" + (param.getName() + "=" + param.getValue());
        }
      }
      reqLog +=
          ", hscd["
              + this.hashCode()
              + "], sslExcIgnore["
              + sslExceptionIgnore
              + "], hs["
              + this.hashCode()
              + "]";

      logger.info(reqLog);
      logger.info(getHttpInfoDumy(method));

      HttpConnectionManager httpConnMgr = new SimpleHttpConnectionManager();
      HttpConnectionManagerParams httpConnMgrParams = new HttpConnectionManagerParams();

      // Connection Timeout 설정
      httpConnMgrParams.setConnectionTimeout(netTimeoutConn);

      // Socket Timeout 설정
      httpConnMgrParams.setSoTimeout(netTimeoutSock);
      httpConnMgr.setParams(httpConnMgrParams);

      hc = new HttpClient(httpConnMgr);
      /*
      if (sslExceptionIgnore){
      	try {
      		Protocol.registerProtocol("https", new Protocol("https", new EasySSLProtocolSocketFactory(), 443));
      	} catch (GeneralSecurityException e) {
      		e.printStackTrace();
      	}
      }
      */

      int status = hc.executeMethod(method);

      if (200 == status) {
        responseBody = method.getResponseBodyAsString();
        logger.info("<< responseBody [" + responseBody + "], hs[" + this.hashCode() + "]");
        if (responseBody == null) responseBody = "";

      } else {
        logger.error(
            "<< http status Not Success ["
                + status
                + "], hs["
                + this.hashCode()
                + "],"
                + getHttpInfoDumy(method));
        throw new HttpNetAgentException(
            HttpNetAgentException.HTTP_HAEDER_NOT_SUCCESS, "Http Status[" + status + "]");
      }

    } catch (HttpException e) {
      logger.error(
          "<< HttpException msg ["
              + e.getMessage()
              + "], hs["
              + this.hashCode()
              + "],"
              + getHttpInfoDumy(method),
          e);
      throw new HttpNetAgentException(HttpNetAgentException.HTTP_NET_ERROR, e.getMessage());
    } catch (IOException e) {
      logger.error(
          "<< IOException msg ["
              + e.getMessage()
              + "], hs["
              + this.hashCode()
              + "],"
              + getHttpInfoDumy(method),
          e);
      throw new HttpNetAgentException(HttpNetAgentException.HTTP_NET_ERROR, e.getMessage());
    }

    return responseBody;
  }
 public HttpClient getHttpClient() {
   HttpConnectionManagerParams params = new HttpConnectionManagerParams();
   HttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
   manager.setParams(params);
   return new HttpClient(manager);
 }