Skip to content

Commit 630fc19

Browse files
committed
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
1 parent 31d1e26 commit 630fc19

26 files changed

+111
-42
lines changed

spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpRequest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,6 +66,11 @@ public HttpMethod getMethod() {
6666
return this.httpMethod;
6767
}
6868

69+
@Override
70+
public String getMethodValue() {
71+
return this.httpMethod.name();
72+
}
73+
6974
public void setURI(URI uri) {
7075
this.uri = uri;
7176
}

spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ public HttpMethod getMethod() {
8383
return this.httpMethod;
8484
}
8585

86+
@Override
87+
public String getMethodValue() {
88+
return this.httpMethod.name();
89+
}
90+
8691
@Override
8792
public String getContextPath() {
8893
return this.contextPath;

spring-web/src/main/java/org/springframework/http/HttpRequest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,7 +32,15 @@ public interface HttpRequest extends HttpMessage {
3232
* @return the HTTP method as an HttpMethod enum value, or {@code null}
3333
* if not resolvable (e.g. in case of a non-standard HTTP method)
3434
*/
35-
HttpMethod getMethod();
35+
default HttpMethod getMethod() {
36+
return HttpMethod.resolve(getMethodValue());
37+
}
38+
39+
/**
40+
* Return the HTTP method of the request as a String
41+
* @return the HTTP method as a String
42+
*/
43+
String getMethodValue();
3644

3745
/**
3846
* Return the URI of the request.

spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestWrapper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,6 +44,11 @@ public HttpMethod getMethod() {
4444
return this.request.getMethod();
4545
}
4646

47+
@Override
48+
public String getMethodValue() {
49+
return this.request.getMethodValue();
50+
}
51+
4752
@Override
4853
public URI getURI() {
4954
return this.request.getURI();

spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpRequest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.apache.http.protocol.HttpContext;
3131

3232
import org.springframework.http.HttpHeaders;
33-
import org.springframework.http.HttpMethod;
3433
import org.springframework.util.concurrent.FailureCallback;
3534
import org.springframework.util.concurrent.FutureAdapter;
3635
import org.springframework.util.concurrent.ListenableFuture;
@@ -69,8 +68,8 @@ final class HttpComponentsAsyncClientHttpRequest extends AbstractBufferingAsyncC
6968

7069

7170
@Override
72-
public HttpMethod getMethod() {
73-
return HttpMethod.resolve(this.httpRequest.getMethod());
71+
public String getMethodValue() {
72+
return this.httpRequest.getMethod();
7473
}
7574

7675
@Override

spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -63,8 +63,8 @@ final class HttpComponentsClientHttpRequest extends AbstractBufferingClientHttpR
6363

6464

6565
@Override
66-
public HttpMethod getMethod() {
67-
return HttpMethod.resolve(this.httpRequest.getMethod());
66+
public String getMethodValue() {
67+
return this.httpRequest.getMethod();
6868
}
6969

7070
@Override

spring-web/src/main/java/org/springframework/http/client/HttpComponentsStreamingClientHttpRequest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,7 +31,6 @@
3131
import org.apache.http.protocol.HttpContext;
3232

3333
import org.springframework.http.HttpHeaders;
34-
import org.springframework.http.HttpMethod;
3534
import org.springframework.http.MediaType;
3635
import org.springframework.http.StreamingHttpOutputMessage;
3736

@@ -65,8 +64,8 @@ final class HttpComponentsStreamingClientHttpRequest extends AbstractClientHttpR
6564

6665

6766
@Override
68-
public HttpMethod getMethod() {
69-
return HttpMethod.resolve(this.httpRequest.getMethod());
67+
public String getMethodValue() {
68+
return this.httpRequest.getMethod();
7069
}
7170

7271
@Override

spring-web/src/main/java/org/springframework/http/client/InterceptingAsyncClientHttpRequest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ protected ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders heade
7575

7676
@Override
7777
public HttpMethod getMethod() {
78-
return httpMethod;
78+
return this.httpMethod;
79+
}
80+
81+
@Override
82+
public String getMethodValue() {
83+
return this.httpMethod.name();
7984
}
8085

8186
@Override

spring-web/src/main/java/org/springframework/http/client/InterceptingClientHttpRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public HttpMethod getMethod() {
5959
return this.method;
6060
}
6161

62+
@Override
63+
public String getMethodValue() {
64+
return this.method.name();
65+
}
66+
6267
@Override
6368
public URI getURI() {
6469
return this.uri;

spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public HttpMethod getMethod() {
7777
return this.method;
7878
}
7979

80+
@Override
81+
public String getMethodValue() {
82+
return this.method.name();
83+
}
84+
8085
@Override
8186
public URI getURI() {
8287
return this.uri;

spring-web/src/main/java/org/springframework/http/client/OkHttp3AsyncClientHttpRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public HttpMethod getMethod() {
6363
return this.method;
6464
}
6565

66+
@Override
67+
public String getMethodValue() {
68+
return this.method.name();
69+
}
70+
6671
@Override
6772
public URI getURI() {
6873
return this.uri;

spring-web/src/main/java/org/springframework/http/client/OkHttp3ClientHttpRequest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,6 +56,11 @@ public HttpMethod getMethod() {
5656
return this.method;
5757
}
5858

59+
@Override
60+
public String getMethodValue() {
61+
return this.method.name();
62+
}
63+
5964
@Override
6065
public URI getURI() {
6166
return this.uri;

spring-web/src/main/java/org/springframework/http/client/SimpleBufferingAsyncClientHttpRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ final class SimpleBufferingAsyncClientHttpRequest extends AbstractBufferingAsync
5858

5959

6060
@Override
61-
public HttpMethod getMethod() {
62-
return HttpMethod.resolve(this.connection.getRequestMethod());
61+
public String getMethodValue() {
62+
return this.connection.getRequestMethod();
6363
}
6464

6565
@Override

spring-web/src/main/java/org/springframework/http/client/SimpleBufferingClientHttpRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,8 +51,8 @@ final class SimpleBufferingClientHttpRequest extends AbstractBufferingClientHttp
5151

5252

5353
@Override
54-
public HttpMethod getMethod() {
55-
return HttpMethod.resolve(this.connection.getRequestMethod());
54+
public String getMethodValue() {
55+
return this.connection.getRequestMethod();
5656
}
5757

5858
@Override

spring-web/src/main/java/org/springframework/http/client/SimpleStreamingAsyncClientHttpRequest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import org.springframework.core.task.AsyncListenableTaskExecutor;
2727
import org.springframework.http.HttpHeaders;
28-
import org.springframework.http.HttpMethod;
2928
import org.springframework.util.StreamUtils;
3029
import org.springframework.util.concurrent.ListenableFuture;
3130

@@ -64,8 +63,8 @@ final class SimpleStreamingAsyncClientHttpRequest extends AbstractAsyncClientHtt
6463

6564

6665
@Override
67-
public HttpMethod getMethod() {
68-
return HttpMethod.resolve(this.connection.getRequestMethod());
66+
public String getMethodValue() {
67+
return this.connection.getRequestMethod();
6968
}
7069

7170
@Override

spring-web/src/main/java/org/springframework/http/client/SimpleStreamingClientHttpRequest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,8 +52,9 @@ final class SimpleStreamingClientHttpRequest extends AbstractClientHttpRequest {
5252
}
5353

5454

55-
public HttpMethod getMethod() {
56-
return HttpMethod.resolve(this.connection.getRequestMethod());
55+
@Override
56+
public String getMethodValue() {
57+
return this.connection.getRequestMethod();
5758
}
5859

5960
@Override

spring-web/src/main/java/org/springframework/http/client/support/HttpRequestWrapper.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -62,6 +62,14 @@ public HttpMethod getMethod() {
6262
return this.request.getMethod();
6363
}
6464

65+
/**
66+
* Return the method value of the wrapped request.
67+
*/
68+
@Override
69+
public String getMethodValue() {
70+
return this.request.getMethodValue();
71+
}
72+
6573
/**
6674
* Return the URI of the wrapped request.
6775
*/

spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public HttpServletRequest getServletRequest() {
8383
}
8484

8585
@Override
86-
public HttpMethod getMethod() {
87-
return HttpMethod.resolve(this.servletRequest.getMethod());
86+
public String getMethodValue() {
87+
return this.servletRequest.getMethod();
8888
}
8989

9090
@Override

spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.core.io.buffer.NettyDataBufferFactory;
2929
import org.springframework.http.HttpCookie;
3030
import org.springframework.http.HttpHeaders;
31-
import org.springframework.http.HttpMethod;
3231
import org.springframework.util.Assert;
3332
import org.springframework.util.LinkedMultiValueMap;
3433
import org.springframework.util.MultiValueMap;
@@ -82,8 +81,8 @@ public HttpServerRequest getReactorRequest() {
8281
}
8382

8483
@Override
85-
public HttpMethod getMethod() {
86-
return HttpMethod.valueOf(this.request.method().name());
84+
public String getMethodValue() {
85+
return this.request.method().name();
8786
}
8887

8988
@Override

spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public HttpMethod getMethod() {
5858
return getDelegate().getMethod();
5959
}
6060

61+
@Override
62+
public String getMethodValue() {
63+
return getDelegate().getMethodValue();
64+
}
65+
6166
@Override
6267
public URI getURI() {
6368
return getDelegate().getURI();

spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.springframework.core.io.buffer.DataBufferFactory;
4040
import org.springframework.http.HttpCookie;
4141
import org.springframework.http.HttpHeaders;
42-
import org.springframework.http.HttpMethod;
4342
import org.springframework.http.MediaType;
4443
import org.springframework.util.Assert;
4544
import org.springframework.util.LinkedCaseInsensitiveMap;
@@ -150,8 +149,8 @@ public HttpServletRequest getServletRequest() {
150149
}
151150

152151
@Override
153-
public HttpMethod getMethod() {
154-
return HttpMethod.valueOf(getServletRequest().getMethod());
152+
public String getMethodValue() {
153+
return getServletRequest().getMethod();
155154
}
156155

157156
@Override

spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.springframework.core.io.buffer.DataBufferFactory;
3535
import org.springframework.http.HttpCookie;
3636
import org.springframework.http.HttpHeaders;
37-
import org.springframework.http.HttpMethod;
3837
import org.springframework.util.Assert;
3938
import org.springframework.util.LinkedMultiValueMap;
4039
import org.springframework.util.MultiValueMap;
@@ -83,8 +82,8 @@ public HttpServerExchange getUndertowExchange() {
8382
}
8483

8584
@Override
86-
public HttpMethod getMethod() {
87-
return HttpMethod.valueOf(this.getUndertowExchange().getRequestMethod().toString());
85+
public String getMethodValue() {
86+
return this.getUndertowExchange().getRequestMethod().toString();
8887
}
8988

9089
@Override

spring-web/src/main/java/org/springframework/web/client/AsyncRestTemplate.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,10 @@ public HttpMethod getMethod() {
662662
return request.getMethod();
663663
}
664664
@Override
665+
public String getMethodValue() {
666+
return request.getMethodValue();
667+
}
668+
@Override
665669
public URI getURI() {
666670
return request.getURI();
667671
}

spring-web/src/test/java/org/springframework/http/client/InterceptingClientHttpRequestFactoryTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ public HttpMethod getMethod() {
267267
return method;
268268
}
269269

270+
@Override
271+
public String getMethodValue() {
272+
return method.name();
273+
}
274+
270275
public void setMethod(HttpMethod method) {
271276
this.method = method;
272277
}

0 commit comments

Comments
 (0)