本文整理汇总了Java中org.apache.http.client.methods.HttpUriRequest.getMethod方法的典型用法代码示例。如果您正苦于以下问题:Java HttpUriRequest.getMethod方法的具体用法?Java HttpUriRequest.getMethod怎么用?Java HttpUriRequest.getMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.client.methods.HttpUriRequest
的用法示例。
在下文中一共展示了HttpUriRequest.getMethod方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: args
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
/**
* 拦截HttpClient的Post与Get方法.
*
*/
@Around("execution(* org.apache.http.client.HttpClient.execute(..)) && args(httpUriRequest)")
public Object around(final ProceedingJoinPoint proceedingJoinPoint, final HttpUriRequest httpUriRequest)
throws Throwable {
final long startTime = System.currentTimeMillis();
final Object[] args = proceedingJoinPoint.getArgs();
final Object result = proceedingJoinPoint.proceed(args);
if (httpUriRequest instanceof HttpUriRequest) {
final String methodName = httpUriRequest.getMethod();
final String className = httpUriRequest.getURI().toString();
Tracer.getInstance().addBinaryAnnotation(className, methodName, (int) (System.currentTimeMillis() - startTime));
}
return result;
}
示例2: retryRequest
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
boolean retry = true;
Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
boolean sent = (b != null && b);
if (executionCount > maxRetries) {
// Do not retry if over max retry count
retry = false;
} else if (isInList(exceptionBlacklist, exception)) {
// immediately cancel retry if the error is blacklisted
retry = false;
} else if (isInList(exceptionWhitelist, exception)) {
// immediately retry if error is whitelisted
retry = true;
} else if (!sent) {
// for most other errors, retry only if request hasn't been fully sent yet
retry = true;
}
if (retry) {
// resend all idempotent requests
HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
if (currentReq == null) {
return false;
}
String requestType = currentReq.getMethod();
retry = !requestType.equals("POST");
}
if (retry) {
SystemClock.sleep(retrySleepTimeMS);
} else {
exception.printStackTrace();
}
return retry;
}