/** * Return the method of the wrapped request. */ @Override @Nullable public HttpMethod getMethod() { return this.request.getMethod(); }
/** * Return the method of the wrapped request. */ @Override @Nullable public HttpMethod getMethod() { return this.request.getMethod(); }
private void logRequest(HttpRequest request, byte[] body) throws UnsupportedEncodingException { log.info("URI: " + request.getURI()); log.info("HTTP Method: " + request.getMethod()); log.info("HTTP Headers: " + headersToString(request.getHeaders())); log.info("Request Body: " + new String(body, StandardCharsets.UTF_8)); }
protected String getRequestName(HttpRequest httpRequest) { String uri = httpRequest.getURI().toString(); final int index = uri.indexOf('?'); if (index != -1) { uri = uri.substring(0, index); } return uri + ' ' + httpRequest.getMethod(); } }
@Override public String method(HttpRequest request) { return request.getMethod().name(); }
@Override public ListenableFuture<ClientHttpResponse> executeAsync(HttpRequest request, byte[] body) throws IOException { if (this.iterator.hasNext()) { AsyncClientHttpRequestInterceptor interceptor = this.iterator.next(); return interceptor.intercept(request, body, this); } else { URI uri = request.getURI(); HttpMethod method = request.getMethod(); HttpHeaders headers = request.getHeaders(); Assert.state(method != null, "No standard HTTP method"); AsyncClientHttpRequest delegate = requestFactory.createAsyncRequest(uri, method); delegate.getHeaders().putAll(headers); if (body.length > 0) { StreamUtils.copy(body, delegate.getBody()); } return delegate.executeAsync(); } } }
@Override public ClientHttpResponse execute(HttpRequest request, byte[] body) throws IOException { if (this.iterator.hasNext()) { ClientHttpRequestInterceptor nextInterceptor = this.iterator.next(); return nextInterceptor.intercept(request, body, this); } else { HttpMethod method = request.getMethod(); Assert.state(method != null, "No standard HTTP method"); ClientHttpRequest delegate = requestFactory.createRequest(request.getURI(), method); request.getHeaders().forEach((key, value) -> delegate.getHeaders().addAll(key, value)); if (body.length > 0) { if (delegate instanceof StreamingHttpOutputMessage) { StreamingHttpOutputMessage streamingOutputMessage = (StreamingHttpOutputMessage) delegate; streamingOutputMessage.setBody(outputStream -> StreamUtils.copy(body, outputStream)); } else { StreamUtils.copy(body, delegate.getBody()); } } return delegate.execute(); } } }
@Override public ListenableFuture<ClientHttpResponse> executeAsync(HttpRequest request, byte[] body) throws IOException { if (this.iterator.hasNext()) { AsyncClientHttpRequestInterceptor interceptor = this.iterator.next(); return interceptor.intercept(request, body, this); } else { URI uri = request.getURI(); HttpMethod method = request.getMethod(); HttpHeaders headers = request.getHeaders(); Assert.state(method != null, "No standard HTTP method"); AsyncClientHttpRequest delegate = requestFactory.createAsyncRequest(uri, method); delegate.getHeaders().putAll(headers); if (body.length > 0) { StreamUtils.copy(body, delegate.getBody()); } return delegate.executeAsync(); } } }
@Override public ClientHttpResponse execute(HttpRequest request, byte[] body) throws IOException { if (this.iterator.hasNext()) { ClientHttpRequestInterceptor nextInterceptor = this.iterator.next(); return nextInterceptor.intercept(request, body, this); } else { HttpMethod method = request.getMethod(); Assert.state(method != null, "No standard HTTP method"); ClientHttpRequest delegate = requestFactory.createRequest(request.getURI(), method); request.getHeaders().forEach((key, value) -> delegate.getHeaders().addAll(key, value)); if (body.length > 0) { if (delegate instanceof StreamingHttpOutputMessage) { StreamingHttpOutputMessage streamingOutputMessage = (StreamingHttpOutputMessage) delegate; streamingOutputMessage.setBody(outputStream -> StreamUtils.copy(body, outputStream)); } else { StreamUtils.copy(body, delegate.getBody()); } } return delegate.execute(); } } }
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { final Scope scope = new ExternalHttpRequest(tracingPlugin.getTracer(), request.getMethod().toString(), removeQuery(request.getURI()), request.getURI().getHost(), request.getURI().getPort()).createScope(); try { Profiler.start(request.getMethod().toString() + " " + request.getURI() + " "); tracingPlugin.getTracer().inject(scope.span().context(), Format.Builtin.HTTP_HEADERS, new SpringHttpRequestInjectAdapter(request)); return execution.execute(request, body); } finally { Profiler.stop(); scope.close(); } }
HttpMethod httpMethod = (inputMessage instanceof HttpRequest ? ((HttpRequest) inputMessage).getMethod() : null); Object body = NO_VALUE;
HttpMethod httpMethod = (inputMessage instanceof HttpRequest ? ((HttpRequest) inputMessage).getMethod() : null); Object body = NO_VALUE;
/** * Checks if the request has a readable body (not a GET, HEAD, or OPTIONS request). * @param request the HTTP request to check the method * @return true or false if HTTP request can contain the body */ protected boolean isReadable(HttpRequest request) { HttpMethod method = request.getMethod(); return method == null ? false : !(CollectionUtils.containsInstance(nonReadableBodyHttpMethods, method)); }
assertEquals(HttpMethod.GET, request.getMethod()); assertEquals(URI.create(this.server.url(path).toString()), request.getURI()); assertNotNull(request.getHeaders());
/** * Creates a {@code method} {@code Tag} for the {@link HttpRequest#getMethod() method} * of the given {@code request}. * @param request the request * @return the method tag */ public static Tag method(HttpRequest request) { return Tag.of("method", request.getMethod().name()); }
/** * Checks if the request has a readable body (not a GET, HEAD, or OPTIONS request). * @param request the HTTP request to check the method * @return true or false if HTTP request can contain the body */ protected boolean isReadable(HttpRequest request) { HttpMethod method = request.getMethod(); return method == null ? false : !(CollectionUtils.containsInstance(nonReadableBodyHttpMethods, method)); }
@Override public @Nullable String getRequestHttpMethod(@Nullable HttpRequest request) { if (request == null) { return null; } HttpMethod method = request.getMethod(); return (method == null) ? "UNKNOWN_HTTP_METHOD" : method.name(); }
private void logRequest(long number, HttpRequest request, byte[] body) throws IOException { StringBuilder builder = new StringBuilder(); builder.append("ID: ").append(number).append('\n'); builder.append("Request: ").append(request.getMethod()).append(' ').append(request.getURI()).append('\n'); builder.append("Headers: ").append(request.getHeaders()).append('\n'); builder.append("Payload: ").append(getRequestBody(body)); LOG.debug("Outbound message\n---------------------\n{}\n---------------------", builder.toString()); }
/** * Creates a {@code method} {@code Tag} for the {@link HttpRequest#getMethod() method} * of the given {@code request}. * * @param request the request * @return the method tag */ public static Tag method(HttpRequest request) { return Tag.of("method", request.getMethod().name()); }
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { DevxTraceLogWrap.request("RestTemplate", request.getMethod().name(), request.getURI().toURL().toString()); ClientHttpResponse response = execution.execute(request, body); DevxTraceLogWrap.response("RestTemplate", response.getRawStatusCode(), request.getMethod().name(), request.getURI().toURL().toString()); return response; }