use of org.apache.http.HttpRequest in project uavstack by uavorg.
the class ApacheHttpClientAdapter method afterPreCap.
@Override
public void afterPreCap(InvokeChainContext context, Object[] args) {
if (args.length < 2) {
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);
HttpRequest request = (HttpRequest) args[1];
request.removeHeaders(InvokeChainConstants.PARAM_HTTPHEAD_SPANINFO);
request.addHeader(InvokeChainConstants.PARAM_HTTPHEAD_SPANINFO, spanMeta);
handleSlowOperSupporter(request, span, context);
}
use of org.apache.http.HttpRequest in project SEPA by arces-wot.
the class SPARQL11Handler method handle.
@Override
public void handle(HttpRequest request, HttpAsyncExchange httpExchange, HttpContext context) throws HttpException, IOException {
Instant start = Instant.now();
// CORS
if (!corsHandling(httpExchange)) {
jmx.corsFailed();
return;
}
// Parsing SPARQL 1.1 request and attach a token
Request sepaRequest = parse(httpExchange);
// Parsing failed
if (sepaRequest == null) {
logger.error("Parsing failed: " + httpExchange.getRequest());
HttpUtilities.sendFailureResponse(httpExchange, HttpStatus.SC_BAD_REQUEST, "Parsing failed: " + httpExchange.getRequest());
jmx.parsingFailed();
return;
}
// Validate
if (!validate(httpExchange.getRequest())) {
logger.error("Validation failed SPARQL: " + sepaRequest.getSPARQL());
HttpUtilities.sendFailureResponse(httpExchange, HttpStatus.SC_BAD_REQUEST, "Validation failed SPARQL: " + sepaRequest.getSPARQL());
jmx.validatingFailed();
return;
}
// Authorize
if (!authorize(httpExchange.getRequest())) {
logger.error("Authorization failed SPARQL: " + sepaRequest.getSPARQL());
HttpUtilities.sendFailureResponse(httpExchange, HttpStatus.SC_UNAUTHORIZED, "Authorization failed SPARQL: " + sepaRequest.getSPARQL());
jmx.authorizingFailed();
return;
}
// Schedule request
scheduler.schedule(sepaRequest, new SPARQL11ResponseHandler(httpExchange, jmx, start));
}
use of org.apache.http.HttpRequest in project pact-jvm by DiUS.
the class HttpTarget method getProviderInfo.
protected ProviderInfo getProviderInfo() {
Provider provider = testClass.getAnnotation(Provider.class);
final ProviderInfo providerInfo = new ProviderInfo(provider.value());
providerInfo.setPort(port);
providerInfo.setHost(host);
providerInfo.setProtocol(protocol);
providerInfo.setPath(path);
providerInfo.setInsecure(insecure);
if (testClass != null) {
final List<FrameworkMethod> methods = testClass.getAnnotatedMethods(TargetRequestFilter.class);
if (!methods.isEmpty()) {
providerInfo.setRequestFilter((Consumer<HttpRequest>) httpRequest -> methods.forEach(method -> {
try {
method.invokeExplosively(testTarget, httpRequest);
} catch (Throwable t) {
throw new AssertionError("Request filter method " + method.getName() + " failed with an exception", t);
}
}));
}
}
return providerInfo;
}
use of org.apache.http.HttpRequest in project pact-jvm by DiUS.
the class MockMvcTarget method getProviderInfo.
@Override
protected ProviderInfo getProviderInfo() {
Provider provider = testClass.getAnnotation(Provider.class);
final ProviderInfo providerInfo = new ProviderInfo(provider.value());
if (testClass != null) {
final List<FrameworkMethod> methods = testClass.getAnnotatedMethods(TargetRequestFilter.class);
if (!methods.isEmpty()) {
providerInfo.setRequestFilter((Consumer<HttpRequest>) httpRequest -> methods.forEach(method -> {
try {
method.invokeExplosively(testTarget, httpRequest);
} catch (Throwable t) {
throw new AssertionError("Request filter method " + method.getName() + " failed with an exception", t);
}
}));
}
}
return providerInfo;
}
use of org.apache.http.HttpRequest in project opennms by OpenNMS.
the class HttpClientWrapper method enablePreemptiveAuth.
protected void enablePreemptiveAuth(final HttpClientBuilder builder) {
/**
* Add an HttpRequestInterceptor that will perform preemptive authentication
* @see http://hc.apache.org/httpcomponents-client-4.0.1/tutorial/html/authentication.html
*/
final HttpRequestInterceptor preemptiveAuth = new HttpRequestInterceptor() {
@Override
public void process(final HttpRequest request, final HttpContext context) throws IOException {
if (context instanceof HttpClientContext) {
final HttpClientContext clientContext = (HttpClientContext) context;
final AuthState authState = clientContext.getTargetAuthState();
final CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
final HttpHost targetHost = clientContext.getTargetHost();
// If not authentication scheme has been initialized yet
if (authState.getAuthScheme() == null) {
final AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
// Obtain credentials matching the target host
final Credentials creds = credsProvider.getCredentials(authScope);
// If found, generate BasicScheme preemptively
if (creds != null) {
authState.update(new BasicScheme(), creds);
}
}
} else {
throw new IllegalArgumentException("Not sure how to handle a non-HttpClientContext context.");
}
}
};
builder.addInterceptorFirst(preemptiveAuth);
}
Aggregations