use of io.netty.handler.codec.http.HttpMethod in project xipki by xipki.
the class HealthCheckServlet method service0.
private FullHttpResponse service0(FullHttpRequest request, ServletURI servletUri, SSLSession sslSession) {
HttpVersion version = request.protocolVersion();
HttpMethod method = request.method();
if (method != HttpMethod.GET) {
return createErrorResponse(version, HttpResponseStatus.METHOD_NOT_ALLOWED);
}
try {
if (server == null) {
LOG.error("server in servlet not configured");
return createErrorResponse(version, HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
ResponderAndPath responderAndPath = server.getResponderForPath(servletUri.getPath());
if (responderAndPath == null) {
return createErrorResponse(version, HttpResponseStatus.NOT_FOUND);
}
HealthCheckResult healthResult = server.healthCheck(responderAndPath.getResponder());
HttpResponseStatus status = healthResult.isHealthy() ? HttpResponseStatus.OK : HttpResponseStatus.INTERNAL_SERVER_ERROR;
byte[] respBytes = healthResult.toJsonMessage(true).getBytes();
return createResponse(version, status, HealthCheckServlet.CT_RESPONSE, respBytes);
} catch (Throwable th) {
if (th instanceof EOFException) {
LogUtil.warn(LOG, th, "connection reset by peer");
} else {
LOG.error("Throwable thrown, this should not happen", th);
}
return createErrorResponse(version, HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
}
use of io.netty.handler.codec.http.HttpMethod in project activemq-artemis by apache.
the class HttpAcceptorHandler method channelRead.
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
FullHttpRequest request = (FullHttpRequest) msg;
HttpMethod method = request.method();
// if we are a post then we send upstream, otherwise we are just being prompted for a response.
if (method.equals(HttpMethod.POST)) {
ctx.fireChannelRead(ReferenceCountUtil.retain(((FullHttpRequest) msg).content()));
// add a new response
responses.put(new ResponseHolder(System.currentTimeMillis() + responseTime, new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK)));
ReferenceCountUtil.release(msg);
return;
}
super.channelRead(ctx, msg);
}
use of io.netty.handler.codec.http.HttpMethod in project netty by netty.
the class RtspMethods method valueOf.
/**
* Returns the {@link HttpMethod} represented by the specified name.
* If the specified name is a standard RTSP getMethod name, a cached instance
* will be returned. Otherwise, a new instance will be returned.
*/
public static HttpMethod valueOf(String name) {
name = checkNonEmptyAfterTrim(name, "name").toUpperCase();
HttpMethod result = methodMap.get(name);
if (result != null) {
return result;
} else {
return HttpMethod.valueOf(name);
}
}
use of io.netty.handler.codec.http.HttpMethod in project wildfly by wildfly.
the class TestingOcspServer method getHttpResponse.
public HttpResponse getHttpResponse(HttpRequest request, HttpOcspServlet servlet) {
byte[] body;
HttpMethod method;
if (request.getBody() == null) {
method = HttpMethod.GET;
body = request.getPath().getValue().split("/ocsp/", 2)[1].getBytes(UTF_8);
} else {
method = HttpMethod.POST;
body = request.getBody().getRawBytes();
}
ByteBuf buffer = Unpooled.wrappedBuffer(body);
FullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, method, request.getPath().getValue(), buffer);
for (Header header : request.getHeaderList()) {
for (NottableString value : header.getValues()) {
nettyRequest.headers().add(header.getName().getValue(), value.getValue());
}
}
FullHttpResponse nettyResponse;
try {
nettyResponse = servlet.service(nettyRequest, new ServletURI(request.getPath().getValue()), null, SslReverseProxyMode.NONE);
} catch (Exception e) {
throw new RuntimeException(e);
}
HttpResponse response = response().withStatusCode(nettyResponse.status().code()).withBody(nettyResponse.content().array());
for (Map.Entry<String, String> header : nettyResponse.headers()) {
response.withHeader(header.getKey(), header.getValue());
}
return response;
}
use of io.netty.handler.codec.http.HttpMethod in project crate by crate.
the class HttpBlobHandler method handleBlobRequest.
private void handleBlobRequest(HttpRequest request, @Nullable HttpContent content) throws IOException {
if (possibleRedirect(request, index, digest)) {
return;
}
HttpMethod method = request.method();
if (method.equals(HttpMethod.GET)) {
get(request, index, digest);
reset();
} else if (method.equals(HttpMethod.HEAD)) {
head(request, index, digest);
} else if (method.equals(HttpMethod.PUT)) {
put(request, content, index, digest);
} else if (method.equals(HttpMethod.DELETE)) {
delete(request, index, digest);
} else {
simpleResponse(request, HttpResponseStatus.METHOD_NOT_ALLOWED);
}
}
Aggregations