Add HttpRequest.getMethodValue
This commit introduces a new method in HttpRequest: `String getMethodValue`, which returns the HTTP method as a String. Furthermore, HttpRequest.getMethod() has been given a default implementation using this String value in combination with `HttpMethod.resolve`. Issue: SPR-15545
This commit is contained in:
parent
31d1e26c95
commit
630fc194f0
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -66,6 +66,11 @@ public class MockClientHttpRequest extends MockHttpOutputMessage implements Clie
|
|||
return this.httpMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
return this.httpMethod.name();
|
||||
}
|
||||
|
||||
public void setURI(URI uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,6 +83,11 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
|||
return this.httpMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
return this.httpMethod.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContextPath() {
|
||||
return this.contextPath;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -32,7 +32,15 @@ public interface HttpRequest extends HttpMessage {
|
|||
* @return the HTTP method as an HttpMethod enum value, or {@code null}
|
||||
* if not resolvable (e.g. in case of a non-standard HTTP method)
|
||||
*/
|
||||
HttpMethod getMethod();
|
||||
default HttpMethod getMethod() {
|
||||
return HttpMethod.resolve(getMethodValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the HTTP method of the request as a String
|
||||
* @return the HTTP method as a String
|
||||
*/
|
||||
String getMethodValue();
|
||||
|
||||
/**
|
||||
* Return the URI of the request.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -44,6 +44,11 @@ final class BufferingClientHttpRequestWrapper extends AbstractBufferingClientHtt
|
|||
return this.request.getMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
return this.request.getMethodValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getURI() {
|
||||
return this.request.getURI();
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import org.apache.http.nio.entity.NByteArrayEntity;
|
|||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.concurrent.FailureCallback;
|
||||
import org.springframework.util.concurrent.FutureAdapter;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
|
@ -69,8 +68,8 @@ final class HttpComponentsAsyncClientHttpRequest extends AbstractBufferingAsyncC
|
|||
|
||||
|
||||
@Override
|
||||
public HttpMethod getMethod() {
|
||||
return HttpMethod.resolve(this.httpRequest.getMethod());
|
||||
public String getMethodValue() {
|
||||
return this.httpRequest.getMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -63,8 +63,8 @@ final class HttpComponentsClientHttpRequest extends AbstractBufferingClientHttpR
|
|||
|
||||
|
||||
@Override
|
||||
public HttpMethod getMethod() {
|
||||
return HttpMethod.resolve(this.httpRequest.getMethod());
|
||||
public String getMethodValue() {
|
||||
return this.httpRequest.getMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -31,7 +31,6 @@ import org.apache.http.message.BasicHeader;
|
|||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.StreamingHttpOutputMessage;
|
||||
|
||||
|
|
@ -65,8 +64,8 @@ final class HttpComponentsStreamingClientHttpRequest extends AbstractClientHttpR
|
|||
|
||||
|
||||
@Override
|
||||
public HttpMethod getMethod() {
|
||||
return HttpMethod.resolve(this.httpRequest.getMethod());
|
||||
public String getMethodValue() {
|
||||
return this.httpRequest.getMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -75,7 +75,12 @@ class InterceptingAsyncClientHttpRequest extends AbstractBufferingAsyncClientHtt
|
|||
|
||||
@Override
|
||||
public HttpMethod getMethod() {
|
||||
return httpMethod;
|
||||
return this.httpMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
return this.httpMethod.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -59,6 +59,11 @@ class InterceptingClientHttpRequest extends AbstractBufferingClientHttpRequest {
|
|||
return this.method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
return this.method.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getURI() {
|
||||
return this.uri;
|
||||
|
|
|
|||
|
|
@ -77,6 +77,11 @@ class Netty4ClientHttpRequest extends AbstractAsyncClientHttpRequest implements
|
|||
return this.method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
return this.method.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getURI() {
|
||||
return this.uri;
|
||||
|
|
|
|||
|
|
@ -63,6 +63,11 @@ class OkHttp3AsyncClientHttpRequest extends AbstractBufferingAsyncClientHttpRequ
|
|||
return this.method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
return this.method.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getURI() {
|
||||
return this.uri;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -56,6 +56,11 @@ class OkHttp3ClientHttpRequest extends AbstractBufferingClientHttpRequest {
|
|||
return this.method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
return this.method.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getURI() {
|
||||
return this.uri;
|
||||
|
|
|
|||
|
|
@ -58,8 +58,8 @@ final class SimpleBufferingAsyncClientHttpRequest extends AbstractBufferingAsync
|
|||
|
||||
|
||||
@Override
|
||||
public HttpMethod getMethod() {
|
||||
return HttpMethod.resolve(this.connection.getRequestMethod());
|
||||
public String getMethodValue() {
|
||||
return this.connection.getRequestMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -51,8 +51,8 @@ final class SimpleBufferingClientHttpRequest extends AbstractBufferingClientHttp
|
|||
|
||||
|
||||
@Override
|
||||
public HttpMethod getMethod() {
|
||||
return HttpMethod.resolve(this.connection.getRequestMethod());
|
||||
public String getMethodValue() {
|
||||
return this.connection.getRequestMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import java.util.concurrent.Callable;
|
|||
|
||||
import org.springframework.core.task.AsyncListenableTaskExecutor;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
||||
|
|
@ -64,8 +63,8 @@ final class SimpleStreamingAsyncClientHttpRequest extends AbstractAsyncClientHtt
|
|||
|
||||
|
||||
@Override
|
||||
public HttpMethod getMethod() {
|
||||
return HttpMethod.resolve(this.connection.getRequestMethod());
|
||||
public String getMethodValue() {
|
||||
return this.connection.getRequestMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -52,8 +52,9 @@ final class SimpleStreamingClientHttpRequest extends AbstractClientHttpRequest {
|
|||
}
|
||||
|
||||
|
||||
public HttpMethod getMethod() {
|
||||
return HttpMethod.resolve(this.connection.getRequestMethod());
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
return this.connection.getRequestMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -62,6 +62,14 @@ public class HttpRequestWrapper implements HttpRequest {
|
|||
return this.request.getMethod();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the method value of the wrapped request.
|
||||
*/
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
return this.request.getMethodValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the URI of the wrapped request.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -83,8 +83,8 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public HttpMethod getMethod() {
|
||||
return HttpMethod.resolve(this.servletRequest.getMethod());
|
||||
public String getMethodValue() {
|
||||
return this.servletRequest.getMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import org.springframework.core.io.buffer.DataBuffer;
|
|||
import org.springframework.core.io.buffer.NettyDataBufferFactory;
|
||||
import org.springframework.http.HttpCookie;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
|
@ -82,8 +81,8 @@ public class ReactorServerHttpRequest extends AbstractServerHttpRequest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public HttpMethod getMethod() {
|
||||
return HttpMethod.valueOf(this.request.method().name());
|
||||
public String getMethodValue() {
|
||||
return this.request.method().name();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -58,6 +58,11 @@ public class ServerHttpRequestDecorator implements ServerHttpRequest {
|
|||
return getDelegate().getMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
return getDelegate().getMethodValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getURI() {
|
||||
return getDelegate().getURI();
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ import org.springframework.core.io.buffer.DataBuffer;
|
|||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
import org.springframework.http.HttpCookie;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||
|
|
@ -150,8 +149,8 @@ public class ServletServerHttpRequest extends AbstractServerHttpRequest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public HttpMethod getMethod() {
|
||||
return HttpMethod.valueOf(getServletRequest().getMethod());
|
||||
public String getMethodValue() {
|
||||
return getServletRequest().getMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ import org.springframework.core.io.buffer.DataBuffer;
|
|||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
import org.springframework.http.HttpCookie;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
|
@ -83,8 +82,8 @@ public class UndertowServerHttpRequest extends AbstractServerHttpRequest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public HttpMethod getMethod() {
|
||||
return HttpMethod.valueOf(this.getUndertowExchange().getRequestMethod().toString());
|
||||
public String getMethodValue() {
|
||||
return this.getUndertowExchange().getRequestMethod().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -662,6 +662,10 @@ public class AsyncRestTemplate extends org.springframework.http.client.support.I
|
|||
return request.getMethod();
|
||||
}
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
return request.getMethodValue();
|
||||
}
|
||||
@Override
|
||||
public URI getURI() {
|
||||
return request.getURI();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -267,6 +267,11 @@ public class InterceptingClientHttpRequestFactoryTests {
|
|||
return method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
return method.name();
|
||||
}
|
||||
|
||||
public void setMethod(HttpMethod method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ import org.springframework.core.io.buffer.DataBuffer;
|
|||
import org.springframework.core.io.buffer.NettyDataBufferFactory;
|
||||
import org.springframework.http.HttpCookie;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
|
@ -93,8 +92,8 @@ public class RxNettyServerHttpRequest extends AbstractServerHttpRequest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public HttpMethod getMethod() {
|
||||
return HttpMethod.valueOf(this.request.getHttpMethod().name());
|
||||
public String getMethodValue() {
|
||||
return this.request.getHttpMethod().name();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -82,6 +82,11 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
|||
return this.httpMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
return this.httpMethod.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContextPath() {
|
||||
return this.contextPath;
|
||||
|
|
|
|||
Loading…
Reference in New Issue