diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParser.java b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParser.java index ae0bcb993a..09184c7100 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParser.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParser.java @@ -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"); * you may not use this file except in compliance with the License. @@ -62,7 +62,7 @@ public class HttpOutboundChannelAdapterParser extends AbstractOutboundChannelAda String mappedRequestHeaders = element.getAttribute("mapped-request-headers"); if (StringUtils.hasText(headerMapper)) { if (StringUtils.hasText(mappedRequestHeaders)) { - parserContext.getReaderContext().error("The 'mappped-request-headers' attribute is not " + + parserContext.getReaderContext().error("The 'mapped-request-headers' attribute is not " + "allowed when a 'header-mapper' has been specified.", parserContext.extractSource(element)); return null; } diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundGatewayParser.java b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundGatewayParser.java index ebbccd5f20..e59176f776 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundGatewayParser.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundGatewayParser.java @@ -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"); * you may not use this file except in compliance with the License. @@ -66,7 +66,7 @@ public class HttpOutboundGatewayParser extends AbstractConsumerEndpointParser { String mappedResponseHeaders = element.getAttribute("mapped-response-headers"); if (StringUtils.hasText(headerMapper)) { if (StringUtils.hasText(mappedRequestHeaders) || StringUtils.hasText(mappedResponseHeaders)) { - parserContext.getReaderContext().error("Neither 'mappped-request-headers' or 'mapped-response-headers' " + + parserContext.getReaderContext().error("Neither 'mapped-request-headers' or 'mapped-response-headers' " + "attributes are allowed when a 'header-mapper' has been specified.", parserContext.extractSource(element)); return null; } diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingEndpointSupport.java b/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingEndpointSupport.java index 7b65d6a840..3541d25f63 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingEndpointSupport.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingEndpointSupport.java @@ -116,7 +116,7 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa private static final boolean jaxb2Present = ClassUtils.isPresent("javax.xml.bind.Binder", HttpRequestHandlingEndpointSupport.class.getClassLoader()); - private static boolean romeToolsPresent = ClassUtils.isPresent("com.rometools.rome.feed.atom.Feed", + private static final boolean romeToolsPresent = ClassUtils.isPresent("com.rometools.rome.feed.atom.Feed", HttpRequestHandlingEndpointSupport.class.getClassLoader()); private static final List nonReadableBodyHttpMethods = @@ -580,8 +580,7 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa this.evaluationContext = createEvaluationContext(); } Object value = this.statusCodeExpression.getValue(this.evaluationContext); - HttpStatus httpStatus = buildHttpStatus(value); - return httpStatus; + return buildHttpStatus(value); } /** diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java b/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java index b67ad9ff98..7ca35ad396 100755 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java @@ -103,7 +103,7 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe private volatile boolean extractPayloadExplicitlySet = false; - private volatile String charset = "UTF-8"; + private volatile Charset charset = Charset.forName("UTF-8"); private volatile boolean transferCookies = false; @@ -219,7 +219,7 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe */ public void setCharset(String charset) { Assert.isTrue(Charset.isSupported(charset), "unsupported charset '" + charset + "'"); - this.charset = charset; + this.charset = Charset.forName(charset); } /** @@ -245,17 +245,15 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe */ public void setExpectedResponseType(Class expectedResponseType) { Assert.notNull(expectedResponseType, "'expectedResponseType' must not be null"); - this.expectedResponseTypeExpression = new LiteralExpression(expectedResponseType.getName()); + this.expectedResponseTypeExpression = new ValueExpression>(expectedResponseType); } /** * Specify the {@link Expression} to determine the type for the expected response * The returned value of the expression could be an instance of {@link Class} or * {@link String} representing a fully qualified class name - * * @param expectedResponseTypeExpression The expected response type expression. - * - * Also see {@link #setExpectedResponseTypeExpression(Expression)} + * Also see {@link #setExpectedResponseType} */ public void setExpectedResponseTypeExpression(Expression expectedResponseTypeExpression) { this.expectedResponseTypeExpression = expectedResponseTypeExpression; @@ -452,8 +450,9 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe } // otherwise, we are creating a request with a body and need to deal with the content-type header as well if (httpHeaders.getContentType() == null) { - MediaType contentType = (payload instanceof String) ? this.resolveContentType((String) payload, this.charset) - : this.resolveContentType(payload); + MediaType contentType = (payload instanceof String) + ? resolveContentType((String) payload, this.charset) + : resolveContentType(payload); httpHeaders.setContentType(contentType); } if (MediaType.APPLICATION_FORM_URLENCODED.equals(httpHeaders.getContentType()) || @@ -511,8 +510,8 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe return !HttpMethod.GET.equals(httpMethod); } - private MediaType resolveContentType(String content, String charset) { - return new MediaType("text", "plain", Charset.forName(charset)); + private MediaType resolveContentType(String content, Charset charset) { + return new MediaType("text", "plain", charset); } private MultiValueMap convertToMultiValueMap(Map simpleMap) { @@ -602,7 +601,8 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe "'expectedResponseType' can be an instance of 'Class', 'String' or 'ParameterizedTypeReference'; " + "evaluation resulted in a" + expectedResponseType.getClass() + "."); if (expectedResponseType instanceof String && StringUtils.hasText((String) expectedResponseType)){ - expectedResponseType = ClassUtils.forName((String) expectedResponseType, ClassUtils.getDefaultClassLoader()); + expectedResponseType = ClassUtils.forName((String) expectedResponseType, + getApplicationContext().getClassLoader()); } } return expectedResponseType; diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParserTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParserTests.java index 236da46498..55245c9d53 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParserTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParserTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import java.io.IOException; +import java.nio.charset.Charset; import java.util.Map; import org.hamcrest.Matchers; @@ -118,7 +119,7 @@ public class HttpOutboundChannelAdapterParserTests { Expression uriExpression = (Expression) handlerAccessor.getPropertyValue("uriExpression"); assertEquals("http://localhost/test1", uriExpression.getValue()); assertEquals(HttpMethod.POST.name(), TestUtils.getPropertyValue(handler, "httpMethodExpression", Expression.class).getExpressionString()); - assertEquals("UTF-8", handlerAccessor.getPropertyValue("charset")); + assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset")); assertEquals(true, handlerAccessor.getPropertyValue("extractPayload")); } @@ -147,7 +148,7 @@ public class HttpOutboundChannelAdapterParserTests { Expression uriExpression = (Expression) handlerAccessor.getPropertyValue("uriExpression"); assertEquals("http://localhost/test2/{foo}", uriExpression.getValue()); assertEquals(HttpMethod.GET.name(), TestUtils.getPropertyValue(handler, "httpMethodExpression", Expression.class).getExpressionString()); - assertEquals("UTF-8", handlerAccessor.getPropertyValue("charset")); + assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset")); assertEquals(false, handlerAccessor.getPropertyValue("extractPayload")); Map uriVariableExpressions = (Map) handlerAccessor.getPropertyValue("uriVariableExpressions"); @@ -192,7 +193,7 @@ public class HttpOutboundChannelAdapterParserTests { Expression uriExpression = (Expression) handlerAccessor.getPropertyValue("uriExpression"); assertEquals("http://localhost/test1", uriExpression.getValue()); assertEquals(HttpMethod.POST.name(), TestUtils.getPropertyValue(handler, "httpMethodExpression", Expression.class).getExpressionString()); - assertEquals("UTF-8", handlerAccessor.getPropertyValue("charset")); + assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset")); assertEquals(true, handlerAccessor.getPropertyValue("extractPayload")); //INT-3055 @@ -223,7 +224,7 @@ public class HttpOutboundChannelAdapterParserTests { assertNotNull(expression); assertEquals("'http://localhost/test1'", expression.getExpressionString()); assertEquals(HttpMethod.POST.name(), TestUtils.getPropertyValue(handler, "httpMethodExpression", Expression.class).getExpressionString()); - assertEquals("UTF-8", handlerAccessor.getPropertyValue("charset")); + assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset")); assertEquals(true, handlerAccessor.getPropertyValue("extractPayload")); } @@ -253,7 +254,7 @@ public class HttpOutboundChannelAdapterParserTests { assertNotNull(expression); assertEquals("'http://localhost/test1'", expression.getExpressionString()); assertEquals(HttpMethod.POST.name(), TestUtils.getPropertyValue(handler, "httpMethodExpression", Expression.class).getExpressionString()); - assertEquals("UTF-8", handlerAccessor.getPropertyValue("charset")); + assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset")); assertEquals(true, handlerAccessor.getPropertyValue("extractPayload")); } diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayParserTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayParserTests.java index a42109e963..8bff4a2b89 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayParserTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayParserTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; +import java.nio.charset.Charset; import java.util.Map; import org.hamcrest.Matchers; @@ -102,7 +103,7 @@ public class HttpOutboundGatewayParserTests { Expression uriExpression = (Expression) handlerAccessor.getPropertyValue("uriExpression"); assertEquals("http://localhost/test1", uriExpression.getValue()); assertEquals(HttpMethod.POST.name(), TestUtils.getPropertyValue(handler, "httpMethodExpression", Expression.class).getExpressionString()); - assertEquals("UTF-8", handlerAccessor.getPropertyValue("charset")); + assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset")); assertEquals(true, handlerAccessor.getPropertyValue("extractPayload")); assertEquals(false, handlerAccessor.getPropertyValue("transferCookies")); } @@ -132,7 +133,7 @@ public class HttpOutboundGatewayParserTests { Expression uriExpression = (Expression) handlerAccessor.getPropertyValue("uriExpression"); assertEquals("http://localhost/test2", uriExpression.getValue()); assertEquals(HttpMethod.PUT.name(), TestUtils.getPropertyValue(handler, "httpMethodExpression", Expression.class).getExpressionString()); - assertEquals("UTF-8", handlerAccessor.getPropertyValue("charset")); + assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset")); assertEquals(false, handlerAccessor.getPropertyValue("extractPayload")); Object requestFactoryBean = this.applicationContext.getBean("testRequestFactory"); assertEquals(requestFactoryBean, requestFactory); @@ -174,7 +175,7 @@ public class HttpOutboundGatewayParserTests { assertNotNull(expression); assertEquals("'http://localhost/test1'", expression.getExpressionString()); assertEquals(HttpMethod.POST.name(), TestUtils.getPropertyValue(handler, "httpMethodExpression", Expression.class).getExpressionString()); - assertEquals("UTF-8", handlerAccessor.getPropertyValue("charset")); + assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset")); assertEquals(true, handlerAccessor.getPropertyValue("extractPayload")); assertEquals(false, handlerAccessor.getPropertyValue("transferCookies"));