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 (responderManager == null) {
LOG.error("responderManager in servlet is not configured");
return createErrorResponse(version, HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
String caName = null;
X509CaCmpResponder responder = null;
if (servletUri.getPath().length() > 1) {
// skip the first char which is always '/'
String caAlias = servletUri.getPath().substring(1);
caName = responderManager.getCaNameForAlias(caAlias);
if (caName == null) {
caName = caAlias.toLowerCase();
}
responder = responderManager.getX509CaResponder(caName);
}
if (caName == null || responder == null || !responder.isOnService()) {
String auditMessage;
if (caName == null) {
auditMessage = "no CA is specified";
} else if (responder == null) {
auditMessage = "unknown CA '" + caName + "'";
} else {
auditMessage = "CA '" + caName + "' is out of service";
}
LOG.warn(auditMessage);
return createErrorResponse(version, HttpResponseStatus.NOT_FOUND);
}
HealthCheckResult healthResult = responder.healthCheck();
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 xipki by xipki.
the class HttpRestServlet method service.
@Override
public FullHttpResponse service(FullHttpRequest request, ServletURI servletUri, SSLSession sslSession, SslReverseProxyMode sslReverseProxyMode) {
HttpVersion version = request.protocolVersion();
HttpMethod method = request.method();
if (method != HttpMethod.POST && method != HttpMethod.GET) {
return createErrorResponse(version, HttpResponseStatus.METHOD_NOT_ALLOWED);
}
AuditEvent event = new AuditEvent(new Date());
try {
Rest rest = responderManager.getRest();
HttpRequestMetadataRetriever httpRetriever = new HttpRequestMetadataRetrieverImpl(request, servletUri, sslSession, sslReverseProxyMode);
byte[] requestBytes = readContent(request);
RestResponse response = rest.service(servletUri.getPath(), event, requestBytes, httpRetriever);
HttpResponseStatus status = HttpResponseStatus.valueOf(response.getStatusCode());
FullHttpResponse resp = createResponse(version, status, response.getContentType(), response.getBody());
for (String headerName : response.getHeaders().keySet()) {
resp.headers().add(headerName, response.getHeaders().get(headerName));
}
return resp;
} finally {
event.finish();
auditServiceRegister.getAuditService().logEvent(event);
}
}
use of io.netty.handler.codec.http.HttpMethod in project cdap by caskdata.
the class RouterPathTest method testRouterFlowletInstancesLookUp.
@Test
public void testRouterFlowletInstancesLookUp() throws Exception {
String path = "/v3/namespaces/default//apps/WordCount/flows/WordCountFlow/flowlets/StreamSource/instances";
HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("PUT"), path);
RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, path, httpRequest);
Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
}
use of io.netty.handler.codec.http.HttpMethod in project cdap by caskdata.
the class RouterPathTest method testRouterV3PathLookup.
@Test
public void testRouterV3PathLookup() {
final String namespacePath = "/v3////namespace/////";
HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), namespacePath);
RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, namespacePath, httpRequest);
Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
}
use of io.netty.handler.codec.http.HttpMethod in project cdap by caskdata.
the class RouterPathTest method testRouterWorkFlowPathLookUp.
@Test
public void testRouterWorkFlowPathLookUp() throws Exception {
String path = "/v3/namespaces/default/apps///PurchaseHistory///workflows/PurchaseHistoryWorkflow/status";
HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), path);
RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, path, httpRequest);
Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
}
Aggregations