@Test void testConvertWithContent() throws IOException { HTTPResponse gaeResponse = createMock(HTTPResponse.class); expect(gaeResponse.getResponseCode()).andReturn(200); List<HTTPHeader> headers = Lists.newArrayList(); headers.add(new HTTPHeader(HttpHeaders.CONTENT_TYPE, "text/xml")); expect(gaeResponse.getHeaders()).andReturn(headers); expect(gaeResponse.getContent()).andReturn("hello".getBytes()).atLeastOnce(); replay(gaeResponse); HttpResponse response = req.apply(gaeResponse); assertEquals(response.getStatusCode(), 200); assertEquals(Strings2.toStringAndClose(response.getPayload().openStream()), "hello"); assertEquals(response.getHeaders().size(), 0); assertEquals(response.getPayload().getContentMetadata().getContentType(), "text/xml"); }
@Override public HttpResponse apply(HTTPResponse gaeResponse) { Payload payload = gaeResponse.getContent() != null ? Payloads.newByteArrayPayload(gaeResponse.getContent()) : null; Multimap<String, String> headers = LinkedHashMultimap.create(); String message = null; for (HTTPHeader header : gaeResponse.getHeaders()) { if (header.getName() == null) message = header.getValue(); else headers.put(header.getName(), header.getValue()); } if (payload != null) { contentMetadataCodec.fromHeaders(payload.getContentMetadata(), headers); } return HttpResponse.builder() .statusCode(gaeResponse.getResponseCode()) .message(message) .payload(payload) .headers(filterOutContentHeaders(headers)).build(); }
ConvertToJcloudsResponse implements Function<HTTPResponse, HttpResponse> { @Override public HttpResponse apply(HTTPResponse gaeResponse) { Payload payload = gaeResponse.getContent() != null ? Payloads.newByteArrayPayload(gaeResponse.getContent()) : null; Multimap<String, String> headers = LinkedHashMultimap.create(); String message = null; for (HTTPHeader header : gaeResponse.getHeaders()) { if (header.getName() == null) message = header.getValue(); else headers.put(header.getName(), header.getValue()); } if (payload != null) { contentMetadataCodec.fromHeaders(payload.getContentMetadata(), headers); } return HttpResponse.builder() .statusCode(gaeResponse.getResponseCode()) .message(message) .payload(payload) .headers(filterOutContentHeaders(headers)).build(); } }
ConvertToJcloudsResponse implements Function<HTTPResponse, HttpResponse> { @Override public HttpResponse apply(HTTPResponse gaeResponse) { Payload payload = gaeResponse.getContent() != null ? Payloads.newByteArrayPayload(gaeResponse.getContent()) : null; Multimap<String, String> headers = LinkedHashMultimap.create(); String message = null; for (HTTPHeader header : gaeResponse.getHeaders()) { if (header.getName() == null) message = header.getValue(); else headers.put(header.getName(), header.getValue()); } if (payload != null) { contentMetadataCodec.fromHeaders(payload.getContentMetadata(), headers); } return HttpResponse.builder() .statusCode(gaeResponse.getResponseCode()) .message(message) .payload(payload) .headers(filterOutContentHeaders(headers)).build(); } @Inject  ConvertToJcloudsResponse(ContentMetadataCodec contentMetadataCodec); }
ConvertToJcloudsResponse implements Function<HTTPResponse, HttpResponse> { @Override public HttpResponse apply(HTTPResponse gaeResponse) { Payload payload = gaeResponse.getContent() != null ? Payloads.newByteArrayPayload(gaeResponse.getContent()) : null; Multimap<String, String> headers = LinkedHashMultimap.create(); String message = null; for (HTTPHeader header : gaeResponse.getHeaders()) { if (header.getName() == null) message = header.getValue(); else headers.put(header.getName(), header.getValue()); } if (payload != null) { contentMetadataCodec.fromHeaders(payload.getContentMetadata(), headers); } return HttpResponse.builder() .statusCode(gaeResponse.getResponseCode()) .message(message) .payload(payload) .headers(filterOutContentHeaders(headers)).build(); } @Inject  ConvertToJcloudsResponse(ContentMetadataCodec contentMetadataCodec); @Override HttpResponse apply(HTTPResponse gaeResponse); }
ConvertToJcloudsResponse implements Function<HTTPResponse, HttpResponse> { @Override public HttpResponse apply(HTTPResponse gaeResponse) { Payload payload = gaeResponse.getContent() != null ? Payloads.newByteArrayPayload(gaeResponse.getContent()) : null; Multimap<String, String> headers = LinkedHashMultimap.create(); String message = null; for (HTTPHeader header : gaeResponse.getHeaders()) { if (header.getName() == null) message = header.getValue(); else headers.put(header.getName(), header.getValue()); } if (payload != null) { contentMetadataCodec.fromHeaders(payload.getContentMetadata(), headers); } return HttpResponse.builder() .statusCode(gaeResponse.getResponseCode()) .message(message) .payload(payload) .headers(filterOutContentHeaders(headers)).build(); } @Inject  ConvertToJcloudsResponse(ContentMetadataCodec contentMetadataCodec); @Override HttpResponse apply(HTTPResponse gaeResponse);  }