use of org.xipki.ca.server.api.Rest in project xipki by xipki.
the class HttpRestServlet method service0.
private void service0(HttpServletRequest req, HttpServletResponse resp, boolean viaPost) throws IOException {
AuditServiceRegister auditServiceRegister = ServletHelper.getAuditServiceRegister();
if (auditServiceRegister == null) {
LOG.error("ServletHelper.auditServiceRegister not configured");
sendError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
ResponderManager responderManager = ServletHelper.getResponderManager();
if (responderManager == null) {
LOG.error("ServletHelper.responderManager not configured");
sendError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
AuditService auditService = auditServiceRegister.getAuditService();
AuditEvent event = new AuditEvent(new Date());
try {
Rest rest = responderManager.getRest();
String path = StringUtil.getRelativeRequestUri(req.getServletPath(), req.getRequestURI());
HttpRequestMetadataRetriever httpRetriever = new HttpRequestMetadataRetrieverImpl(req);
byte[] requestBytes = IoUtil.read(req.getInputStream());
RestResponse response = rest.service(path, event, requestBytes, httpRetriever);
resp.setStatus(response.getStatusCode());
if (resp.getContentType() != null) {
resp.setContentType(resp.getContentType());
}
for (String headerName : response.getHeaders().keySet()) {
resp.setHeader(headerName, response.getHeaders().get(headerName));
}
byte[] respBody = response.getBody();
if (respBody == null) {
resp.setContentLength(0);
} else {
resp.setContentLength(respBody.length);
resp.getOutputStream().write(respBody);
}
} finally {
event.finish();
auditService.logEvent(event);
}
}
use of org.xipki.ca.server.api.Rest 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);
}
}
Aggregations