use of org.apache.http.HttpRequest in project oap by oaplatform.
the class BlockingHandlerAdapter method handle.
@Override
public void handle(final HttpRequest httpRequest, final HttpResponse httpResponse, final HttpContext httpContext) throws IOException {
log.trace("Handling [{}]", httpRequest);
final HttpInetConnection connection = (HttpInetConnection) httpContext.getAttribute(HTTP_CONNECTION);
final InetAddress remoteAddress = connection.getRemoteAddress();
final String httpContextProtocol = String.valueOf(httpContext.getAttribute("protocol"));
final Request request = new Request(httpRequest, new Context(location, remoteAddress, httpContextProtocol));
RequestCors cors = corsPolicy.getCors(request);
final Response response = new Response(httpResponse, cors);
if (Protocol.LOCAL.equals(this.protocol) && !Inet.isLocalAddress(remoteAddress)) {
response.respond(HTTP_FORBIDDEN);
} else if (cors.autoOptions && request.httpMethod == Request.HttpMethod.OPTIONS) {
response.respond(NO_CONTENT);
} else {
handler.handle(request, response);
}
}
use of org.apache.http.HttpRequest in project oap by oaplatform.
the class NioHandlerAdapter method handle.
@Override
public void handle(final HttpRequest httpRequest, final HttpAsyncExchange httpAsyncExchange, final HttpContext httpContext) throws HttpException, IOException {
LOGGER.trace("handling [{}]", httpRequest);
final HttpInetConnection connection = (HttpInetConnection) httpContext.getAttribute(HttpCoreContext.HTTP_CONNECTION);
final InetAddress remoteAddress = connection.getRemoteAddress();
final HttpResponse response = httpAsyncExchange.getResponse();
final String httpContextProtocol = String.valueOf(httpContext.getAttribute("protocol"));
if (Protocol.LOCAL.equals(this.protocol) && !Inet.isLocalAddress(remoteAddress)) {
response.setStatusCode(HTTP_FORBIDDEN);
} else {
Request request = new Request(httpRequest, new Context(location, remoteAddress, httpContextProtocol));
handler.handle(request, new Response(response, corsPolicy.getCors(request)));
}
httpAsyncExchange.submitResponse();
}
use of org.apache.http.HttpRequest in project jaeger-client-java by jaegertracing.
the class TracingRequestInterceptorTest method testProcessNullScope.
@Test
public void testProcessNullScope() throws Exception {
ScopeManager mockScopeManager = Mockito.mock(ScopeManager.class);
when(mockScopeManager.active()).thenReturn(null);
Tracer mockTracer = Mockito.mock(Tracer.class);
when(mockTracer.scopeManager()).thenReturn(mockScopeManager);
HttpRequestInterceptor interceptor = new TracingRequestInterceptor(mockTracer);
PowerMockito.spy(interceptor);
HttpRequest mockRequest = Mockito.mock(HttpRequest.class);
HttpContext mockContext = Mockito.mock(HttpContext.class);
interceptor.process(mockRequest, mockContext);
PowerMockito.verifyPrivate(interceptor, times(0)).invoke("onSpanStarted", any(Span.class), mockRequest, mockContext);
}
use of org.apache.http.HttpRequest in project oap by oaplatform.
the class SecurityInterceptorTest method testShouldVerifyAndSetUserInSessionIfAuthorizationHeaderIsPresent.
@Test
public void testShouldVerifyAndSetUserInSessionIfAuthorizationHeaderIsPresent() throws UnknownHostException {
final Reflection.Method methodWithAnnotation = REFLECTION.method(method -> method.name().equals("methodWithAnnotation")).get();
final Context context = new Context("/", InetAddress.getLocalHost(), Protocol.HTTP.name());
final String tokenId = UUID.randomUUID().toString();
final HttpRequest httpRequest = new HttpGet();
httpRequest.setHeader("Authorization", tokenId);
httpRequest.setHeader("Host", "localhost");
final Request request = new Request(httpRequest, context);
final User user = new DefaultUser(Role.ADMIN, "testOrg", "test@example.com");
final Token token = new Token();
token.user = new DefaultUser(user);
token.id = tokenId;
token.created = DateTime.now();
when(mockTokenService.getToken(tokenId)).thenReturn(Optional.of(token));
final Session session = new Session();
final Optional<HttpResponse> httpResponse = securityInterceptor.intercept(request, session, methodWithAnnotation, p -> null);
assertFalse(httpResponse.isPresent());
assertNotNull(session.get("user"));
}
use of org.apache.http.HttpRequest in project wso2-synapse by wso2.
the class ProxyTunnelHandler method generateRequest.
public HttpRequest generateRequest(final HttpContext context) throws IOException, HttpException {
HttpHost target = this.route.getTargetHost();
HttpRequest connect = new BasicHttpRequest("CONNECT", target.toHostString(), HttpVersion.HTTP_1_1);
connect.setHeader(HttpHeaders.HOST, target.toHostString());
this.httpProcessor.process(connect, context);
context.setAttribute(SynapseHTTPRequestFactory.ENDPOINT_URL, target.toString());
return connect;
}
Aggregations