Java Code Examples for org.springframework.http.HttpRequest#getMethod()
The following examples show how to use
org.springframework.http.HttpRequest#getMethod() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InterceptingAsyncClientHttpRequest.java From spring-analysis-note with MIT License | 6 votes |
@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(); } }
Example 2
Source File: InterceptingClientHttpRequest.java From spring-analysis-note with MIT License | 6 votes |
@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(); } }
Example 3
Source File: InterceptingAsyncClientHttpRequest.java From java-technology-stack with MIT License | 6 votes |
@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(); } }
Example 4
Source File: InterceptingClientHttpRequest.java From java-technology-stack with MIT License | 6 votes |
@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(); } }
Example 5
Source File: InterceptingAsyncClientHttpRequest.java From lams with GNU General Public License v2.0 | 6 votes |
@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(); AsyncClientHttpRequest delegate = requestFactory.createAsyncRequest(uri, method); delegate.getHeaders().putAll(headers); if (body.length > 0) { StreamUtils.copy(body, delegate.getBody()); } return delegate.executeAsync(); } }
Example 6
Source File: HttpRequestMethodsMatcher.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
@Override public boolean match(HttpRequest request) { boolean matched = false; HttpMethod httpMethod = request.getMethod(); if (httpMethod != null) { for (HttpMethod method : getMethods()) { if (httpMethod.equals(method)) { matched = true; break; } } } return matched; }
Example 7
Source File: MutableHttpServerRequest.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
public MutableHttpServerRequest(HttpRequest httpRequest, byte[] body) { this.httpMethod = httpRequest.getMethod(); this.uri = httpRequest.getURI(); this.path = uri.getPath(); this.httpHeaders = httpRequest.getHeaders(); this.queryParams = getParameters(httpRequest); this.httpInputMessage = new ByteArrayHttpInputMessage(body); }
Example 8
Source File: SpringHttpClientTagAdapter.java From wingtips with Apache License 2.0 | 5 votes |
@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(); }
Example 9
Source File: TracingAsyncClientHttpRequestInterceptor.java From opencensus-java with Apache License 2.0 | 5 votes |
@Override @Nullable public String getMethod(HttpRequest request) { HttpMethod method = request.getMethod(); if (method != null) { return method.toString(); } return null; }
Example 10
Source File: AbstractIT.java From bowman with Apache License 2.0 | 5 votes |
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { ClientHttpResponse response = execution.execute(request, body); if (request.getMethod() == HttpMethod.POST) { createdEntities.add(response.getHeaders().getLocation()); } return response; }
Example 11
Source File: RestTemplateConfig.java From spring-boot-cookbook with Apache License 2.0 | 5 votes |
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { long begin = System.currentTimeMillis(); String httpMethodName = UNKNOWN_HTTP_METHOD; HttpMethod method = request.getMethod(); if (method != null) { httpMethodName = method.name(); } String requestBody = IOUtils.toString(body, "utf-8"); try { ClientHttpResponse response = execution.execute(request, body); long cost = System.currentTimeMillis() - begin; MediaType contentType = response.getHeaders().getContentType(); String responseContent; if (contentType != null) { String subtype = contentType.getSubtype(); if (subtype.contains("json") || contentType.getType().contains("text") || subtype.contains("xml")) { responseContent = IOUtils.toString(response.getBody(), "utf-8"); } else { responseContent = "neither text,nor xml,nor json"; } } else { responseContent = HAS_NO_CONTENT_TYPE; } if (cost > 3000) { log.info("【特殊标识】慢接口 【 TODOLIST 】 大于3秒 cost:[{}]ms,{} {}. request:{},response:{},", cost, httpMethodName, request.getURI().toString(), requestBody, responseContent); } else if (cost > 2000) { log.info("【特殊标识】慢接口 【 TODOLIST 】 大于2秒 cost:[{}]ms,{} {}. request:{},response:{},", cost, httpMethodName, request.getURI().toString(), requestBody, responseContent); } else { log.info("cost:[{}]ms,on {} {}. request:{},response:{},", cost, httpMethodName, request.getURI().toString(), requestBody, responseContent); } return response; } catch (IOException e) { log.error("【特殊标识】【 TODOLIST 】 接口 cost:[{}]ms,I/O error on {} {}. request:{},response:{},", (System.currentTimeMillis() - begin), httpMethodName, request.getURI().toString(), requestBody, e.getMessage()); throw e; } }
Example 12
Source File: SpringRestTemplateInterceptor.java From javamelody with Apache License 2.0 | 5 votes |
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(); }