Response toFeignResponse(HttpResponse httpResponse) throws IOException { StatusLine statusLine = httpResponse.getStatusLine(); int statusCode = statusLine.getStatusCode(); String reason = statusLine.getReasonPhrase(); Map<String, Collection<String>> headers = new HashMap<String, Collection<String>>(); for (Header header : httpResponse.getAllHeaders()) { String name = header.getName(); String value = header.getValue(); Collection<String> headerValues = headers.get(name); if (headerValues == null) { headerValues = new ArrayList<String>(); headers.put(name, headerValues); } headerValues.add(value); } return Response.builder() .status(statusCode) .reason(reason) .headers(headers) .body(toFeignBody(httpResponse)) .build(); }
Response toFeignResponse(HttpResponse httpResponse, Request request) throws IOException { StatusLine statusLine = httpResponse.getStatusLine(); int statusCode = statusLine.getStatusCode(); String reason = statusLine.getReasonPhrase(); Map<String, Collection<String>> headers = new HashMap<String, Collection<String>>(); for (Header header : httpResponse.getAllHeaders()) { String name = header.getName(); String value = header.getValue(); Collection<String> headerValues = headers.get(name); if (headerValues == null) { headerValues = new ArrayList<String>(); headers.put(name, headerValues); } headerValues.add(value); } return Response.builder() .status(statusCode) .reason(reason) .headers(headers) .request(request) .body(toFeignBody(httpResponse)) .build(); }
private static feign.Response toFeignResponse(Response response, feign.Request request) throws IOException { return feign.Response.builder() .status(response.code()) .reason(response.message()) .request(request) .headers(toMap(response.headers())) .body(toBody(response.body())) .build(); }
@Override public Response execute(Request request, Request.Options options) throws IOException { HelloReply reply = new HelloReply(); reply.setMessage(message); String body = objectMapper.writeValueAsString(reply); return Response.builder() .body(body, StandardCharsets.UTF_8) .status(200) .headers(new HashMap<>()) .build(); } }
@Override public Mono<? extends Throwable> decode(String methodTag, ReactiveHttpResponse response) { return response.bodyData() .defaultIfEmpty(new byte[0]) .map(bodyData -> errorDecoder.decode(methodTag, Response.builder().status(response.status()) .reason(HttpStatus.getStatusText(response.status())) .headers(response.headers().entrySet() .stream() .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))) .body(bodyData).build())); } };
public MockClient add(RequestKey requestKey, int status, byte[] responseBody) { return add(requestKey, Response.builder() .status(status) .reason("Mocked") .headers(EMPTY_HEADERS) .body(responseBody)); }
@Override public Mono<? extends Throwable> decode(String methodKey, ClientResponse response) { return response .bodyToMono(ByteArrayResource.class) .map(ByteArrayResource::getByteArray).defaultIfEmpty(new byte[0]) .map(bodyData -> errorDecoder.decode(methodKey, Response.builder() .status(response.statusCode().value()) .reason(response.statusCode() .getReasonPhrase()) .headers(response.headers().asHttpHeaders() .entrySet().stream() .collect(Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue))) .body(bodyData).build())); }
private Response.Builder getResponseBuilder(Request request, RequestKey requestKey) { Response.Builder responseBuilder = null; for (RequestResponse requestResponse : responses) { if (requestResponse.requestKey.equalsExtended(requestKey)) { responseBuilder = requestResponse.responseBuilder; // Don't break here, last one should win to be compatible with previous // releases of this library! } } if (responseBuilder == null) { responseBuilder = Response.builder() .status(HttpURLConnection.HTTP_NOT_FOUND) .reason("Not mocker") .headers(request.headers()); } return responseBuilder; }
public RibbonResponseStatusCodeException(String serviceId, Response response, byte[] body, URI uri) { super(serviceId, response.status(), response, uri); this.response = Response.builder().body(new ByteArrayInputStream(body), body.length) .headers(response.headers()).reason(response.reason()) .status(response.status()).request(response.request()).build(); }
public RibbonResponseStatusCodeException(String serviceId, Response response, byte[] body, URI uri) { super(serviceId, response.status(), response, uri); this.response = Response.builder().body(new ByteArrayInputStream(body), body.length) .headers(response.headers()).reason(response.reason()) .status(response.status()).request(response.request()).build(); }
private static feign.Response toFeignResponse(ServiceResponse serviceResponse) { return feign.Response.builder() .body(toFeignBody(serviceResponse.getBody())) .headers(toFeignHeaders(serviceResponse.getHeaders())) .status(serviceResponse.getStatusCode()) .reason(serviceResponse.getReasonPhrase()) .build(); }