use of org.apache.http.protocol.HttpContext in project camel by apache.
the class HttpProducerContentTypeTest method setUp.
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().setHttpProcessor(getBasicHttpProcessor()).setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory()).setExpectationVerifier(getHttpExpectationVerifier()).setSslContext(getSSLContext()).registerHandler("/content", new HttpRequestHandler() {
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
String contentType = request.getFirstHeader(Exchange.CONTENT_TYPE).getValue();
assertEquals(CONTENT_TYPE, contentType);
response.setEntity(new StringEntity(contentType, "ASCII"));
response.setStatusCode(HttpStatus.SC_OK);
}
}).create();
localServer.start();
super.setUp();
}
use of org.apache.http.protocol.HttpContext in project camel by apache.
the class HttpNoCamelHeaderTest method setUp.
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().setHttpProcessor(getBasicHttpProcessor()).setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory()).setExpectationVerifier(getHttpExpectationVerifier()).setSslContext(getSSLContext()).registerHandler("/hello", new HttpRequestHandler() {
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
response.setStatusCode(HttpStatus.SC_OK);
Object header = request.getFirstHeader(Exchange.FILE_NAME);
assertNull("There should be no Camel header", header);
for (Header h : request.getAllHeaders()) {
if (h.getName().startsWith("Camel") || h.getName().startsWith("org.apache.camel")) {
assertNull("There should be no Camel header", h);
}
}
// set ar regular and Camel header
response.setHeader("MyApp", "dude");
response.setHeader(Exchange.TO_ENDPOINT, "foo");
}
}).create();
localServer.start();
super.setUp();
}
use of org.apache.http.protocol.HttpContext 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.protocol.HttpContext in project oap by oaplatform.
the class Server method accepted.
@SneakyThrows
public void accepted(final Socket socket) {
try {
final DefaultBHttpServerConnection connection = connectionFactory.createConnection(socket);
final String connectionId = connection.toString();
executor.submit(() -> {
try {
connections.put(connectionId, connection);
log.debug("connection accepted: {}", connection);
final HttpContext httpContext = createHttpContext(socket);
Thread.currentThread().setName(connection.toString());
log.debug("start handling {}", connection);
while (!Thread.interrupted() && connection.isOpen()) httpService.handleRequest(connection, httpContext);
} catch (SocketException e) {
if (socketClosed(e))
log.debug("Socket closed: {}", connection);
else if (connectionReset(e))
log.warn("Connection reset: {}", connection);
else
log.error(e.getMessage(), e);
} catch (ConnectionClosedException e) {
log.debug("connection closed: {}", connection);
} catch (Throwable e) {
log.error(e.getMessage(), e);
} finally {
connections.remove(connectionId);
Closeables.close(connection);
}
});
} catch (final IOException e) {
log.warn(e.getMessage());
connections.values().forEach(Closeables::close);
connections.clear();
throw e;
}
}
use of org.apache.http.protocol.HttpContext in project oap by oaplatform.
the class Server method createHttpContext.
// TODO Fix resolution of local through headers instead of socket inet address
private static HttpContext createHttpContext(final Socket socket) {
final HttpContext httpContext = HttpCoreContext.create();
final Protocol protocol;
if (!Inet.isLocalAddress(socket.getInetAddress()))
protocol = Protocol.LOCAL;
else
protocol = SSLSocket.class.isInstance(socket) ? Protocol.HTTPS : Protocol.HTTP;
httpContext.setAttribute("protocol", protocol);
return httpContext;
}
Aggregations