Skip to content

Commit cff67cc

Browse files
artembilangaryrussell
authored andcommitted
Fix complexity for DefaultHttpHeaderMapper (#2881)
* Fix complexity for DefaultHttpHeaderMapper * Deprecate `DefaultHttpHeaderMapper` constants which are fully Spring Web `HttpHeaders` constants * Introduce lowercase constants for `getHttpHeader()` switch * Reuse `HttpHeaders` API as much as possible * Simplify logic in some methods to break them to smaller methods * * Remove Java Streams from critical paths * Rework `setHttpHeader()` for `switch` * * Use `ObjectUtils.toObjectArray()` to simplify complexity * * Fix complexity in `setAccept()`, `setAcceptCharset()`, `setAllow()` & `setIfNoneMatch()` using newly extracted `valueToCollection()`
1 parent 2e2b49a commit cff67cc

File tree

5 files changed

+1008
-824
lines changed

5 files changed

+1008
-824
lines changed

spring-integration-http/src/main/java/org/springframework/integration/http/outbound/AbstractHttpRequestExecutingMessageHandler.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ public void setExpectReply(boolean expectReply) {
188188
* be returned as a payload of the reply Message.
189189
* To take advantage of the HttpMessageConverters
190190
* registered on this adapter, provide a different type).
191-
*
192191
* @param expectedResponseType The expected type.
193-
*
194192
* Also see {@link #setExpectedResponseTypeExpression(Expression)}
195193
*/
196194
public void setExpectedResponseType(Class<?> expectedResponseType) {
@@ -221,7 +219,6 @@ public void setHeaderMapper(HeaderMapper<HttpHeaders> headerMapper) {
221219
/**
222220
* Set the Map of URI variable expressions to evaluate against the outbound message
223221
* when replacing the variable placeholders in a URI template.
224-
*
225222
* @param uriVariableExpressions The URI variable expressions.
226223
*/
227224
public void setUriVariableExpressions(Map<String, Expression> uriVariableExpressions) {
@@ -235,7 +232,6 @@ public void setUriVariableExpressions(Map<String, Expression> uriVariableExpress
235232
* Set the {@link Expression} to evaluate against the outbound message; the expression
236233
* must evaluate to a Map of URI variable expressions to evaluate against the outbound message
237234
* when replacing the variable placeholders in a URI template.
238-
*
239235
* @param uriVariablesExpression The URI variables expression.
240236
*/
241237
public void setUriVariablesExpression(Expression uriVariablesExpression) {
@@ -246,7 +242,6 @@ public void setUriVariablesExpression(Expression uriVariablesExpression) {
246242
* Set to true if you wish 'Set-Cookie' headers in responses to be
247243
* transferred as 'Cookie' headers in subsequent interactions for
248244
* a message.
249-
*
250245
* @param transferCookies the transferCookies to set.
251246
*/
252247
public void setTransferCookies(boolean transferCookies) {
@@ -343,14 +338,14 @@ protected Object getReply(ResponseEntity<?> httpResponse) {
343338
private void doConvertSetCookie(Map<String, Object> headers) {
344339
String keyName = null;
345340
for (String key : headers.keySet()) {
346-
if (key.equalsIgnoreCase(DefaultHttpHeaderMapper.SET_COOKIE)) {
341+
if (key.equalsIgnoreCase(HttpHeaders.SET_COOKIE)) {
347342
keyName = key;
348343
break;
349344
}
350345
}
351346
if (keyName != null) {
352347
Object cookies = headers.remove(keyName);
353-
headers.put(DefaultHttpHeaderMapper.COOKIE, cookies);
348+
headers.put(HttpHeaders.COOKIE, cookies);
354349
if (logger.isDebugEnabled()) {
355350
logger.debug("Converted Set-Cookie header to Cookie for: "
356351
+ cookies);
@@ -562,7 +557,6 @@ private Object determineExpectedResponseType(Message<?> requestMessage) {
562557
.usingEvaluationContext(evaluationContextToUse)
563558
.withRoot(requestMessage)
564559
.build();
565-
566560
}
567561

568562
}

spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@
6161
* @since 2.0
6262
*/
6363
public class HttpRequestExecutingMessageHandler extends AbstractHttpRequestExecutingMessageHandler {
64+
6465
private final RestTemplate restTemplate;
6566

6667
/**
6768
* Create a handler that will send requests to the provided URI.
68-
*
6969
* @param uri The URI.
7070
*/
7171
public HttpRequestExecutingMessageHandler(URI uri) {
@@ -74,7 +74,6 @@ public HttpRequestExecutingMessageHandler(URI uri) {
7474

7575
/**
7676
* Create a handler that will send requests to the provided URI.
77-
*
7877
* @param uri The URI.
7978
*/
8079
public HttpRequestExecutingMessageHandler(String uri) {
@@ -83,7 +82,6 @@ public HttpRequestExecutingMessageHandler(String uri) {
8382

8483
/**
8584
* Create a handler that will send requests to the provided URI Expression.
86-
*
8785
* @param uriExpression The URI expression.
8886
*/
8987
public HttpRequestExecutingMessageHandler(Expression uriExpression) {
@@ -142,9 +140,7 @@ public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters
142140

143141
/**
144142
* Set the {@link ClientHttpRequestFactory} for the underlying {@link RestTemplate}.
145-
*
146143
* @param requestFactory The request factory.
147-
*
148144
* @see RestTemplate#setRequestFactory(ClientHttpRequestFactory)
149145
*/
150146
public void setRequestFactory(ClientHttpRequestFactory requestFactory) {
@@ -154,6 +150,7 @@ public void setRequestFactory(ClientHttpRequestFactory requestFactory) {
154150
@Override
155151
protected Object exchange(Supplier<URI> uriSupplier, HttpMethod httpMethod, HttpEntity<?> httpRequest,
156152
Object expectedResponseType, Message<?> requestMessage) {
153+
157154
URI uri = uriSupplier.get();
158155
ResponseEntity<?> httpResponse;
159156
try {
@@ -162,14 +159,13 @@ protected Object exchange(Supplier<URI> uriSupplier, HttpMethod httpMethod, Http
162159
(ParameterizedTypeReference<?>) expectedResponseType);
163160
}
164161
else {
165-
httpResponse = this.restTemplate.exchange(uri, httpMethod, httpRequest,
166-
(Class<?>) expectedResponseType);
162+
httpResponse = this.restTemplate.exchange(uri, httpMethod, httpRequest, (Class<?>) expectedResponseType);
167163
}
168164
return getReply(httpResponse);
169165
}
170166
catch (RestClientException e) {
171-
throw new MessageHandlingException(requestMessage,
172-
"HTTP request execution failed for URI [" + uri + "]", e);
167+
throw new MessageHandlingException(requestMessage, "HTTP request execution failed for URI [" + uri + "]", e);
173168
}
174169
}
170+
175171
}

0 commit comments

Comments
 (0)