public Object decode(Response resp, Type type) throws IOException, DecodeException, FeignException { Request request = resp.request(); String reqTransactionStr = this.getHeaderValue(request, HEADER_TRANCACTION_KEY); String reqPropagationStr = this.getHeaderValue(request, HEADER_PROPAGATION_KEY); String respTransactionStr = this.getHeaderValue(resp, HEADER_TRANCACTION_KEY); String respPropagationStr = this.getHeaderValue(resp, HEADER_PROPAGATION_KEY); if (StringUtils.isBlank(reqTransactionStr)) { return this.delegate.decode(resp, type); } else if (StringUtils.isBlank(reqPropagationStr)) { return this.delegate.decode(resp, type); } try { String transactionStr = StringUtils.isBlank(respTransactionStr) ? reqTransactionStr : respTransactionStr; String propagationStr = StringUtils.isBlank(respPropagationStr) ? reqPropagationStr : respPropagationStr; byte[] byteArray = Base64.getDecoder().decode(transactionStr); // ByteUtils.stringToByteArray(transactionStr); TransactionContext transactionContext = (TransactionContext) SerializeUtils.deserializeObject(byteArray); SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance(); RemoteCoordinator remoteCoordinator = beanRegistry.getConsumeCoordinator(propagationStr); TransactionResponseImpl response = new TransactionResponseImpl(); response.setTransactionContext(transactionContext); response.setSourceTransactionCoordinator(remoteCoordinator); } catch (IOException ex) { logger.error("Error occurred while decoding response({})!", resp, ex); } return this.delegate.decode(resp, type); }
public Exception decode(String methodKey, Response resp) { Request request = resp.request(); String reqTransactionStr = this.getHeaderValue(request, HEADER_TRANCACTION_KEY); String reqPropagationStr = this.getHeaderValue(request, HEADER_PROPAGATION_KEY); String respTransactionStr = this.getHeaderValue(resp, HEADER_TRANCACTION_KEY); String respPropagationStr = this.getHeaderValue(resp, HEADER_PROPAGATION_KEY); if (StringUtils.isBlank(reqTransactionStr)) { return this.delegate.decode(methodKey, resp); } else if (StringUtils.isBlank(reqPropagationStr)) { return this.delegate.decode(methodKey, resp); } // int status = resp.status(); try { String transactionStr = StringUtils.isBlank(respTransactionStr) ? reqTransactionStr : respTransactionStr; String propagationStr = StringUtils.isBlank(respPropagationStr) ? reqPropagationStr : respPropagationStr; byte[] byteArray = Base64.getDecoder().decode(transactionStr); // ByteUtils.stringToByteArray(transactionStr); TransactionContext transactionContext = (TransactionContext) SerializeUtils.deserializeObject(byteArray); SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance(); RemoteCoordinator remoteCoordinator = beanRegistry.getConsumeCoordinator(propagationStr); TransactionResponseImpl response = new TransactionResponseImpl(); response.setTransactionContext(transactionContext); response.setSourceTransactionCoordinator(remoteCoordinator); } catch (IOException ex) { logger.error("Error occurred while decoding response: methodKey= {}, response= {}", methodKey, resp, ex); } return this.delegate.decode(methodKey, resp); }
public HttpException(String methodKey, Response response) { super(String.format("Got %d for backend call %s.%n⤷ %s", response.status(), methodKey, response.request())); if (response.body() != null) { try { try (InputStreamReader ir = new InputStreamReader(response.body().asInputStream())) { errorMessage = new BufferedReader(ir).lines().parallel().collect(Collectors.joining(" ")); errorMessage = errorMessage.replaceFirst("^\"", "").replaceFirst("\"$", ""); } } catch (IOException e) { errorMessage = "Cannot read error message because of " + e.getMessage(); } } this.statuscode = response.status(); }
public Object decode(Response resp, Type type) throws IOException, DecodeException, FeignException { Request request = resp.request(); String reqTransactionStr = this.getHeaderValue(request, HEADER_TRANCACTION_KEY); String reqPropagationStr = this.getHeaderValue(request, HEADER_PROPAGATION_KEY); String respTransactionStr = this.getHeaderValue(resp, HEADER_TRANCACTION_KEY); String respPropagationStr = this.getHeaderValue(resp, HEADER_PROPAGATION_KEY); if (StringUtils.isBlank(reqTransactionStr)) { return this.delegate.decode(resp, type); } else if (StringUtils.isBlank(reqPropagationStr)) { return this.delegate.decode(resp, type); } try { String transactionStr = StringUtils.isBlank(respTransactionStr) ? reqTransactionStr : respTransactionStr; String propagationStr = StringUtils.isBlank(respPropagationStr) ? reqPropagationStr : respPropagationStr; byte[] byteArray = Base64.getDecoder().decode(transactionStr); // ByteUtils.stringToByteArray(transactionStr); TransactionContext transactionContext = (TransactionContext) SerializeUtils.deserializeObject(byteArray); SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance(); RemoteCoordinator remoteCoordinator = beanRegistry.getConsumeCoordinator(propagationStr); TransactionResponseImpl response = new TransactionResponseImpl(); response.setTransactionContext(transactionContext); response.setSourceTransactionCoordinator(remoteCoordinator); } catch (IOException ex) { logger.error("Error occurred while decoding response({})!", resp, ex); } return this.delegate.decode(resp, type); }
public Exception decode(String methodKey, Response resp) { Request request = resp.request(); String reqTransactionStr = this.getHeaderValue(request, HEADER_TRANCACTION_KEY); String reqPropagationStr = this.getHeaderValue(request, HEADER_PROPAGATION_KEY); String respTransactionStr = this.getHeaderValue(resp, HEADER_TRANCACTION_KEY); String respPropagationStr = this.getHeaderValue(resp, HEADER_PROPAGATION_KEY); if (StringUtils.isBlank(reqTransactionStr)) { return this.delegate.decode(methodKey, resp); } else if (StringUtils.isBlank(reqPropagationStr)) { return this.delegate.decode(methodKey, resp); } // int status = resp.status(); try { String transactionStr = StringUtils.isBlank(respTransactionStr) ? reqTransactionStr : respTransactionStr; String propagationStr = StringUtils.isBlank(respPropagationStr) ? reqPropagationStr : respPropagationStr; byte[] byteArray = Base64.getDecoder().decode(transactionStr); // ByteUtils.stringToByteArray(transactionStr); TransactionContext transactionContext = (TransactionContext) SerializeUtils.deserializeObject(byteArray); SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance(); RemoteCoordinator remoteCoordinator = beanRegistry.getConsumeCoordinator(propagationStr); TransactionResponseImpl response = new TransactionResponseImpl(); response.setTransactionContext(transactionContext); response.setSourceTransactionCoordinator(remoteCoordinator); } catch (IOException ex) { logger.error("Error occurred while decoding response: methodKey= {}, response= {}", methodKey, resp, ex); } return this.delegate.decode(methodKey, resp); }
.addContextValue("requestUrl", response.request().url()) .addContextValue("requestMethod", response.request().httpMethod()) .addContextValue("requestHeaders", response.request().headers().entrySet().toString()) .addContextValue("responseBody", responseBody); } else if (response.status() == 404) { throw new NotFoundException() .addContextValue("requestUrl", response.request().url()) .addContextValue("requestMethod", response.request().httpMethod()) .addContextValue("requestHeaders", response.request().headers().entrySet().toString()) .addContextValue("responseBody", responseBody); } else if (response.status() == 503) { .addContextValue("requestUrl", response.request().url()) .addContextValue("requestMethod", response.request().httpMethod()) .addContextValue("requestHeaders", response.request().headers().entrySet().toString()) .addContextValue("responseBody", responseBody) .addContextValue("errorType", helixError.getError())
.addContextValue("requestUrl", response.request().url()) .addContextValue("requestMethod", response.request().httpMethod()) .addContextValue("requestHeaders", response.request().headers().entrySet().toString()) .addContextValue("responseBody", responseBody); } else if (response.status() == 404) { throw new NotFoundException() .addContextValue("requestUrl", response.request().url()) .addContextValue("requestMethod", response.request().httpMethod()) .addContextValue("requestHeaders", response.request().headers().entrySet().toString()) .addContextValue("responseBody", responseBody); } else if (response.status() == 503) { .addContextValue("requestUrl", response.request().url()) .addContextValue("requestMethod", response.request().httpMethod()) .addContextValue("requestHeaders", response.request().headers().entrySet().toString()) .addContextValue("responseBody", responseBody) .addContextValue("errorType", error.getError())
.addContextValue("requestUrl", response.request().url()) .addContextValue("requestMethod", response.request().httpMethod()) .addContextValue("requestHeaders", response.request().headers().entrySet().toString()) .addContextValue("responseBody", responseBody); } else if (response.status() == 404) { throw new NotFoundException() .addContextValue("requestUrl", response.request().url()) .addContextValue("requestMethod", response.request().httpMethod()) .addContextValue("requestHeaders", response.request().headers().entrySet().toString()) .addContextValue("responseBody", responseBody); } else if (response.status() == 503) { .addContextValue("requestUrl", response.request().url()) .addContextValue("requestMethod", response.request().httpMethod()) .addContextValue("requestHeaders", response.request().headers().entrySet().toString()) .addContextValue("responseBody", responseBody) .addContextValue("errorType", error.getError())
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(); }