@Override public String toString() { RestRequest request = getRawRequest(); StringBuilder outBuffer = new StringBuilder(); String endl = "\n"; outBuffer.append("R2Request Info").append(endl); outBuffer.append("type: RestRequest").append(endl); outBuffer.append("uri: ").append(request.getURI().toString()).append(endl); outBuffer.append("headers: "); request.getHeaders().forEach((k, v) -> outBuffer.append("[").append(k).append(":").append(v).append("] ") ); outBuffer.append(endl); ByteString entity = request.getEntity(); if (entity != null) { outBuffer.append("body: ").append(entity.asString(Charset.defaultCharset())).append(endl); } return outBuffer.toString(); } }
@Override public void onRequest(RestRequest restRequest, RequestContext requestContext, Map<String, String> wireAttrs) { String header = restRequest.getHeader(_headerName); Assert.assertEquals(header, _expectedValue); if (_entityLength > 0) { Assert.assertEquals(restRequest.getEntity().length(), _entityLength); } }
byte[] decompressedContent = encoding.getCompressor().inflate(req.getEntity().asInputStream()); Map<String, String> headers = new HashMap<String, String>(req.getHeaders()); headers.remove(HttpConstants.CONTENT_ENCODING);
public RestRequestBuilder(RestRequest request) { super(request); _entity = request.getEntity(); }
@Override public InputStream getInputStream() throws IOException { return request.getEntity().asInputStream(); }
@Override public String toString() { RestRequest request = getRawRequest(); StringBuilder outBuffer = new StringBuilder(); String endl = "\n"; outBuffer.append("R2Request Info").append(endl); outBuffer.append("type: RestRequest").append(endl); outBuffer.append("uri: ").append(request.getURI().toString()).append(endl); outBuffer.append("headers: "); request.getHeaders().forEach((k, v) -> outBuffer.append("[").append(k).append(":").append(v).append("] ") ); outBuffer.append(endl); ByteString entity = request.getEntity(); if (entity != null) { outBuffer.append("body: ").append(entity.asString(Charset.defaultCharset())).append(endl); } return outBuffer.toString(); } }
private void trace(final String method, final RestRequest request, final Map<String, String> wireAttrs, final RequestContext requestContext) { _log.debug(buildLogMessage(method, "request", formatRequest(request, request.getEntity().length()), wireAttrs, requestContext)); }
/** * Adapts a RestRequest to Netty's HttpRequest * @param request R2 rest request * @return Adapted HttpRequest. */ public static HttpRequest toNettyRequest(RestRequest request) throws Exception { HttpMethod nettyMethod = HttpMethod.valueOf(request.getMethod()); URL url = new URL(request.getURI().toString()); String path = url.getFile(); // RFC 2616, section 5.1.2: // Note that the absolute path cannot be empty; if none is present in the original URI, // it MUST be given as "/" (the server root). if (path.isEmpty()) { path = "/"; } ByteBuf content = Unpooled.wrappedBuffer(request.getEntity().asByteBuffer()); HttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, nettyMethod, path, content); nettyRequest.headers().set(HttpConstants.CONTENT_LENGTH, request.getEntity().length()); for (Map.Entry<String, String> entry : request.getHeaders().entrySet()) { nettyRequest.headers().set(entry.getKey(), entry.getValue()); } nettyRequest.headers().set(HttpHeaderNames.HOST, url.getAuthority()); nettyRequest.headers().set(HttpConstants.REQUEST_COOKIE_HEADER_NAME, request.getCookies()); return nettyRequest; }
@Override protected void encode(ChannelHandlerContext ctx, RestRequest request, List<Object> out) throws Exception { HttpMethod nettyMethod = HttpMethod.valueOf(request.getMethod()); URL url = new URL(request.getURI().toString()); String path = url.getFile(); // RFC 2616, section 5.1.2: // Note that the absolute path cannot be empty; if none is present in the original URI, // it MUST be given as "/" (the server root). if (path.isEmpty()) { path = "/"; } ByteString entity = request.getEntity(); ByteBuf content = Unpooled.wrappedBuffer(entity.asByteBuffer()); FullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, nettyMethod, path, content); for (Map.Entry<String, String> e : request.getHeaders().entrySet()) { nettyRequest.headers().set(e.getKey(), e.getValue()); } nettyRequest.headers().set(HttpHeaderNames.HOST, url.getAuthority()); nettyRequest.headers().set(HttpConstants.REQUEST_COOKIE_HEADER_NAME, request.getCookies()); nettyRequest.headers().set(HttpHeaderNames.CONTENT_LENGTH, entity.length()); out.add(nettyRequest); } }
/** * Create a StreamRequest based on the RestRequest * @param restRequest the rest request * @return the StreamRequest that's created based on rest request */ public static StreamRequest toStreamRequest(RestRequest restRequest) { StreamRequestBuilder builder = new StreamRequestBuilder(restRequest); return builder.build(EntityStreams.newEntityStream(new ByteStringWriter(restRequest.getEntity()))); }
ByteString entity = request.getEntity(); if (entity == null || entity.length() == 0)
query = request.getEntity().asString(Data.UTF_8_CHARSET); h.remove(HEADER_CONTENT_TYPE); h.remove(CONTENT_LENGTH);
protected void handleResourceRequest(RestRequest request, RoutingResult routingResult, Callback<RestResponse> callback) { DataMap entityDataMap = null; if (request.getEntity() != null && request.getEntity().length() > 0) { if (UnstructuredDataUtil.isUnstructuredDataRouting(routingResult)) { callback.onError(new RoutingException("Unstructured Data is not supported in non-streaming Rest.li server", HttpStatus.S_400_BAD_REQUEST.getCode())); return; } try { entityDataMap = DataMapUtils.readMapWithExceptions(request); } catch (IOException e) { callback.onError(new RoutingException("Cannot parse request entity", HttpStatus.S_400_BAD_REQUEST.getCode(), e)); } } handleResourceRequest(request, routingResult, entityDataMap, new RestLiToRestResponseCallbackAdapter(callback, routingResult)); }
if (future.isSuccess()) final ByteBuf data = Unpooled.wrappedBuffer(restRequest.getEntity().asByteBuffer()); LOG.debug("Sent HTTP/2 DATA frame, stream={}, end={}, data={}bytes, padding={}bytes", new Object[]{streamId, END_STREAM, data.readableBytes(), NO_PADDING});
if (capture.getRequest().getEntity().length() > 0)
byte[] decompressedContent = encoding.getCompressor().inflate(req.getEntity().asInputStream()); Map<String, String> headers = new HashMap<String, String>(req.getHeaders()); headers.remove(HttpConstants.CONTENT_ENCODING);