Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -236,7 +236,7 @@ public class JibxMarshaller extends AbstractMarshaller implements InitializingBe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(Class<?> clazz) {
|
public boolean supports(Class<?> clazz) {
|
||||||
Assert.notNull(clazz, "'clazz' must not be null");
|
Assert.notNull(clazz, "Class must not be null");
|
||||||
if (this.targetClass != null) {
|
if (this.targetClass != null) {
|
||||||
return this.targetClass.equals(clazz);
|
return this.targetClass.equals(clazz);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.test.web.client;
|
package org.springframework.test.web.client;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -52,7 +53,6 @@ public class MockMvcClientHttpRequestFactory implements ClientHttpRequestFactory
|
|||||||
@Override
|
@Override
|
||||||
public ClientHttpRequest createRequest(final URI uri, final HttpMethod httpMethod) throws IOException {
|
public ClientHttpRequest createRequest(final URI uri, final HttpMethod httpMethod) throws IOException {
|
||||||
return new MockClientHttpRequest(httpMethod, uri) {
|
return new MockClientHttpRequest(httpMethod, uri) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientHttpResponse executeInternal() throws IOException {
|
public ClientHttpResponse executeInternal() throws IOException {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.test.web.client;
|
package org.springframework.test.web.client;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -29,7 +30,6 @@ public interface RequestMatcher {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Match the given request against some expectations.
|
* Match the given request against some expectations.
|
||||||
*
|
|
||||||
* @param request the request to make assertions on
|
* @param request the request to make assertions on
|
||||||
* @throws IOException in case of I/O errors
|
* @throws IOException in case of I/O errors
|
||||||
* @throws AssertionError if expectations are not met
|
* @throws AssertionError if expectations are not met
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -46,6 +46,7 @@ class RequestMatcherClientHttpRequest extends MockAsyncClientHttpRequest impleme
|
|||||||
this.requestMatchers.add(requestMatcher);
|
this.requestMatchers.add(requestMatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseActions andExpect(RequestMatcher requestMatcher) {
|
public ResponseActions andExpect(RequestMatcher requestMatcher) {
|
||||||
Assert.notNull(requestMatcher, "RequestMatcher is required");
|
Assert.notNull(requestMatcher, "RequestMatcher is required");
|
||||||
@@ -61,22 +62,19 @@ class RequestMatcherClientHttpRequest extends MockAsyncClientHttpRequest impleme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientHttpResponse executeInternal() throws IOException {
|
public ClientHttpResponse executeInternal() throws IOException {
|
||||||
|
|
||||||
if (this.requestMatchers.isEmpty()) {
|
if (this.requestMatchers.isEmpty()) {
|
||||||
throw new AssertionError("No request expectations to execute");
|
throw new AssertionError("No request expectations to execute");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.responseCreator == null) {
|
if (this.responseCreator == null) {
|
||||||
throw new AssertionError("No ResponseCreator was set up. Add it after request expectations, "
|
throw new AssertionError("No ResponseCreator was set up. Add it after request expectations, " +
|
||||||
+ "e.g. MockRestServiceServer.expect(requestTo(\"/foo\")).andRespond(withSuccess())");
|
"e.g. MockRestServiceServer.expect(requestTo(\"/foo\")).andRespond(withSuccess())");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (RequestMatcher requestMatcher : this.requestMatchers) {
|
for (RequestMatcher requestMatcher : this.requestMatchers) {
|
||||||
requestMatcher.match(this);
|
requestMatcher.match(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
setResponse(this.responseCreator.createResponse(this));
|
setResponse(this.responseCreator.createResponse(this));
|
||||||
|
|
||||||
return super.executeInternal();
|
return super.executeInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.test.web.client;
|
package org.springframework.test.web.client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.test.web.client;
|
package org.springframework.test.web.client;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|||||||
@@ -448,12 +448,12 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
|||||||
public Set<HttpMethod> getAllow() {
|
public Set<HttpMethod> getAllow() {
|
||||||
String value = getFirst(ALLOW);
|
String value = getFirst(ALLOW);
|
||||||
if (!StringUtils.isEmpty(value)) {
|
if (!StringUtils.isEmpty(value)) {
|
||||||
List<HttpMethod> allowedMethod = new ArrayList<HttpMethod>(5);
|
List<HttpMethod> result = new LinkedList<HttpMethod>();
|
||||||
String[] tokens = value.split(",\\s*");
|
String[] tokens = value.split(",\\s*");
|
||||||
for (String token : tokens) {
|
for (String token : tokens) {
|
||||||
allowedMethod.add(HttpMethod.valueOf(token));
|
result.add(HttpMethod.valueOf(token));
|
||||||
}
|
}
|
||||||
return EnumSet.copyOf(allowedMethod);
|
return EnumSet.copyOf(result);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return EnumSet.noneOf(HttpMethod.class);
|
return EnumSet.noneOf(HttpMethod.class);
|
||||||
@@ -468,7 +468,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value of the {@code Cache-Control} header.
|
* Return the value of the {@code Cache-Control} header.
|
||||||
*/
|
*/
|
||||||
public String getCacheControl() {
|
public String getCacheControl() {
|
||||||
return getFirst(CACHE_CONTROL);
|
return getFirst(CACHE_CONTROL);
|
||||||
@@ -489,7 +489,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value of the {@code Connection} header.
|
* Return the value of the {@code Connection} header.
|
||||||
*/
|
*/
|
||||||
public List<String> getConnection() {
|
public List<String> getConnection() {
|
||||||
return getFirstValueAsList(CONNECTION);
|
return getFirstValueAsList(CONNECTION);
|
||||||
@@ -763,7 +763,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value of the {@code Upgrade} header.
|
* Return the value of the {@code Upgrade} header.
|
||||||
*/
|
*/
|
||||||
public String getUpgrade() {
|
public String getUpgrade() {
|
||||||
return getFirst(UPGRADE);
|
return getFirst(UPGRADE);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -26,6 +26,6 @@ package org.springframework.http;
|
|||||||
*/
|
*/
|
||||||
public enum HttpMethod {
|
public enum HttpMethod {
|
||||||
|
|
||||||
GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE, TRACE
|
GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -23,7 +23,8 @@ import org.springframework.http.HttpMethod;
|
|||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base class for {@link ClientHttpRequestFactory} implementations that decorate another request factory.
|
* Abstract base class for {@link ClientHttpRequestFactory} implementations
|
||||||
|
* that decorate another request factory.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
@@ -34,11 +35,11 @@ public abstract class AbstractClientHttpRequestFactoryWrapper implements ClientH
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@code AbstractClientHttpRequestFactoryWrapper} wrapping the given request factory.
|
* Create a {@code AbstractClientHttpRequestFactoryWrapper} wrapping the given request factory.
|
||||||
* @param requestFactory the request factory to be wrapped
|
* @param requestFactory the request factory to be wrapped
|
||||||
*/
|
*/
|
||||||
protected AbstractClientHttpRequestFactoryWrapper(ClientHttpRequestFactory requestFactory) {
|
protected AbstractClientHttpRequestFactoryWrapper(ClientHttpRequestFactory requestFactory) {
|
||||||
Assert.notNull(requestFactory, "'requestFactory' must not be null");
|
Assert.notNull(requestFactory, "ClientHttpRequestFactory must not be null");
|
||||||
this.requestFactory = requestFactory;
|
this.requestFactory = requestFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,12 +51,12 @@ public abstract class AbstractClientHttpRequestFactoryWrapper implements ClientH
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
|
public final ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
|
||||||
return createRequest(uri, httpMethod, requestFactory);
|
return createRequest(uri, httpMethod, this.requestFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link ClientHttpRequest} for the specified URI and HTTP method by using the
|
* Create a new {@link ClientHttpRequest} for the specified URI and HTTP method
|
||||||
* passed-on request factory.
|
* by using the passed-on request factory.
|
||||||
* <p>Called from {@link #createRequest(URI, HttpMethod)}.
|
* <p>Called from {@link #createRequest(URI, HttpMethod)}.
|
||||||
* @param uri the URI to create a request for
|
* @param uri the URI to create a request for
|
||||||
* @param httpMethod the HTTP method to execute
|
* @param httpMethod the HTTP method to execute
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -114,8 +114,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
|||||||
*/
|
*/
|
||||||
public void setConnectTimeout(int timeout) {
|
public void setConnectTimeout(int timeout) {
|
||||||
Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value");
|
Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value");
|
||||||
this.requestConfig = cloneRequestConfig()
|
this.requestConfig = cloneRequestConfig().setConnectTimeout(timeout).build();
|
||||||
.setConnectTimeout(timeout).build();
|
|
||||||
setLegacyConnectionTimeout(getHttpClient(), timeout);
|
setLegacyConnectionTimeout(getHttpClient(), timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,8 +135,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private void setLegacyConnectionTimeout(HttpClient client, int timeout) {
|
private void setLegacyConnectionTimeout(HttpClient client, int timeout) {
|
||||||
if (org.apache.http.impl.client.AbstractHttpClient.class.isInstance(client)) {
|
if (org.apache.http.impl.client.AbstractHttpClient.class.isInstance(client)) {
|
||||||
client.getParams().setIntParameter(
|
client.getParams().setIntParameter(org.apache.http.params.CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
|
||||||
org.apache.http.params.CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,8 +149,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
|||||||
* @see RequestConfig#getConnectionRequestTimeout()
|
* @see RequestConfig#getConnectionRequestTimeout()
|
||||||
*/
|
*/
|
||||||
public void setConnectionRequestTimeout(int connectionRequestTimeout) {
|
public void setConnectionRequestTimeout(int connectionRequestTimeout) {
|
||||||
this.requestConfig = cloneRequestConfig()
|
this.requestConfig = cloneRequestConfig().setConnectionRequestTimeout(connectionRequestTimeout).build();
|
||||||
.setConnectionRequestTimeout(connectionRequestTimeout).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -165,8 +162,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
|||||||
*/
|
*/
|
||||||
public void setReadTimeout(int timeout) {
|
public void setReadTimeout(int timeout) {
|
||||||
Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value");
|
Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value");
|
||||||
this.requestConfig = cloneRequestConfig()
|
this.requestConfig = cloneRequestConfig().setSocketTimeout(timeout).build();
|
||||||
.setSocketTimeout(timeout).build();
|
|
||||||
setLegacySocketTimeout(getHttpClient(), timeout);
|
setLegacySocketTimeout(getHttpClient(), timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,15 +176,10 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private void setLegacySocketTimeout(HttpClient client, int timeout) {
|
private void setLegacySocketTimeout(HttpClient client, int timeout) {
|
||||||
if (org.apache.http.impl.client.AbstractHttpClient.class.isInstance(client)) {
|
if (org.apache.http.impl.client.AbstractHttpClient.class.isInstance(client)) {
|
||||||
client.getParams().setIntParameter(
|
client.getParams().setIntParameter(org.apache.http.params.CoreConnectionPNames.SO_TIMEOUT, timeout);
|
||||||
org.apache.http.params.CoreConnectionPNames.SO_TIMEOUT, timeout);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private RequestConfig.Builder cloneRequestConfig() {
|
|
||||||
return this.requestConfig != null ? RequestConfig.copy(this.requestConfig) : RequestConfig.custom();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether this request factory should buffer the request body internally.
|
* Indicates whether this request factory should buffer the request body internally.
|
||||||
* <p>Default is {@code true}. When sending large amounts of data via POST or PUT, it is
|
* <p>Default is {@code true}. When sending large amounts of data via POST or PUT, it is
|
||||||
@@ -209,6 +200,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
|||||||
if (context == null) {
|
if (context == null) {
|
||||||
context = HttpClientContext.create();
|
context = HttpClientContext.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request configuration not set in the context
|
// Request configuration not set in the context
|
||||||
if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
|
if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
|
||||||
// Use request configuration given by the user, when available
|
// Use request configuration given by the user, when available
|
||||||
@@ -223,6 +215,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
|||||||
context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
|
context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.bufferRequestBody) {
|
if (this.bufferRequestBody) {
|
||||||
return new HttpComponentsClientHttpRequest(client, httpRequest, context);
|
return new HttpComponentsClientHttpRequest(client, httpRequest, context);
|
||||||
}
|
}
|
||||||
@@ -231,6 +224,11 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private RequestConfig.Builder cloneRequestConfig() {
|
||||||
|
return (this.requestConfig != null ? RequestConfig.copy(this.requestConfig) : RequestConfig.custom());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
|
* Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
|
||||||
* @param httpMethod the HTTP method
|
* @param httpMethod the HTTP method
|
||||||
@@ -241,20 +239,20 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
|||||||
switch (httpMethod) {
|
switch (httpMethod) {
|
||||||
case GET:
|
case GET:
|
||||||
return new HttpGet(uri);
|
return new HttpGet(uri);
|
||||||
case DELETE:
|
|
||||||
return new HttpDelete(uri);
|
|
||||||
case HEAD:
|
case HEAD:
|
||||||
return new HttpHead(uri);
|
return new HttpHead(uri);
|
||||||
case OPTIONS:
|
|
||||||
return new HttpOptions(uri);
|
|
||||||
case POST:
|
case POST:
|
||||||
return new HttpPost(uri);
|
return new HttpPost(uri);
|
||||||
case PUT:
|
case PUT:
|
||||||
return new HttpPut(uri);
|
return new HttpPut(uri);
|
||||||
case TRACE:
|
|
||||||
return new HttpTrace(uri);
|
|
||||||
case PATCH:
|
case PATCH:
|
||||||
return new HttpPatch(uri);
|
return new HttpPatch(uri);
|
||||||
|
case DELETE:
|
||||||
|
return new HttpDelete(uri);
|
||||||
|
case OPTIONS:
|
||||||
|
return new HttpOptions(uri);
|
||||||
|
case TRACE:
|
||||||
|
return new HttpTrace(uri);
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
|
throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
|
||||||
}
|
}
|
||||||
@@ -312,4 +310,5 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
|||||||
return "DELETE";
|
return "DELETE";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -42,52 +42,51 @@ class InterceptingClientHttpRequest extends AbstractBufferingClientHttpRequest {
|
|||||||
|
|
||||||
private URI uri;
|
private URI uri;
|
||||||
|
|
||||||
|
|
||||||
protected InterceptingClientHttpRequest(ClientHttpRequestFactory requestFactory,
|
protected InterceptingClientHttpRequest(ClientHttpRequestFactory requestFactory,
|
||||||
List<ClientHttpRequestInterceptor> interceptors,
|
List<ClientHttpRequestInterceptor> interceptors, URI uri, HttpMethod method) {
|
||||||
URI uri,
|
|
||||||
HttpMethod method) {
|
|
||||||
this.requestFactory = requestFactory;
|
this.requestFactory = requestFactory;
|
||||||
this.interceptors = interceptors;
|
this.interceptors = interceptors;
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpMethod getMethod() {
|
public HttpMethod getMethod() {
|
||||||
return method;
|
return this.method;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URI getURI() {
|
public URI getURI() {
|
||||||
return uri;
|
return this.uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException {
|
protected final ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException {
|
||||||
RequestExecution requestExecution = new RequestExecution();
|
InterceptingRequestExecution requestExecution = new InterceptingRequestExecution();
|
||||||
|
|
||||||
return requestExecution.execute(this, bufferedOutput);
|
return requestExecution.execute(this, bufferedOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RequestExecution implements ClientHttpRequestExecution {
|
|
||||||
|
private class InterceptingRequestExecution implements ClientHttpRequestExecution {
|
||||||
|
|
||||||
private final Iterator<ClientHttpRequestInterceptor> iterator;
|
private final Iterator<ClientHttpRequestInterceptor> iterator;
|
||||||
|
|
||||||
private RequestExecution() {
|
public InterceptingRequestExecution() {
|
||||||
this.iterator = interceptors.iterator();
|
this.iterator = interceptors.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientHttpResponse execute(HttpRequest request, byte[] body) throws IOException {
|
public ClientHttpResponse execute(HttpRequest request, byte[] body) throws IOException {
|
||||||
if (iterator.hasNext()) {
|
if (this.iterator.hasNext()) {
|
||||||
ClientHttpRequestInterceptor nextInterceptor = iterator.next();
|
ClientHttpRequestInterceptor nextInterceptor = this.iterator.next();
|
||||||
return nextInterceptor.intercept(request, body, this);
|
return nextInterceptor.intercept(request, body, this);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ClientHttpRequest delegate = requestFactory.createRequest(request.getURI(), request.getMethod());
|
ClientHttpRequest delegate = requestFactory.createRequest(request.getURI(), request.getMethod());
|
||||||
|
|
||||||
delegate.getHeaders().putAll(request.getHeaders());
|
delegate.getHeaders().putAll(request.getHeaders());
|
||||||
|
|
||||||
if (body.length > 0) {
|
if (body.length > 0) {
|
||||||
StreamUtils.copy(body, delegate.getBody());
|
StreamUtils.copy(body, delegate.getBody());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2011 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -32,20 +32,22 @@ public class InterceptingClientHttpRequestFactory extends AbstractClientHttpRequ
|
|||||||
|
|
||||||
private final List<ClientHttpRequestInterceptor> interceptors;
|
private final List<ClientHttpRequestInterceptor> interceptors;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of the {@code InterceptingClientHttpRequestFactory} with the given parameters.
|
* Create a new instance of the {@code InterceptingClientHttpRequestFactory} with the given parameters.
|
||||||
*
|
|
||||||
* @param requestFactory the request factory to wrap
|
* @param requestFactory the request factory to wrap
|
||||||
* @param interceptors the interceptors that are to be applied. Can be {@code null}.
|
* @param interceptors the interceptors that are to be applied (can be {@code null})
|
||||||
*/
|
*/
|
||||||
public InterceptingClientHttpRequestFactory(ClientHttpRequestFactory requestFactory,
|
public InterceptingClientHttpRequestFactory(ClientHttpRequestFactory requestFactory,
|
||||||
List<ClientHttpRequestInterceptor> interceptors) {
|
List<ClientHttpRequestInterceptor> interceptors) {
|
||||||
|
|
||||||
super(requestFactory);
|
super(requestFactory);
|
||||||
this.interceptors = interceptors != null ? interceptors : Collections.<ClientHttpRequestInterceptor>emptyList();
|
this.interceptors = (interceptors != null ? interceptors : Collections.<ClientHttpRequestInterceptor>emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod, ClientHttpRequestFactory requestFactory) {
|
protected ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod, ClientHttpRequestFactory requestFactory) {
|
||||||
return new InterceptingClientHttpRequest(requestFactory, interceptors, uri, httpMethod);
|
return new InterceptingClientHttpRequest(requestFactory, this.interceptors, uri, httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -136,6 +136,7 @@ public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory,
|
|||||||
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
|
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
|
||||||
HttpURLConnection connection = openConnection(uri.toURL(), this.proxy);
|
HttpURLConnection connection = openConnection(uri.toURL(), this.proxy);
|
||||||
prepareConnection(connection, httpMethod.name());
|
prepareConnection(connection, httpMethod.name());
|
||||||
|
|
||||||
if (this.bufferRequestBody) {
|
if (this.bufferRequestBody) {
|
||||||
return new SimpleBufferingClientHttpRequest(connection, this.outputStreaming);
|
return new SimpleBufferingClientHttpRequest(connection, this.outputStreaming);
|
||||||
}
|
}
|
||||||
@@ -146,20 +147,23 @@ public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
* <p>Setting the {@link #setTaskExecutor(org.springframework.core.task.AsyncListenableTaskExecutor) taskExecutor} property
|
* <p>Setting the {@link #setTaskExecutor taskExecutor} property is required before calling this method.
|
||||||
* is required before calling this method.
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
|
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
|
||||||
Assert.state(this.taskExecutor != null, "Asynchronous execution requires an AsyncTaskExecutor to be set");
|
Assert.state(this.taskExecutor != null,
|
||||||
|
"Asynchronous execution requires an AsyncTaskExecutor to be set");
|
||||||
|
|
||||||
HttpURLConnection connection = openConnection(uri.toURL(), this.proxy);
|
HttpURLConnection connection = openConnection(uri.toURL(), this.proxy);
|
||||||
prepareConnection(connection, httpMethod.name());
|
prepareConnection(connection, httpMethod.name());
|
||||||
|
|
||||||
if (this.bufferRequestBody) {
|
if (this.bufferRequestBody) {
|
||||||
return new SimpleBufferingAsyncClientHttpRequest(connection, this.outputStreaming, this.taskExecutor);
|
return new SimpleBufferingAsyncClientHttpRequest(
|
||||||
|
connection, this.outputStreaming, this.taskExecutor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new SimpleStreamingAsyncClientHttpRequest(connection, this.chunkSize,
|
return new SimpleStreamingAsyncClientHttpRequest(
|
||||||
this.outputStreaming, this.taskExecutor);
|
connection, this.chunkSize, this.outputStreaming, this.taskExecutor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,20 +196,24 @@ public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory,
|
|||||||
if (this.readTimeout >= 0) {
|
if (this.readTimeout >= 0) {
|
||||||
connection.setReadTimeout(this.readTimeout);
|
connection.setReadTimeout(this.readTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
|
|
||||||
if ("GET".equals(httpMethod)) {
|
if ("GET".equals(httpMethod)) {
|
||||||
connection.setInstanceFollowRedirects(true);
|
connection.setInstanceFollowRedirects(true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
connection.setInstanceFollowRedirects(false);
|
connection.setInstanceFollowRedirects(false);
|
||||||
}
|
}
|
||||||
if ("PUT".equals(httpMethod) || "POST".equals(httpMethod) ||
|
|
||||||
|
if ("POST".equals(httpMethod) || "PUT".equals(httpMethod) ||
|
||||||
"PATCH".equals(httpMethod) || "DELETE".equals(httpMethod)) {
|
"PATCH".equals(httpMethod) || "DELETE".equals(httpMethod)) {
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
connection.setDoOutput(false);
|
connection.setDoOutput(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.setRequestMethod(httpMethod);
|
connection.setRequestMethod(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -24,8 +24,10 @@ import org.springframework.http.HttpRequest;
|
|||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a convenient implementation of the {@link HttpRequest} interface that can be overridden to adapt the
|
* Provides a convenient implementation of the {@link HttpRequest} interface
|
||||||
* request. Methods default to calling through to the wrapped request object.
|
* that can be overridden to adapt the request.
|
||||||
|
*
|
||||||
|
* <p>These methods default to calling through to the wrapped request object.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
@@ -36,24 +38,24 @@ public class HttpRequestWrapper implements HttpRequest {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@code HttpRequest} wrapping the given request object.
|
* Create a new {@code HttpRequest} wrapping the given request object.
|
||||||
*
|
|
||||||
* @param request the request object to be wrapped
|
* @param request the request object to be wrapped
|
||||||
*/
|
*/
|
||||||
public HttpRequestWrapper(HttpRequest request) {
|
public HttpRequestWrapper(HttpRequest request) {
|
||||||
Assert.notNull(request, "'request' must not be null");
|
Assert.notNull(request, "HttpRequest must not be null");
|
||||||
this.request = request;
|
this.request = request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the wrapped request.
|
* Return the wrapped request.
|
||||||
*/
|
*/
|
||||||
public HttpRequest getRequest() {
|
public HttpRequest getRequest() {
|
||||||
return request;
|
return this.request;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the method of the wrapped request.
|
* Return the method of the wrapped request.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HttpMethod getMethod() {
|
public HttpMethod getMethod() {
|
||||||
@@ -61,7 +63,7 @@ public class HttpRequestWrapper implements HttpRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the URI of the wrapped request.
|
* Return the URI of the wrapped request.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public URI getURI() {
|
public URI getURI() {
|
||||||
@@ -69,7 +71,7 @@ public class HttpRequestWrapper implements HttpRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the headers of the wrapped request.
|
* Return the headers of the wrapped request.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HttpHeaders getHeaders() {
|
public HttpHeaders getHeaders() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -166,18 +166,30 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isFormPost(HttpServletRequest request) {
|
@Override
|
||||||
return (request.getContentType() != null && request.getContentType().contains(FORM_CONTENT_TYPE) &&
|
public ServerHttpAsyncRequestControl getAsyncRequestControl(ServerHttpResponse response) {
|
||||||
|
if (this.asyncRequestControl == null) {
|
||||||
|
Assert.isInstanceOf(ServletServerHttpResponse.class, response);
|
||||||
|
ServletServerHttpResponse servletServerResponse = (ServletServerHttpResponse) response;
|
||||||
|
this.asyncRequestControl = new ServletServerHttpAsyncRequestControl(this, servletServerResponse);
|
||||||
|
}
|
||||||
|
return this.asyncRequestControl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static boolean isFormPost(HttpServletRequest request) {
|
||||||
|
String contentType = request.getContentType();
|
||||||
|
return (contentType != null && contentType.contains(FORM_CONTENT_TYPE) &&
|
||||||
METHOD_POST.equalsIgnoreCase(request.getMethod()));
|
METHOD_POST.equalsIgnoreCase(request.getMethod()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use {@link javax.servlet.ServletRequest#getParameterMap()} to reconstruct the
|
* Use {@link javax.servlet.ServletRequest#getParameterMap()} to reconstruct the
|
||||||
* body of a form 'POST' providing a predictable outcome as opposed to reading
|
* body of a form 'POST' providing a predictable outcome as opposed to reading
|
||||||
* from the body, which can fail if any other code has used ServletRequest
|
* from the body, which can fail if any other code has used the ServletRequest
|
||||||
* to access a parameter thus causing the input stream to be "consumed".
|
* to access a parameter, thus causing the input stream to be "consumed".
|
||||||
*/
|
*/
|
||||||
private InputStream getBodyFromServletRequestParameters(HttpServletRequest request) throws IOException {
|
private static InputStream getBodyFromServletRequestParameters(HttpServletRequest request) throws IOException {
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
|
ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
|
||||||
Writer writer = new OutputStreamWriter(bos, FORM_CHARSET);
|
Writer writer = new OutputStreamWriter(bos, FORM_CHARSET);
|
||||||
|
|
||||||
@@ -205,14 +217,4 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
|
|||||||
return new ByteArrayInputStream(bos.toByteArray());
|
return new ByteArrayInputStream(bos.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ServerHttpAsyncRequestControl getAsyncRequestControl(ServerHttpResponse response) {
|
|
||||||
if (this.asyncRequestControl == null) {
|
|
||||||
Assert.isInstanceOf(ServletServerHttpResponse.class, response);
|
|
||||||
ServletServerHttpResponse servletServerResponse = (ServletServerHttpResponse) response;
|
|
||||||
this.asyncRequestControl = new ServletServerHttpAsyncRequestControl(this, servletServerResponse);
|
|
||||||
}
|
|
||||||
return this.asyncRequestControl;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,16 +17,14 @@
|
|||||||
package org.springframework.web.bind.annotation;
|
package org.springframework.web.bind.annotation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java 5 enumeration of HTTP request methods. Intended for use
|
* Java 5 enumeration of HTTP request methods. Intended for use with the
|
||||||
* with the {@link RequestMapping#method()} attribute of the
|
* {@link RequestMapping#method()} attribute of the {@link RequestMapping} annotation.
|
||||||
* {@link RequestMapping} annotation.
|
|
||||||
*
|
*
|
||||||
* <p>Note that, by default, {@link org.springframework.web.servlet.DispatcherServlet}
|
* <p>Note that, by default, {@link org.springframework.web.servlet.DispatcherServlet}
|
||||||
* supports GET, HEAD, POST, PUT, PATCH and DELETE only. DispatcherServlet will
|
* supports GET, HEAD, POST, PUT, PATCH and DELETE only. DispatcherServlet will
|
||||||
* process TRACE and OPTIONS with the default HttpServlet behavior unless
|
* process TRACE and OPTIONS with the default HttpServlet behavior unless explicitly
|
||||||
* explicitly told to dispatch those request types as well: Check out
|
* told to dispatch those request types as well: Check out the "dispatchOptionsRequest"
|
||||||
* the "dispatchOptionsRequest" and "dispatchTraceRequest" properties,
|
* and "dispatchTraceRequest" properties, switching them to "true" if necessary.
|
||||||
* switching them to "true" if necessary.
|
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
|
|||||||
@@ -1137,9 +1137,8 @@ public class DispatcherServlet extends FrameworkServlet {
|
|||||||
"] in DispatcherServlet with name '" + getServletName() + "'");
|
"] in DispatcherServlet with name '" + getServletName() + "'");
|
||||||
}
|
}
|
||||||
if (this.throwExceptionIfNoHandlerFound) {
|
if (this.throwExceptionIfNoHandlerFound) {
|
||||||
ServletServerHttpRequest sshr = new ServletServerHttpRequest(request);
|
throw new NoHandlerFoundException(request.getMethod(), getRequestUri(request),
|
||||||
throw new NoHandlerFoundException(
|
new ServletServerHttpRequest(request).getHeaders());
|
||||||
sshr.getMethod().name(), sshr.getServletRequest().getRequestURI(), sshr.getHeaders());
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||||
|
|||||||
@@ -828,15 +828,13 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override the parent class implementation in order to intercept PATCH
|
* Override the parent class implementation in order to intercept PATCH requests.
|
||||||
* requests.
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void service(HttpServletRequest request, HttpServletResponse response)
|
protected void service(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
|
|
||||||
String method = request.getMethod();
|
if (RequestMethod.PATCH.name().equalsIgnoreCase(request.getMethod())) {
|
||||||
if (method.equalsIgnoreCase(RequestMethod.PATCH.name())) {
|
|
||||||
processRequest(request, response);
|
processRequest(request, response);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -41,36 +41,39 @@ abstract class AbstractMediaTypeExpression implements Comparable<AbstractMediaTy
|
|||||||
|
|
||||||
private final boolean isNegated;
|
private final boolean isNegated;
|
||||||
|
|
||||||
|
|
||||||
AbstractMediaTypeExpression(String expression) {
|
AbstractMediaTypeExpression(String expression) {
|
||||||
if (expression.startsWith("!")) {
|
if (expression.startsWith("!")) {
|
||||||
isNegated = true;
|
this.isNegated = true;
|
||||||
expression = expression.substring(1);
|
expression = expression.substring(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
isNegated = false;
|
this.isNegated = false;
|
||||||
}
|
}
|
||||||
this.mediaType = MediaType.parseMediaType(expression);
|
this.mediaType = MediaType.parseMediaType(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractMediaTypeExpression(MediaType mediaType, boolean negated) {
|
AbstractMediaTypeExpression(MediaType mediaType, boolean negated) {
|
||||||
this.mediaType = mediaType;
|
this.mediaType = mediaType;
|
||||||
isNegated = negated;
|
this.isNegated = negated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MediaType getMediaType() {
|
public MediaType getMediaType() {
|
||||||
return mediaType;
|
return this.mediaType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNegated() {
|
public boolean isNegated() {
|
||||||
return isNegated;
|
return this.isNegated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public final boolean match(HttpServletRequest request) {
|
public final boolean match(HttpServletRequest request) {
|
||||||
try {
|
try {
|
||||||
boolean match = matchMediaType(request);
|
boolean match = matchMediaType(request);
|
||||||
return !isNegated ? match : !match;
|
return (!this.isNegated ? match : !match);
|
||||||
}
|
}
|
||||||
catch (HttpMediaTypeException ex) {
|
catch (HttpMediaTypeException ex) {
|
||||||
return false;
|
return false;
|
||||||
@@ -79,6 +82,7 @@ abstract class AbstractMediaTypeExpression implements Comparable<AbstractMediaTy
|
|||||||
|
|
||||||
protected abstract boolean matchMediaType(HttpServletRequest request) throws HttpMediaTypeException;
|
protected abstract boolean matchMediaType(HttpServletRequest request) throws HttpMediaTypeException;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(AbstractMediaTypeExpression other) {
|
public int compareTo(AbstractMediaTypeExpression other) {
|
||||||
return MediaType.SPECIFICITY_COMPARATOR.compare(this.getMediaType(), other.getMediaType());
|
return MediaType.SPECIFICITY_COMPARATOR.compare(this.getMediaType(), other.getMediaType());
|
||||||
@@ -91,23 +95,23 @@ abstract class AbstractMediaTypeExpression implements Comparable<AbstractMediaTy
|
|||||||
}
|
}
|
||||||
if (obj != null && getClass().equals(obj.getClass())) {
|
if (obj != null && getClass().equals(obj.getClass())) {
|
||||||
AbstractMediaTypeExpression other = (AbstractMediaTypeExpression) obj;
|
AbstractMediaTypeExpression other = (AbstractMediaTypeExpression) obj;
|
||||||
return (this.mediaType.equals(other.mediaType)) && (this.isNegated == other.isNegated);
|
return (this.mediaType.equals(other.mediaType) && this.isNegated == other.isNegated);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return mediaType.hashCode();
|
return this.mediaType.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
if (isNegated) {
|
if (this.isNegated) {
|
||||||
builder.append('!');
|
builder.append('!');
|
||||||
}
|
}
|
||||||
builder.append(mediaType.toString());
|
builder.append(this.mediaType.toString());
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user