use of org.jboss.netty.handler.codec.http.HttpResponseStatus in project bagheera by mozilla-metrics.
the class SubmissionHandler method handlePost.
private void handlePost(MessageEvent e, BagheeraHttpRequest request) {
HttpResponseStatus status = BAD_REQUEST;
ChannelBuffer content = request.getContent();
String remoteIpAddress = HttpUtil.getRemoteAddr(request, ((InetSocketAddress) e.getChannel().getRemoteAddress()).getAddress().getHostAddress());
if (content.readable() && content.readableBytes() > 0) {
BagheeraMessage.Builder templateBuilder = BagheeraMessage.newBuilder();
setMessageFields(request, e, templateBuilder, System.currentTimeMillis(), false);
BagheeraMessage template = templateBuilder.buildPartial();
BagheeraMessage.Builder storeBuilder = BagheeraMessage.newBuilder(template);
storeBuilder.setPayload(ByteString.copyFrom(content.toByteBuffer()));
storeBuilder.setId(request.getId());
producer.send(storeBuilder.build());
if (request.containsHeader(HEADER_OBSOLETE_DOCUMENT)) {
handleObsoleteDocuments(request, remoteIpAddress, request.getHeaders(HEADER_OBSOLETE_DOCUMENT), template);
} else {
LOG.info("IP " + remoteIpAddress + " " + request.getNamespace() + " HTTP_PUT " + request.getId());
}
status = CREATED;
}
updateRequestMetrics(request.getNamespace(), request.getMethod().getName(), content.readableBytes());
writeResponse(status, e, request.getNamespace(), URI.create(request.getId()).toString());
}
Aggregations