當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultHttpMethodRetryHandler類代碼示例

本文整理匯總了Java中org.apache.commons.httpclient.DefaultHttpMethodRetryHandler的典型用法代碼示例。如果您正苦於以下問題:Java DefaultHttpMethodRetryHandler類的具體用法?Java DefaultHttpMethodRetryHandler怎麽用?Java DefaultHttpMethodRetryHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DefaultHttpMethodRetryHandler類屬於org.apache.commons.httpclient包,在下文中一共展示了DefaultHttpMethodRetryHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: get

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; //導入依賴的package包/類
@Override
public HttpResponse get(URL urlObj, String userName, String password, int timeout) {
  HttpClient client = new HttpClient();
  HttpMethod method = new GetMethod(urlObj.toString());

  client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
      new DefaultHttpMethodRetryHandler());
  client.getParams().setSoTimeout(1000 * timeout);
  client.getParams().setConnectionManagerTimeout(1000 * timeout);
  if (userName != null && password != null) {
    setBasicAuthorization(method, userName, password);
  }
  try {
    int response = client.executeMethod(method);
    return new HttpResponse(response, method.getResponseBody());
  } catch (IOException e) {
    throw new RuntimeException("Failed to get " + urlObj.toString(), e);
  } finally {
    method.releaseConnection();
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:22,代碼來源:LogiURLFetchService.java

示例2: post

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; //導入依賴的package包/類
@Override
public HttpResponse post(URL urlObj, byte[] payload, String userName, String password,
                         int timeout) {
  HttpClient client = new HttpClient();
  PostMethod method = new PostMethod(urlObj.toString());
  method.setRequestEntity(new ByteArrayRequestEntity(payload));
  method.setRequestHeader("Content-type", "application/json");
  client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
      new DefaultHttpMethodRetryHandler());
  client.getParams().setSoTimeout(1000 * timeout);
  client.getParams().setConnectionManagerTimeout(1000 * timeout);
  if (userName != null && password != null) {
    setBasicAuthorization(method, userName, password);
  }
  try {
    int response = client.executeMethod(method);
    return new HttpResponse(response, method.getResponseBody());
  } catch (IOException e) {
    throw new RuntimeException("Failed to process post request URL: " + urlObj, e);
  } finally {
    method.releaseConnection();
  }

}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:25,代碼來源:LogiURLFetchService.java

示例3: createPostMethod

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; //導入依賴的package包/類
private PostMethod createPostMethod(KalturaParams kparams,
		KalturaFiles kfiles, String url) {
	PostMethod method = new PostMethod(url);
       method.setRequestHeader("Accept","text/xml,application/xml,*/*");
       method.setRequestHeader("Accept-Charset","utf-8,ISO-8859-1;q=0.7,*;q=0.5");
       
       if (!kfiles.isEmpty()) {        	
           method = this.getPostMultiPartWithFiles(method, kparams, kfiles);        	
       } else {
           method = this.addParams(method, kparams);            
       }
       
       if (isAcceptGzipEncoding()) {
		method.addRequestHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
	}
       

	// Provide custom retry handler is necessary
	method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
			new DefaultHttpMethodRetryHandler (3, false));
	return method;
}
 
開發者ID:ITYug,項目名稱:kaltura-ce-sakai-extension,代碼行數:23,代碼來源:KalturaClientBase.java

示例4: main

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    HttpClient hc = new HttpClient();
        PostMethod method = null;
        //同步企業名錄
        method = new PostMethod("http://test.vop.onlyou.com/interface/bpo/UserValidate.htm");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("username", "pancs_qd");
        jsonObject.put("password", "123456");
        String transJson = jsonObject.toString();
        RequestEntity se = new StringRequestEntity(transJson,"application/json","UTF-8");
        method.setRequestEntity(se);
        //使用係統提供的默認的恢複策略
        method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
        //設置超時的時間
        method.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 3000);	            
        int statusCode = hc.executeMethod(method);
        System.out.println(statusCode);
        byte[] responseBody = method.getResponseBody();
        System.out.println(new String(responseBody));
        System.out.println("getStatusLine:"+method.getStatusLine());
        String response = new String(method.getResponseBodyAsString().getBytes("utf-8"));
        System.out.println("response:"+response);
}
 
開發者ID:pcsh,項目名稱:cashion,代碼行數:24,代碼來源:UserValidate.java

