本文整理匯總了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;
}