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

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

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

Request.body介绍

[英]If present, this is the replayable body to send to the server. In some cases, this may be interpretable as text.
[中]如果存在,这是要发送到服务器的可重放正文。在某些情况下,这可以解释为文本。

代码示例

代码示例来源: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: com.ofg/micro-infra-spring-base

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

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

byte[] inputBody = input.body();
boolean isMethodWithBody = "POST".equals(input.method()) || "PUT".equals(input.method());
if (isMethodWithBody && inputBody == null) {

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

if (request.body() != null) {
 if (contentLength != null) {
  connection.setFixedLengthStreamingMode(contentLength);
  out.write(request.body());
 } finally {
  try {

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

byte[] inputBody = input.body();
boolean isMethodWithBody =
  HttpMethod.POST == input.httpMethod() || HttpMethod.PUT == input.httpMethod()

代码示例来源:origin: bbilger/jrestless

private static ServiceRequest toServiceRequest(feign.Request feignRequest) {
  return new DefaultServiceRequest(toServiceBody(feignRequest.body()), toServiceHeaders(feignRequest.headers()),
      URI.create(feignRequest.url()), feignRequest.method());
}

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

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: 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: 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: OpenFeign/feign-vertx

if (request.body() != null) {
 httpClientRequest.write(Buffer.buffer(request.body()));

代码示例来源: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: 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: bbilger/jrestless

@Test
public void execute_RequestBodyGiven_ShouldRequestWithBody() throws IOException {
  FeignLambdaClientImpl client = new FeignLambdaClientImpl(serviceResponse);
  when(feignRequest.body()).thenReturn("body".getBytes());
  client.execute(feignRequest, null);
  assertEquals("body", client.getServiceRequest().getBody());
}

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

相关文章