use of org.apache.http.HttpRequest in project spark by perwendel.
the class SparkTestUtil method setFollowRedirectStrategy.
public void setFollowRedirectStrategy(Integer... codes) {
final List<Integer> redirectCodes = Arrays.asList(codes);
DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy() {
public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) {
boolean isRedirect = false;
try {
isRedirect = super.isRedirected(request, response, context);
} catch (Exception e) {
e.printStackTrace();
}
if (!isRedirect) {
int responseCode = response.getStatusLine().getStatusCode();
if (redirectCodes.contains(responseCode)) {
return true;
}
}
return isRedirect;
}
};
this.httpClient = httpClientBuilder().setRedirectStrategy(redirectStrategy).build();
}
use of org.apache.http.HttpRequest in project lucene-solr by apache.
the class SolrHttpRequestRetryHandler method retryRequest.
@Override
public boolean retryRequest(final IOException exception, final int executionCount, final HttpContext context) {
log.debug("Retry http request {} out of {}", executionCount, this.retryCount);
if (executionCount > this.retryCount) {
log.debug("Do not retry, over max retry count");
return false;
}
if (this.nonRetriableClasses.contains(exception.getClass())) {
log.debug("Do not retry, non retriable class {}", exception.getClass().getName());
return false;
} else {
for (final Class<? extends IOException> rejectException : this.nonRetriableClasses) {
if (rejectException.isInstance(exception)) {
log.debug("Do not retry, non retriable class {}", exception.getClass().getName());
return false;
}
}
}
final HttpClientContext clientContext = HttpClientContext.adapt(context);
final HttpRequest request = clientContext.getRequest();
if (requestIsAborted(request)) {
log.debug("Do not retry, request was aborted");
return false;
}
if (handleAsIdempotent(clientContext)) {
log.debug("Retry, request should be idempotent");
return true;
}
log.debug("Do not retry, no allow rules matched");
return false;
}
use of org.apache.http.HttpRequest in project lucene-solr by apache.
the class ConnectionReuseTest method headerRequest.
public void headerRequest(HttpHost target, HttpRoute route, HttpClientConnection conn, PoolingHttpClientConnectionManager cm) throws IOException, HttpException {
HttpRequest req = new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1);
req.addHeader("Host", target.getHostName());
if (!conn.isOpen()) {
// establish connection based on its route info
cm.connect(conn, route, 1000, context);
// and mark it as route complete
cm.routeComplete(conn, route, context);
}
conn.sendRequestHeader(req);
conn.flush();
conn.receiveResponseHeader();
}
use of org.apache.http.HttpRequest in project uavstack by uavorg.
the class ApacheAsyncHttpClientIT method doAsyncStart.
/**
* for async http client
*
* @param args
* @return
*/
@SuppressWarnings({ "rawtypes", "unused", "unchecked" })
public FutureCallback doAsyncStart(Object[] args) {
HttpAsyncRequestProducer requestProducer = null;
HttpAsyncResponseConsumer responseConsumer = null;
HttpContext context = null;
FutureCallback callback = null;
Map mObj = null;
if (args.length == 4) {
requestProducer = (HttpAsyncRequestProducer) args[0];
responseConsumer = (HttpAsyncResponseConsumer) args[1];
context = (HttpContext) args[2];
callback = (FutureCallback) args[3];
} else if (args.length == 5) {
requestProducer = (HttpAsyncRequestProducer) args[1];
responseConsumer = (HttpAsyncResponseConsumer) args[2];
context = (HttpContext) args[3];
callback = (FutureCallback) args[4];
}
String httpAction = null;
try {
HttpRequest hr = requestProducer.generateRequest();
/**
* 呵呵,就是把UAV的客户端标记加到http header里面,接收方就知道是哪个东东调用的了,便于实现来源快速匹配,这个模式只适合直连模式
*
* 对于代理模式,只匹配代理源即可
*/
hr.addHeader("UAV-Client-Src", MonitorServerUtil.getUAVClientSrc(this.applicationId));
RequestLine rl = hr.getRequestLine();
httpAction = rl.getMethod();
targetURL = rl.getUri();
} catch (IOException e) {
// ignore thie exception
return null;
} catch (HttpException e) {
// ignore thie exception
return null;
}
Map<String, Object> params = new HashMap<String, Object>();
params.put(CaptureConstants.INFO_CLIENT_REQUEST_URL, targetURL);
params.put(CaptureConstants.INFO_CLIENT_REQUEST_ACTION, httpAction);
params.put(CaptureConstants.INFO_CLIENT_APPID, this.applicationId);
params.put(CaptureConstants.INFO_CLIENT_TYPE, "apache.http.AsyncClient");
if (logger.isDebugable()) {
logger.debug("Invoke START:" + targetURL + "," + httpAction + "," + this.applicationId, null);
}
/**
* for async, as not in the same thread
*/
ccMap = UAVServer.instance().runMonitorAsyncCaptureOnServerCapPoint(CaptureConstants.CAPPOINT_APP_CLIENT, Monitor.CapturePhase.PRECAP, params, null);
// register invokechain adapter
UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "registerAdapter", ApacheAsyncHttpClientAdapter.class);
ccMap4Chain = (Map<String, Object>) UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "runCap", InvokeChainConstants.CHAIN_APP_CLIENT, InvokeChainConstants.CapturePhase.PRECAP, params, ApacheAsyncHttpClientAdapter.class, args);
if (callback == null) {
return null;
}
callback = JDKProxyInvokeUtil.newProxyInstance(HttpContext.class.getClassLoader(), new Class<?>[] { FutureCallback.class }, new JDKProxyInvokeHandler<FutureCallback>(callback, new FutureCallbackProxyInvokeProcessor(ccMap4Chain)));
return callback;
}
use of org.apache.http.HttpRequest in project uavstack by uavorg.
the class ApacheAsyncHttpClientAdapter method afterPreCap.
@Override
public void afterPreCap(InvokeChainContext context, Object[] args) {
HttpAsyncRequestProducer requestProducer = null;
HttpRequest request = null;
if (args.length == 4) {
requestProducer = (HttpAsyncRequestProducer) args[0];
} else if (args.length == 5) {
requestProducer = (HttpAsyncRequestProducer) args[1];
} else {
return;
}
try {
request = requestProducer.generateRequest();
} catch (Exception e) {
// ignore
}
if (request == null) {
return;
}
/**
* after precap the client's span is created, set the span meta into http request header
*/
String url = (String) context.get(InvokeChainConstants.CLIENT_SPAN_THREADLOCAL_STOREKEY);
Span span = this.spanFactory.getSpanFromContext(url);
String spanMeta = this.spanFactory.getSpanMeta(span);
request.removeHeaders(InvokeChainConstants.PARAM_HTTPHEAD_SPANINFO);
request.addHeader(InvokeChainConstants.PARAM_HTTPHEAD_SPANINFO, spanMeta);
/**
* store span into context for async
*/
context.put(InvokeChainConstants.PARAM_SPAN_KEY, span);
handleSlowOperSupporter(request, span, context);
}
Aggregations