示例5: getCustomerList

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; //導入依賴的package包/類
public void getCustomerList()  throws JSONException, IOException {
    HttpClient hc = new HttpClient();
    PostMethod method = null;
    JSONObject jsonObject = new JSONObject();
    System.out.println("同步企業名錄");
    method = new PostMethod("http://test.vop.onlyou.com/interface/bpo/getCustomerList.htm");
    jsonObject.put("lastSyncDate", "201501");
    String transJson = jsonObject.toString();
    RequestEntity se = new StringRequestEntity(transJson,"application/json","UTF-8");
    method.setRequestEntity(se);
    //使用係統提供的默認的恢複策略
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
    //設置超時的時間
    method.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 3000);
    hc.executeMethod(method);
    InputStream strStream = method.getResponseBodyAsStream();
    ByteArrayOutputStream   baos   =   new   ByteArrayOutputStream(); 
    int   i=-1; 
    while((i=strStream.read())!=-1){ 
    baos.write(i); 
    } 
   String strBody =   baos.toString(); 
    System.out.println(new String(strBody));
    System.out.println("getStatusLine:"+method.getStatusLine());
}
 
開發者ID:pcsh,項目名稱:cashion,代碼行數:26,代碼來源:allBPOInterface.java

示例6: UserValidate

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; //導入依賴的package包/類
public void UserValidate() throws JSONException, IOException {
    HttpClient hc = new HttpClient();
    PostMethod method = null;
    System.out.println(" 掃描前置客戶端權限校驗");
    method = new PostMethod("http://test.vop.onlyou.com/interface/bpo/UserValidate.htm");
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("username", "pancs_qd");
    jsonObject.put("password", "111111");
    String transJson = jsonObject.toString();
    RequestEntity se = new StringRequestEntity(transJson,"application/json","UTF-8");
    method.setRequestEntity(se);
    //使用係統提供的默認的恢複策略
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
    //設置超時的時間
    method.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 3000);	            
    hc.executeMethod(method);
    InputStream strStream = method.getResponseBodyAsStream();
    ByteArrayOutputStream   baos   =   new   ByteArrayOutputStream(); 
    int   i=-1; 
    while((i=strStream.read())!=-1){ 
    baos.write(i); 
    } 
   String strBody =   baos.toString(); 
    System.out.println(new String(strBody));
    System.out.println("getStatusLine:"+method.getStatusLine());
}
 
開發者ID:pcsh,項目名稱:cashion,代碼行數:27,代碼來源:allBPOInterface.java

示例7: main

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
      HttpClient hc = new HttpClient();
          PostMethod method = null;
          JSONObject jsonObject = new JSONObject();
          //同步企業名錄
          method = new PostMethod("http://test.vop.onlyou.com/interface/bpo/getCustomerList.htm");
          jsonObject.put("lastSyncDate", "201501");
          String transJson = jsonObject.toString();
          RequestEntity se = new StringRequestEntity(transJson,"application/json","UTF-8");
          method.setRequestEntity(se);
          //使用係統提供的默認的恢複策略
          method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
          //設置超時的時間
          method.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 3000);
          int statusCode = hc.executeMethod(method);
          System.out.println(statusCode);
          byte[] responseBody = method.getResponseBody();
          System.out.println(new String(responseBody));
          System.out.println("getStatusLine:"+method.getStatusLine());
          String response = new String(method.getResponseBodyAsString().getBytes("utf-8"));
          System.out.println("response:"+response);
}
 
開發者ID:pcsh,項目名稱:cashion,代碼行數:23,代碼來源:getCustomerList.java

示例8: executeMethod

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; //導入依賴的package包/類
/**
	 * @param martServiceLocation
	 * @param data
	 * @return
	 * @throws MartServiceException
	 */
	private static InputStream executeMethod(HttpMethod method,
			String martServiceLocation) throws MartServiceException {
		HttpClient client = new HttpClient();
		if (isProxyHost(martServiceLocation)) {
			setProxy(client);
		}

		method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
				new DefaultHttpMethodRetryHandler(3, false));
//		method.getParams().setSoTimeout(60000);
		try {
			int statusCode = client.executeMethod(method);
			if (statusCode != HttpStatus.SC_OK) {
				throw constructException(method, martServiceLocation, null);
			}
			return method.getResponseBodyAsStream();
		} catch (IOException e) {
			throw constructException(method, martServiceLocation, e);
		}
	}
 
開發者ID:apache,項目名稱:incubator-taverna-plugin-bioinformatics,代碼行數:27,代碼來源:MartServiceUtils.java

示例9: test

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; //導入依賴的package包/類
@Test
public void test() throws Exception {
    HttpClient client = new HttpClient();
    client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT);
    client.getParams().setSoTimeout(SO_TIMEOUT);

    GetMethod method = new GetMethod(webServer.getCallHttpUrl());

    // 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(method);
    } catch (Exception ignored) {
    } finally {
        method.releaseConnection();
    }

    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
}
 
