本文整理汇总了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();
}
}
示例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();
}
}
示例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;
}
示例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);
}
示例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());
}
示例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());
}
示例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);
}
示例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);
}
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}