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()); }
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); }
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()); }
byte[] inputBody = input.body(); boolean isMethodWithBody = "POST".equals(input.method()) || "PUT".equals(input.method()); if (isMethodWithBody && inputBody == null) {
private Request request(Request request, Map<String, Collection<String>> headers) { return Request.create(request.method(), request.url(), headers, request.body(), request.charset()); }
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); }
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());
byte[] inputBody = input.body(); boolean isMethodWithBody = HttpMethod.POST == input.httpMethod() || HttpMethod.PUT == input.httpMethod()
private static ServiceRequest toServiceRequest(feign.Request feignRequest) { return new DefaultServiceRequest(toServiceBody(feignRequest.body()), toServiceHeaders(feignRequest.headers()), URI.create(feignRequest.url()), feignRequest.method()); }
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());
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(); }
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); } }
Request toRequest() { return new RequestTemplate() .method(request.method()) .append(getUri().toASCIIString()) .headers(request.headers()) .body(request.body(), request.charset()) .request(); }
@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(); } } }
@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()); }
@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; } }