開發者ID:naver,項目名稱:pinpoint,代碼行數:24,代碼來源:HttpClientIT.java

示例10: hostConfig

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; //導入依賴的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

示例11: getHttpClient

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; //導入依賴的package包/類
private static HttpClient getHttpClient() {
	HttpClient httpClient = new HttpClient();
	// 設置 HttpClient 接收 Cookie,用與瀏覽器一樣的策略
	httpClient.getParams().setCookiePolicy(
			CookiePolicy.BROWSER_COMPATIBILITY);
	// 設置 默認的超時重試處理策略
	httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
			new DefaultHttpMethodRetryHandler());
	// 設置 連接超時時間
	httpClient.getHttpConnectionManager().getParams()
			.setConnectionTimeout(TIMEOUT_CONNECTION);
	// 設置 讀數據超時時間
	httpClient.getHttpConnectionManager().getParams()
			.setSoTimeout(TIMEOUT_SOCKET);
	// 設置 字符集
	httpClient.getParams().setContentCharset(UTF_8);
	return httpClient;
}
 
開發者ID:misty-rain,項目名稱:smartedu,代碼行數:19,代碼來源:BitmapManager.java

示例12: getHttpClient

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; //導入依賴的package包/類
/**
 * 獲取HttpClient對象
 * 
 * @return
 */
private static HttpClient getHttpClient() {
	HttpClient httpClient = new HttpClient();
	// 設置 HttpClient 接收 Cookie,用與瀏覽器一樣的策略
	httpClient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
	// 設置 默認的超時重試處理策略
	httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
			new DefaultHttpMethodRetryHandler());
	// 設置 連接超時時間
	httpClient.getHttpConnectionManager().getParams()
			.setConnectionTimeout(TIMEOUT_CONNECTION);
	// 設置 讀數據超時時間
	httpClient.getHttpConnectionManager().getParams().setSoTimeout(TIMEOUT_SOCKET);
	// 設置 字符集
	httpClient.getParams().setContentCharset(UTF_8);
	return httpClient;
}
 
開發者ID:WanderingSeed,項目名稱:Common-Library,代碼行數:22,代碼來源:HttpClientUtils.java

示例13: getHttpClient

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; //導入依賴的package包/類
private static HttpClient getHttpClient() {
	HttpClient httpClient = new HttpClient();
	httpClient.getParams().setCookiePolicy(
			CookiePolicy.BROWSER_COMPATIBILITY);
	httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
			new DefaultHttpMethodRetryHandler());
	httpClient.getHttpConnectionManager().getParams()
			.setConnectionTimeout(TIMEOUT_CONNECTION);
	
	httpClient.getHttpConnectionManager().getParams().setParameter("http.socket.timeout", TIMEOUT_SOCKET);
	httpClient.getHttpConnectionManager().getParams()
			.setSoTimeout(TIMEOUT_SOCKET);
	httpClient.getParams().setContentCharset(UTF_8);
	return httpClient;
}
 
開發者ID:PlutoArchitecture,項目名稱:Pluto-Android,代碼行數:16,代碼來源:ApiClient.java

示例14: executeQuery

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; //導入依賴的package包/類
private HttpMethod executeQuery(FederatedSearch sruSearch, String query, SRUSettings settings, int offset,
	int perpage) throws IOException
{
	HttpMethod httpMethod = null;

	try
	{
		// URL includes the port (if any) we trust ...
		URL url = new URL(settings.getUrl());
		PostMethod postMethod = new PostMethod(url.toExternalForm());
		NameValuePair[] nameValuePairs = populateNameValuePairs(query, settings, offset, perpage);
		postMethod.addParameters(nameValuePairs);
		httpMethod = postMethod;
	}
	catch( Exception e )
	{
		throw new RuntimeException(e);
	}

	HttpClient httpClient = new HttpClient();
	httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(sruSearch.getTimeout() * 1000);
	httpClient.getHttpConnectionManager().getParams().setSoTimeout(sruSearch.getTimeout() * 1000);
	// Prevent the default 3 tries - so once is enough ...?
	httpClient.getHttpConnectionManager().getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
		new DefaultHttpMethodRetryHandler(0, false));

	httpClient.executeMethod(httpMethod);

	return httpMethod;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:31,代碼來源:SruServiceImpl.java

示例15: buildClient

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:46,代碼來源:HttpClientBuilder.java


注:本文中的org.apache.commons.httpclient.DefaultHttpMethodRetryHandler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。