Map<String, String> headers = new HashMap<String, String>(res.getHeaders()); headers.remove(HttpConstants.CONTENT_ENCODING); headers.put(HttpConstants.CONTENT_LENGTH, Integer.toString(inflated.length));
public String getErrorSource() { RestResponse response = getResponse(); return HeaderUtil.getErrorResponseHeaderValue(response.getHeaders()); }
protected void encode(ChannelHandlerContext ctx, RestResponse response, List<Object> out) throws Exception { final ByteString entity = response.getEntity(); ByteBuf content = Unpooled.wrappedBuffer(entity.asByteBuffer()); HttpResponse nettyResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(response.getStatus()), content); for (Map.Entry<String, String> e : response.getHeaders().entrySet()) { nettyResponse.headers().set(e.getKey(), e.getValue()); } nettyResponse.headers().set(HttpConstants.RESPONSE_COOKIE_HEADER_NAME, response.getCookies()); nettyResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, entity.length()); out.add(nettyResponse); } }
@Override protected void channelRead0(ChannelHandlerContext ctx, RestResponse response) throws Exception { final Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); headers.putAll(response.getHeaders()); final Map<String, String> wireAttrs = WireAttributeHelper.removeWireAttributes(headers); final RestResponse newResponse = new RestResponseBuilder(response) .unsafeSetHeaders(headers) .build(); // In general there should always be a callback to handle a received message, // but it could have been removed due to a previous exception or closure on the // channel TransportCallback<RestResponse> callback = ctx.channel().attr(CALLBACK_ATTR_KEY).getAndSet(null); if (callback != null) { LOG.debug("{}: handling a response", ctx.channel().remoteAddress()); callback.onResponse(TransportResponseImpl.success(newResponse, wireAttrs)); } else { LOG.debug("{}: dropped a response", ctx.channel().remoteAddress()); } ctx.fireChannelRead(response); }
Map<String, String> headers = restResponse.getHeaders(); for (Map.Entry<String, String> e : headers.entrySet())
public Response<T> decodeResponse(RestResponse restResponse) throws RestLiDecodingException { return createResponse(restResponse.getHeaders(), restResponse.getStatus(), restResponse.getEntity(), restResponse.getCookies()); }
private static ErrorResponse getErrorResponse(RestResponse response) throws RestLiDecodingException { ErrorResponse errorResponse = null; final String header = HeaderUtil.getErrorResponseHeaderValue(response.getHeaders()); if (header != null) { errorResponse = ERROR_DECODER.decodeResponse(response).getEntity(); } if (errorResponse == null) { errorResponse = new ErrorResponse(); } return errorResponse; } }
private static IndividualResponse toIndividualResponse(String id, RestResponse restResponse) throws MimeTypeParseException, IOException { IndividualResponse individualResponse = new IndividualResponse(); individualResponse.setStatus(restResponse.getStatus()); individualResponse.setHeaders(new StringMap(restResponse.getHeaders())); ByteString entity = restResponse.getEntity(); if (!entity.isEmpty()) { // TODO Avoid converting bytes to datamap here. Individual response should have only the bytes. individualResponse.setBody(new IndividualBody(DataMapConverter.bytesToDataMap(restResponse.getHeaders(), entity))); } return individualResponse; }
private static StreamResponse createStreamResponseWithAttachment(RestResponse structuredFirstPart, RestLiResponseAttachments attachments) { //Construct the StreamResponse and invoke the callback. The RestResponse entity should be the first part. //There may potentially be attachments included in the response. Note that unlike the client side request builders, //here it is possible to have a non-null attachment list with 0 attachments due to the way the builder in //RestLiResponseAttachments works. Therefore we have to make sure its a non zero size as well. final ByteStringWriter firstPartWriter = new ByteStringWriter(structuredFirstPart.getEntity()); final MultiPartMIMEWriter multiPartMIMEWriter = AttachmentUtils.createMultiPartMIMEWriter(firstPartWriter, structuredFirstPart.getHeader(RestConstants.HEADER_CONTENT_TYPE), attachments.getMultiPartMimeWriterBuilder()); //Ensure that any headers or cookies from the RestResponse make into the outgoing StreamResponse. The exception //of course being the Content-Type header which will be overridden by MultiPartMIMEStreamResponseFactory. return MultiPartMIMEStreamResponseFactory.generateMultiPartMIMEStreamResponse(AttachmentUtils.RESTLI_MULTIPART_SUBTYPE, multiPartMIMEWriter, Collections.emptyMap(), structuredFirstPart.getHeaders(), structuredFirstPart.getStatus(), structuredFirstPart.getCookies()); }
final String header = HeaderUtil.getErrorResponseHeaderValue(response.getHeaders());
Map<String, String> headers = new HashMap<String, String>(res.getHeaders()); headers.remove(HttpConstants.CONTENT_ENCODING); headers.put(HttpConstants.CONTENT_LENGTH, Integer.toString(inflated.length));
@SuppressWarnings("unchecked") private Response<T> createResponseFromError(RestLiResponseException restLiResponseException) throws RemoteInvocationException { Response<T> response = null; // If the exception contains a decoded response, we use it. Otherwise we do manual response // creation which will not have an entity. if (restLiResponseException.hasDecodedResponse()) { response = new ResponseImpl<T>( (Response<T>) restLiResponseException.getDecodedResponse(), restLiResponseException); } else { response = new ResponseImpl<T>( restLiResponseException.getStatus(), restLiResponseException.getResponse().getHeaders(), CookieUtil.decodeSetCookies(restLiResponseException.getResponse().getCookies()), restLiResponseException); } return response; }