@Override public Exception decode(String methodKey, Response response) { if (response.status() == HttpStatus.NOT_FOUND.value()) { return new ReservationExpireException("tcc reservation expired", response); } if (response.status() == HttpStatus.CONFLICT.value()) { String conflictionDetails; try { conflictionDetails = IOUtils.toString(response.body().asInputStream(), Charsets.UTF_8); } catch (IOException e) { LOGGER.error("read conflict response body exception. {}", e.toString()); conflictionDetails = "{}"; } return new PartialConfirmException(conflictionDetails); } return FeignException.errorStatus(methodKey, response); } }
@Override public Object getPayload() throws ClientException { return this.response.body(); }
@Override public void close() { try { this.response.body().close(); } catch (IOException ex) { // Ignore exception on close... } }
@Override public void close() { try { this.response.body().close(); } catch (final IOException ex) { // Ignore exception on close... log.debug("error close feign response body.", ex); } }
@Override public void close() { try { this.response.body().close(); } catch (IOException ex) { // Ignore exception on close... } }
default Optional<String> getAgentSandboxFileAsString(final String agentId, final String path) throws DCOSException { final feign.Response response = getAgentSandboxFile(agentId, path); if (response.status() == 404 || response.body() == null) { return Optional.empty(); } try (final Reader reader = response.body().asReader()) { return Optional.of(IOUtils.toString(reader)); } catch (IOException e) { return Optional.empty(); } }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { if (type.equals(InputStream.class)) { byte[] body = response.body() != null ? Util.toByteArray(response.body().asInputStream()) : new byte[0]; return new ByteArrayInputStream(body); } else { return delegate.decode(response, type); } } }
static String extractContent(Response response) { ByteArrayOutputStream output = new ByteArrayOutputStream(); try{ StreamUtils.copy(response.body().asInputStream(), output); } catch (FileNotFoundException ex) { log.debug("ExtractContent error:", ex); } catch (Exception ex) { log.error("ExtractContent error:", ex); } return new String(output.toByteArray()); }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { if (type.equals(InputStream.class)) { byte[] body = response.body() != null ? Util.toByteArray(response.body().asInputStream()) : new byte[0]; return new ByteArrayInputStream(body); } else { return delegate.decode(response, type); } } }
@Override public Object decode(final Response response, final Type type) throws IOException, FeignException { if (JsonObject.class == type) { final String content = Ut.ioString(response.body().asInputStream()); return new JsonObject(content); } return null; } }
private String getResponseBodyString(Response response) { try { return StreamUtils.copyToString(response.body().asInputStream(), StandardCharsets.UTF_8); } catch (IOException e) { return "error read response body. " + e.getMessage(); } } }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { if (type.equals(InputStream.class)) { byte[] body = Util.toByteArray(response.body().asInputStream()); return new ByteArrayInputStream(body); } else { return delegate.decode(response, type); } } }
@Override public Object decode(Response response, Type type) throws IOException { Response.Body body = response.body(); if (body == null) { return null; } if (String.class.equals(type)) { return Util.toString(body.asReader()); } throw new DecodeException(format("%s is not a type supported by this decoder.", type)); } }
public static FeignException errorStatus(String methodKey, Response response) { String message = format("status %s reading %s", response.status(), methodKey); try { if (response.body() != null) { String body = Util.toString(response.body().asReader()); message += "; content:\n" + body; } } catch (IOException ignored) { // NOPMD } return new FeignException(response.status(), message); }
@Override public Object decode(Response response, Type type) throws IOException { if (response.status() == 404) return Util.emptyValueOf(type); if (response.body() == null) return null; if (byte[].class.equals(type)) { return Util.toByteArray(response.body().asInputStream()); } return super.decode(response, type); } }
private static byte[] responseBody(final feign.Response response) { try { return StreamUtils.copyToByteArray(response.body().asInputStream()); } catch (final Exception wrapped) { log.info("Failed to process response body.", wrapped); throw new DecodeException("Failed to process response body.", wrapped); } }
@Override public Exception decode(String methodKey, Response response) { String details; try { details = IOUtils.toString(response.body().asInputStream(), "UTF-8"); } catch (NullPointerException | IOException e) { details = "Unable to read response body"; } return new DCOSException(response.status(), response.reason(), methodKey, details); } }