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

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

本文整理了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

  1. private Request getModifyRequest(Request request) {
  2. String xid = RootContext.getXID();
  3. if (StringUtils.isEmpty(xid)) {
  4. return request;
  5. }
  6. Map<String, Collection<String>> headers = new HashMap<>();
  7. headers.putAll(request.headers());
  8. List<String> fescarXid = new ArrayList<>();
  9. fescarXid.add(xid);
  10. headers.put(RootContext.KEY_XID, fescarXid);
  11. return Request.create(request.method(), request.url(), headers, request.body(),
  12. request.charset());
  13. }

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

  1. private Request modifiedRequest(Request request,
  2. Map<String, Collection<String>> headers) {
  3. String method = request.method();
  4. String url = request.url();
  5. byte[] body = request.body();
  6. Charset charset = request.charset();
  7. return Request.create(method, url, headers, body, charset);
  8. }

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

  1. static Request toOkHttpRequest(feign.Request input) {
  2. Request.Builder requestBuilder = new Request.Builder();
  3. requestBuilder.url(input.url());
  4. for (String field : input.headers().keySet()) {
  5. if (field.equalsIgnoreCase("Accept")) {
  6. hasAcceptHeader = true;
  7. for (String value : input.headers().get(field)) {
  8. requestBuilder.addHeader(field, value);
  9. if (field.equalsIgnoreCase("Content-Type")) {
  10. mediaType = MediaType.parse(value);
  11. if (input.charset() != null) {
  12. mediaType.charset(input.charset());
  13. byte[] inputBody = input.body();
  14. boolean isMethodWithBody =
  15. HttpMethod.POST == input.httpMethod() || HttpMethod.PUT == input.httpMethod()
  16. || HttpMethod.PATCH == input.httpMethod();
  17. if (isMethodWithBody) {
  18. requestBuilder.removeHeader("Content-Type");
  19. requestBuilder.method(input.httpMethod().name(), body);
  20. return requestBuilder.build();

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

  1. private String getHeaderValue(Request req, String headerName) {
  2. Map<String, Collection<String>> headers = req.headers();
  3. Collection<String> values = headers.get(headerName);
  4. String value = null;
  5. if (values != null && values.isEmpty() == false) {
  6. String[] array = new String[values.size()];
  7. values.toArray(array);
  8. value = array[0];
  9. }
  10. return value;
  11. }

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

  1. .addContextValue("requestUrl", response.request().url())
  2. .addContextValue("requestMethod", response.request().httpMethod())
  3. .addContextValue("requestHeaders", response.request().headers().entrySet().toString())
  4. .addContextValue("responseBody", responseBody);
  5. } else if (response.status() == 404) {
  6. throw new NotFoundException()
  7. .addContextValue("requestUrl", response.request().url())
  8. .addContextValue("requestMethod", response.request().httpMethod())
  9. .addContextValue("requestHeaders", response.request().headers().entrySet().toString())
  10. .addContextValue("responseBody", responseBody);
  11. } else if (response.status() == 503) {
  12. .addContextValue("requestUrl", response.request().url())
  13. .addContextValue("requestMethod", response.request().httpMethod())
  14. .addContextValue("requestHeaders", response.request().headers().entrySet().toString())
  15. .addContextValue("responseBody", responseBody)
  16. .addContextValue("errorType", error.getError())

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

  1. @Override
  2. public String url(Request request) {
  3. return request.url();
  4. }

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

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

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

  1. /**
  2. * Creates {@link HttpClientRequest} (Vert.x) from {@link Request} (feign).
  3. *
  4. * @param request feign request
  5. * @return fully formed HttpClientRequest
  6. */
  7. private HttpClientRequest makeHttpClientRequest(final Request request)
  8. throws MalformedURLException {
  9. final URL url = new URL(request.url());
  10. final int port = url.getPort() > -1
  11. ? url.getPort()
  12. : HttpClientOptions.DEFAULT_DEFAULT_PORT;
  13. final String host = url.getHost();
  14. final String requestUri = url.getFile();
  15. HttpClientRequest httpClientRequest = httpClient.request(
  16. HttpMethod.valueOf(request.method()),
  17. port,
  18. host,
  19. requestUri);
  20. /* Add headers to request */
  21. for (final Map.Entry<String, Collection<String>> header : request.headers().entrySet()) {
  22. httpClientRequest = httpClientRequest.putHeader(header.getKey(), header.getValue());
  23. }
  24. return httpClientRequest;
  25. }
  26. }

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

  1. @Override
  2. public Response execute(Request request, Request.Options options) throws IOException {
  3. URI uri = URI.create(request.url());
  4. BambooRequest.Builder builder = BambooRequest.builder()
  5. .serviceId(uri.getHost())
  6. .uri(uri.getPath())
  7. .ip(RequestIpKeeper.getRequestIp())
  8. .addMultiParams(WebUtils.getQueryParams(uri.getQuery()));
  9. if(bambooProperties.getBambooRequest().isLoadBody()){
  10. builder.requestBody(request.body());
  11. }
  12. request.headers().entrySet().forEach(entry ->{
  13. for (String v : entry.getValue()) {
  14. builder.addHeader(entry.getKey(), v);
  15. }
  16. });
  17. ConnectPointContext connectPointContext = ConnectPointContext.builder().bambooRequest(builder.build()).build();
  18. try {
  19. BambooAppContext.getBambooRibbonConnectionPoint().executeConnectPoint(connectPointContext);
  20. return delegate.execute(request, options);
  21. }finally {
  22. BambooAppContext.getBambooRibbonConnectionPoint().shutdownconnectPoint();
  23. }
  24. }
  25. }

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

  1. @Override
  2. public void apply(RequestTemplate template) {
  3. try {
  4. template.header( StarterConstants.TRACE_ID_KEY, TraceIdHelper.getTraceId() );
  5. template.header( StarterConstants.IP_HEADER_NAME, TraceIdHelper.getRemoteIp() );
  6. String bodyStr = "";
  7. byte[] body = template.body();
  8. if ( null != body && body.length > 0 ) {
  9. bodyStr = new String( body );
  10. }
  11. LOGGER.info( "traceId:{}, request -> path:{}, headers:{}, querys:{}, body:{}",
  12. TraceIdHelper.getTraceId(), template.request().url(), JSON.toJSONString(template.request().headers()),
  13. JSON.toJSONString(template.queries()), bodyStr );
  14. } catch (Exception e) {
  15. e.printStackTrace();
  16. }
  17. }
  18. }

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

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

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

  1. private ContentType getContentType(Request request) {
  2. ContentType contentType = ContentType.DEFAULT_TEXT;
  3. for (Map.Entry<String, Collection<String>> entry : request.headers().entrySet()) {
  4. if (entry.getKey().equalsIgnoreCase("Content-Type")) {
  5. Collection values = entry.getValue();
  6. if (values != null && !values.isEmpty()) {
  7. contentType = ContentType.create(entry.getValue().iterator().next(), request.charset());
  8. break;
  9. }
  10. }
  11. }
  12. return contentType;
  13. }

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

  1. @Override
  2. public String method(Request request) {
  3. return request.method();
  4. }

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

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

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

  1. @Override
  2. public HttpMethod getMethod() {
  3. return HttpMethod
  4. .resolve(RibbonRequest.this.toRequest().httpMethod().name());
  5. }

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

  1. public Request request() {
  2. Map<String, Collection<String>> safeCopy = new LinkedHashMap<String, Collection<String>>();
  3. safeCopy.putAll(headers);
  4. return Request.create(
  5. method,
  6. new StringBuilder(url).append(queryLine()).toString(),
  7. Collections.unmodifiableMap(safeCopy),
  8. body, charset
  9. );
  10. }

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

  1. HttpUriRequest toHttpUriRequest(Request request, Request.Options options)
  2. throws URISyntaxException {
  3. RequestBuilder requestBuilder = RequestBuilder.create(request.httpMethod().name());
  4. requestBuilder.setConfig(requestConfig);
  5. URI uri = new URIBuilder(request.url()).build();
  6. for (Map.Entry<String, Collection<String>> headerEntry : request.headers().entrySet()) {
  7. String headerName = headerEntry.getKey();
  8. if (headerName.equalsIgnoreCase(ACCEPT_HEADER_NAME)) {
  9. if (request.body() != null) {
  10. HttpEntity entity = null;
  11. if (request.charset() != null) {
  12. ContentType contentType = getContentType(request);
  13. String content = new String(request.body(), request.charset());
  14. entity = new StringEntity(content, contentType);
  15. } else {
  16. entity = new ByteArrayEntity(request.body());

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

  1. private String getHeaderValue(Request req, String headerName) {
  2. Map<String, Collection<String>> headers = req.headers();
  3. Collection<String> values = headers.get(headerName);
  4. String value = null;
  5. if (values != null && values.isEmpty() == false) {
  6. String[] array = new String[values.size()];
  7. values.toArray(array);
  8. value = array[0];
  9. }
  10. return value;
  11. }

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

  1. .addContextValue("requestUrl", response.request().url())
  2. .addContextValue("requestMethod", response.request().httpMethod())
  3. .addContextValue("requestHeaders", response.request().headers().entrySet().toString())
  4. .addContextValue("responseBody", responseBody);
  5. } else if (response.status() == 404) {
  6. throw new NotFoundException()
  7. .addContextValue("requestUrl", response.request().url())
  8. .addContextValue("requestMethod", response.request().httpMethod())
  9. .addContextValue("requestHeaders", response.request().headers().entrySet().toString())
  10. .addContextValue("responseBody", responseBody);
  11. } else if (response.status() == 503) {
  12. .addContextValue("requestUrl", response.request().url())
  13. .addContextValue("requestMethod", response.request().httpMethod())
  14. .addContextValue("requestHeaders", response.request().headers().entrySet().toString())
  15. .addContextValue("responseBody", responseBody)
  16. .addContextValue("errorType", error.getError())

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

  1. @Override
  2. public String url(Request request) {
  3. return request.url();
  4. }

相关文章