feign.Response.request()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中feign.Response.request方法的一些代码示例,展示了Response.request的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.request方法的具体详情如下:
包路径:feign.Response
类名称:Response
方法名:request

Response.request介绍

暂无

代码示例

代码示例来源:origin: liuyangming/ByteTCC

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);
}

代码示例来源:origin: liuyangming/ByteTCC

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);
}

代码示例来源:origin: de.digitalcollections.cudami/dc-cudami-client-openfeign

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();
}

代码示例来源:origin: liuyangming/ByteJTA

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);
}

代码示例来源:origin: liuyangming/ByteJTA

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);
}

代码示例来源:origin: twitch4j/twitch4j

.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())

代码示例来源:origin: twitch4j/twitch4j

.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())

代码示例来源:origin: twitch4j/twitch4j

.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())

代码示例来源:origin: spring-cloud/spring-cloud-openfeign

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();
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-openfeign-core

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();
}

相关文章