feign.Request.charset()方法的使用及代码示例

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

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

Request.charset介绍

[英]The character set with which the body is encoded, or null if unknown or not applicable. When this is present, you can use new String(req.body(), req.charset()) to access the body as a String.
[中]用于编码正文的字符集,如果未知或不适用,则为null。当出现这种情况时,可以使用新字符串(req.body(),req。charset())以字符串形式访问正文。

代码示例

代码示例来源: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: 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: io.github.openfeign/feign-httpclient

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<String> values = entry.getValue();
   if (values != null && !values.isEmpty()) {
    contentType = ContentType.parse(values.iterator().next());
    if (contentType.getCharset() == null) {
     contentType = contentType.withCharset(request.charset());
    }
    break;
   }
  }
 return contentType;
}

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

private Request tracePreRequest(Request request, TraceEvent traceEvent) {
  // set tracing headers to HTTP request
  Map<String, Collection<String>> traceHeaders = new HashMap<>();
  traceHeaders.putAll(request.headers());
  traceHeaders.put(TracingConstants.TRACE_ID_HEADER, Collections.singletonList(traceEvent.getTraceId()));
  traceHeaders.put(TracingConstants.TRACE_ORIGIN_ID_HEADER, Collections.singletonList(traceEvent.getOriginId()));
  // publish event to DAS
  TracingUtil.pushToDAS(traceEvent, dasUrl);
  return Request.create(request.method(), request.url(), traceHeaders, request.body(), request.charset());
}

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

if (field.equalsIgnoreCase("Content-Type")) {
 mediaType = MediaType.parse(value);
 if (input.charset() != null) {
  mediaType.charset(input.charset());

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

if (field.equalsIgnoreCase("Content-Type")) {
 mediaType = MediaType.parse(value);
 if (input.charset() != null) {
  mediaType.charset(input.charset());

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

private Request request(Request request,
    Map<String, Collection<String>> headers) {
  return Request.create(request.method(), request.url(), headers,
      request.body(), request.charset());
}

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

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: wso2/msf4j

if (request.charset() != null) {
  ContentType contentType = getContentType(request);
  String content = new String(request.body(), request.charset());
  entity = new StringEntity(content, contentType);
} else {

代码示例来源:origin: com.marvinformatics.feign/feign-mock

private RequestKey(Request request) {
  this.method = HttpMethod.valueOf(request.method());
  this.url = buildUrl(request);
  this.headers = request.headers();
  this.charset = request.charset();
  this.body = request.body();
}

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

if (request.charset() != null) {
 ContentType contentType = getContentType(request);
 String content = new String(request.body(), request.charset());
 entity = new StringEntity(content, contentType);
} else {

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

Request toRequest() {
 return new RequestTemplate()
   .method(request.method())
   .append(getUri().toASCIIString())
   .headers(request.headers())
   .body(request.body(), request.charset())
   .request();
}

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

protected void logRequest(String configKey, Level logLevel, Request request) {
 log(configKey, "---> %s %s HTTP/1.1", request.method(), request.url());
 if (logLevel.ordinal() >= Level.HEADERS.ordinal()) {
  for (String field : request.headers().keySet()) {
   for (String value : valuesOrEmpty(request.headers(), field)) {
    log(configKey, "%s: %s", field, value);
   }
  }
  int bodyLength = 0;
  if (request.body() != null) {
   bodyLength = request.body().length;
   if (logLevel.ordinal() >= Level.FULL.ordinal()) {
    String
      bodyText =
      request.charset() != null ? new String(request.body(), request.charset()) : null;
    log(configKey, ""); // CRLF
    log(configKey, "%s", bodyText != null ? bodyText : "Binary data");
   }
  }
  log(configKey, "---> END HTTP (%s-byte body)", bodyLength);
 }
}

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

@Override
  public Response execute(Request request, Request.Options options) throws IOException {
    Map<String, Collection<String>> traceHeaders = new HashMap<>();
    traceHeaders.putAll(request.headers());
    Request wrappedRequest =
        Request.create(request.method(), request.url(), traceHeaders, request.body(), request.charset());
    HttpClientRequest httpClientRequest = new TraceableHttpClientRequest(wrappedRequest);
    ClientRequestAdapter adapter = new HttpClientRequestAdapter(httpClientRequest, new DefaultSpanNameProvider());
    requestInterceptor.handle(adapter);

    Response response = clientDelegate.execute(wrappedRequest, options);

    HttpResponse httpResponse = new TraceableHttpClientResponse(response);
    ClientResponseAdapter responseAdapter = new HttpClientResponseAdapter(httpResponse);
    responseInterceptor.handle(responseAdapter);
    return response;
  }
}

相关文章