feign.Request类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(233)

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

Request介绍

[英]An immutable request to an http server.
[中]对http服务器的不可变请求。

代码示例

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

private Request getModifyRequest(Request request) {
  String xid = RootContext.getXID();
  if (StringUtils.isEmpty(xid)) {
    return request;
  }
  Map<String, Collection<String>> headers = new HashMap<>();
  headers.putAll(request.headers());
  List<String> fescarXid = new ArrayList<>();
  fescarXid.add(xid);
  headers.put(RootContext.KEY_XID, fescarXid);
  return Request.create(request.method(), request.url(), headers, request.body(),
      request.charset());
}

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

private Request modifiedRequest(Request request,
    Map<String, Collection<String>> headers) {
  String method = request.method();
  String url = request.url();
  byte[] body = request.body();
  Charset charset = request.charset();
  return Request.create(method, url, headers, body, charset);
}

代码示例来源:origin: io.github.openfeign/feign-okhttp

static Request toOkHttpRequest(feign.Request input) {
 Request.Builder requestBuilder = new Request.Builder();
 requestBuilder.url(input.url());
 for (String field : input.headers().keySet()) {
  if (field.equalsIgnoreCase("Accept")) {
   hasAcceptHeader = true;
  for (String value : input.headers().get(field)) {
   requestBuilder.addHeader(field, value);
   if (field.equalsIgnoreCase("Content-Type")) {
    mediaType = MediaType.parse(value);
    if (input.charset() != null) {
     mediaType.charset(input.charset());
 byte[] inputBody = input.body();
 boolean isMethodWithBody =
   HttpMethod.POST == input.httpMethod() || HttpMethod.PUT == input.httpMethod()
     || HttpMethod.PATCH == input.httpMethod();
 if (isMethodWithBody) {
  requestBuilder.removeHeader("Content-Type");
 requestBuilder.method(input.httpMethod().name(), body);
 return requestBuilder.build();

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

private String getHeaderValue(Request req, String headerName) {
  Map<String, Collection<String>> headers = req.headers();
  Collection<String> values = headers.get(headerName);
  String value = null;
  if (values != null && values.isEmpty() == false) {
    String[] array = new String[values.size()];
    values.toArray(array);
    value = array[0];
  }
  return value;
}

代码示例来源: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-sleuth

@Override
public String url(Request request) {
  return request.url();
}

代码示例来源:origin: com.netflix.feign/feign-core

static FeignException errorReading(Request request, Response ignored, IOException cause) {
 return new FeignException(
   format("%s reading %s %s", cause.getMessage(), request.method(), request.url()),
   cause);
}

代码示例来源:origin: OpenFeign/feign-vertx

/**
  * Creates {@link HttpClientRequest} (Vert.x) from {@link Request} (feign).
  *
  * @param request  feign request
  * @return fully formed HttpClientRequest
  */
 private HttpClientRequest makeHttpClientRequest(final Request request)
   throws MalformedURLException {
  final URL url = new URL(request.url());
  final int port = url.getPort() > -1
    ? url.getPort()
    : HttpClientOptions.DEFAULT_DEFAULT_PORT;
  final String host = url.getHost();
  final String requestUri = url.getFile();

  HttpClientRequest httpClientRequest = httpClient.request(
    HttpMethod.valueOf(request.method()),
    port,
    host,
    requestUri);

  /* Add headers to request */
  for (final Map.Entry<String, Collection<String>> header : request.headers().entrySet()) {
   httpClientRequest = httpClientRequest.putHeader(header.getKey(), header.getValue());
  }

  return httpClientRequest;
 }
}

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

@Override
  public Response execute(Request request, Request.Options options) throws IOException {
    URI uri = URI.create(request.url());
    BambooRequest.Builder builder = BambooRequest.builder()
        .serviceId(uri.getHost())
        .uri(uri.getPath())
        .ip(RequestIpKeeper.getRequestIp())
        .addMultiParams(WebUtils.getQueryParams(uri.getQuery()));
    if(bambooProperties.getBambooRequest().isLoadBody()){
      builder.requestBody(request.body());
    }

    request.headers().entrySet().forEach(entry ->{
      for (String v : entry.getValue()) {
        builder.addHeader(entry.getKey(), v);
      }
    });

    ConnectPointContext connectPointContext = ConnectPointContext.builder().bambooRequest(builder.build()).build();

    try {
      BambooAppContext.getBambooRibbonConnectionPoint().executeConnectPoint(connectPointContext);
      return delegate.execute(request, options);
    }finally {
      BambooAppContext.getBambooRibbonConnectionPoint().shutdownconnectPoint();
    }
  }
}

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

@Override
  public void apply(RequestTemplate template) {
    
    try {
      template.header( StarterConstants.TRACE_ID_KEY, TraceIdHelper.getTraceId() );
      template.header( StarterConstants.IP_HEADER_NAME, TraceIdHelper.getRemoteIp() );
      
      String bodyStr = "";
      byte[] body = template.body();
      if ( null != body && body.length > 0 ) {
        bodyStr = new String( body );
      }
      LOGGER.info( "traceId:{}, request -> path:{}, headers:{}, querys:{}, body:{}",
          TraceIdHelper.getTraceId(), template.request().url(), JSON.toJSONString(template.request().headers()),
          JSON.toJSONString(template.queries()), bodyStr );            
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

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

private Request toRequest(Request request) {
  Map<String, Collection<String>> headers = new LinkedHashMap<>(
      request.headers());
  return Request.create(request.httpMethod(), getUri().toASCIIString(), headers,
      request.requestBody());
}

代码示例来源:origin: wso2/msf4j

private ContentType getContentType(Request request) {
  ContentType contentType = ContentType.DEFAULT_TEXT;
  for (Map.Entry<String, Collection<String>> entry : request.headers().entrySet()) {
    if (entry.getKey().equalsIgnoreCase("Content-Type")) {
      Collection values = entry.getValue();
      if (values != null && !values.isEmpty()) {
        contentType = ContentType.create(entry.getValue().iterator().next(), request.charset());
        break;
      }
    }
  }
  return contentType;
}

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

@Override
public String method(Request request) {
  return request.method();
}

代码示例来源:origin: com.ofg/micro-infra-spring-base

static String extractContent(Request request) {
  return request.body() == null ? "" : new String(request.body());
}

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

@Override
public HttpMethod getMethod() {
  return HttpMethod
      .resolve(RibbonRequest.this.toRequest().httpMethod().name());
}

代码示例来源:origin: com.netflix.feign/feign-core

public Request request() {
 Map<String, Collection<String>> safeCopy = new LinkedHashMap<String, Collection<String>>();
 safeCopy.putAll(headers);
 return Request.create(
   method,
   new StringBuilder(url).append(queryLine()).toString(),
   Collections.unmodifiableMap(safeCopy),
   body, charset
 );
}

代码示例来源:origin: io.github.openfeign/feign-httpclient

HttpUriRequest toHttpUriRequest(Request request, Request.Options options)
  throws URISyntaxException {
 RequestBuilder requestBuilder = RequestBuilder.create(request.httpMethod().name());
 requestBuilder.setConfig(requestConfig);
 URI uri = new URIBuilder(request.url()).build();
 for (Map.Entry<String, Collection<String>> headerEntry : request.headers().entrySet()) {
  String headerName = headerEntry.getKey();
  if (headerName.equalsIgnoreCase(ACCEPT_HEADER_NAME)) {
 if (request.body() != null) {
  HttpEntity entity = null;
  if (request.charset() != null) {
   ContentType contentType = getContentType(request);
   String content = new String(request.body(), request.charset());
   entity = new StringEntity(content, contentType);
  } else {
   entity = new ByteArrayEntity(request.body());

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

private String getHeaderValue(Request req, String headerName) {
  Map<String, Collection<String>> headers = req.headers();
  Collection<String> values = headers.get(headerName);
  String value = null;
  if (values != null && values.isEmpty() == false) {
    String[] array = new String[values.size()];
    values.toArray(array);
    value = array[0];
  }
  return value;
}

代码示例来源: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: org.springframework.cloud/spring-cloud-sleuth-core

@Override
public String url(Request request) {
  return request.url();
}

相关文章