Some various upgrades, fixes and refactoring
* Upgrade to SA and SF snapshots * Address TODOs regarding those upgrades * Resolve some other TODOs * Replace `PropertyPlaceholderConfigurer` beans with the `<context:property-placeholder>` * Upgrade to Spring Social Twitter 1.1.2 and resolve deprecations via mocks (https://github.com/spring-projects/spring-social-twitter/issues/91) * Upgrade to Curator `3.1.0` and resolve deprecation in the `ZookeeperMetadataStore`
This commit is contained in:
@@ -51,8 +51,7 @@ public class SimpleMultipartFileReader implements MultipartFileReader<Object> {
|
||||
public Object readMultipartFile(MultipartFile multipartFile) throws IOException {
|
||||
if (multipartFile.getContentType() != null && multipartFile.getContentType().startsWith("text")) {
|
||||
MediaType contentType = MediaType.parseMediaType(multipartFile.getContentType());
|
||||
// TODO there is no yet in the SF-4.3.RC1 a MediaType.getCharset() method
|
||||
Charset charset = contentType.getCharSet();
|
||||
Charset charset = contentType.getCharset();
|
||||
if (charset == null) {
|
||||
charset = this.defaultCharset;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -37,8 +36,6 @@ import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerExecutionChain;
|
||||
@@ -53,11 +50,6 @@ import org.springframework.web.servlet.HandlerInterceptor;
|
||||
@DirtiesContext
|
||||
public class CrossOriginTests {
|
||||
|
||||
// SPR-13130
|
||||
private static boolean isSpring43 =
|
||||
ClassUtils.isPresent("org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping$HttpOptionsHandler",
|
||||
CrossOriginTests.class.getClassLoader());
|
||||
|
||||
@Autowired
|
||||
private IntegrationRequestMappingHandlerMapping handlerMapping;
|
||||
|
||||
@@ -101,10 +93,10 @@ public class CrossOriginTests {
|
||||
HandlerExecutionChain chain = this.handlerMapping.getHandler(this.request);
|
||||
CorsConfiguration config = getCorsConfiguration(chain, false);
|
||||
assertNotNull(config);
|
||||
assertArrayEquals(new String[]{"GET"}, config.getAllowedMethods().toArray());
|
||||
assertArrayEquals(new String[]{"*"}, config.getAllowedOrigins().toArray());
|
||||
assertArrayEquals(new String[] { "GET" }, config.getAllowedMethods().toArray());
|
||||
assertArrayEquals(new String[] { "*" }, config.getAllowedOrigins().toArray());
|
||||
assertTrue(config.getAllowCredentials());
|
||||
assertArrayEquals(new String[]{"*"}, config.getAllowedHeaders().toArray());
|
||||
assertArrayEquals(new String[] { "*" }, config.getAllowedHeaders().toArray());
|
||||
assertNull(config.getExposedHeaders());
|
||||
assertEquals(new Long(1800), config.getMaxAge());
|
||||
}
|
||||
@@ -115,10 +107,10 @@ public class CrossOriginTests {
|
||||
HandlerExecutionChain chain = this.handlerMapping.getHandler(this.request);
|
||||
CorsConfiguration config = getCorsConfiguration(chain, false);
|
||||
assertNotNull(config);
|
||||
assertArrayEquals(new String[]{"DELETE"}, config.getAllowedMethods().toArray());
|
||||
assertArrayEquals(new String[]{"http://site1.com", "http://site2.com"}, config.getAllowedOrigins().toArray());
|
||||
assertArrayEquals(new String[]{"header1", "header2"}, config.getAllowedHeaders().toArray());
|
||||
assertArrayEquals(new String[]{"header3", "header4"}, config.getExposedHeaders().toArray());
|
||||
assertArrayEquals(new String[] { "DELETE" }, config.getAllowedMethods().toArray());
|
||||
assertArrayEquals(new String[] { "http://site1.com", "http://site2.com" }, config.getAllowedOrigins().toArray());
|
||||
assertArrayEquals(new String[] { "header1", "header2" }, config.getAllowedHeaders().toArray());
|
||||
assertArrayEquals(new String[] { "header3", "header4" }, config.getExposedHeaders().toArray());
|
||||
assertEquals(new Long(123), config.getMaxAge());
|
||||
assertEquals(false, config.getAllowCredentials());
|
||||
}
|
||||
@@ -131,10 +123,10 @@ public class CrossOriginTests {
|
||||
HandlerExecutionChain chain = this.handlerMapping.getHandler(this.request);
|
||||
CorsConfiguration config = getCorsConfiguration(chain, true);
|
||||
assertNotNull(config);
|
||||
assertArrayEquals(new String[]{"GET"}, config.getAllowedMethods().toArray());
|
||||
assertArrayEquals(new String[]{"*"}, config.getAllowedOrigins().toArray());
|
||||
assertArrayEquals(new String[] { "GET" }, config.getAllowedMethods().toArray());
|
||||
assertArrayEquals(new String[] { "*" }, config.getAllowedOrigins().toArray());
|
||||
assertTrue(config.getAllowCredentials());
|
||||
assertArrayEquals(new String[]{"*"}, config.getAllowedHeaders().toArray());
|
||||
assertArrayEquals(new String[] { "*" }, config.getAllowedHeaders().toArray());
|
||||
assertNull(config.getExposedHeaders());
|
||||
assertEquals(new Long(1800), config.getMaxAge());
|
||||
}
|
||||
@@ -148,9 +140,9 @@ public class CrossOriginTests {
|
||||
HandlerExecutionChain chain = this.handlerMapping.getHandler(this.request);
|
||||
CorsConfiguration config = getCorsConfiguration(chain, true);
|
||||
assertNotNull(config);
|
||||
assertArrayEquals(new String[]{"*"}, config.getAllowedMethods().toArray());
|
||||
assertArrayEquals(new String[]{"*"}, config.getAllowedOrigins().toArray());
|
||||
assertArrayEquals(new String[]{"*"}, config.getAllowedHeaders().toArray());
|
||||
assertArrayEquals(new String[] { "*" }, config.getAllowedMethods().toArray());
|
||||
assertArrayEquals(new String[] { "*" }, config.getAllowedOrigins().toArray());
|
||||
assertArrayEquals(new String[] { "*" }, config.getAllowedHeaders().toArray());
|
||||
assertTrue(config.getAllowCredentials());
|
||||
assertNull(config.getExposedHeaders());
|
||||
assertNull(config.getMaxAge());
|
||||
@@ -164,9 +156,9 @@ public class CrossOriginTests {
|
||||
HandlerExecutionChain chain = this.handlerMapping.getHandler(this.request);
|
||||
CorsConfiguration config = getCorsConfiguration(chain, true);
|
||||
assertNotNull(config);
|
||||
assertArrayEquals(new String[]{"*"}, config.getAllowedMethods().toArray());
|
||||
assertArrayEquals(new String[]{"*"}, config.getAllowedOrigins().toArray());
|
||||
assertArrayEquals(new String[]{"*"}, config.getAllowedHeaders().toArray());
|
||||
assertArrayEquals(new String[] { "*" }, config.getAllowedMethods().toArray());
|
||||
assertArrayEquals(new String[] { "*" }, config.getAllowedOrigins().toArray());
|
||||
assertArrayEquals(new String[] { "*" }, config.getAllowedHeaders().toArray());
|
||||
assertTrue(config.getAllowCredentials());
|
||||
assertNull(config.getExposedHeaders());
|
||||
assertNull(config.getMaxAge());
|
||||
@@ -176,23 +168,13 @@ public class CrossOriginTests {
|
||||
public void testOptionsHeaderHandling() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("OPTIONS", "/default");
|
||||
request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
|
||||
try {
|
||||
HandlerExecutionChain handler = this.handlerMapping.getHandler(request);
|
||||
if (isSpring43) {
|
||||
// SPR-13130
|
||||
assertNotNull(handler);
|
||||
Object handlerMethod = handler.getHandler();
|
||||
assertNotNull(handlerMethod);
|
||||
assertThat(handlerMethod, instanceOf(HandlerMethod.class));
|
||||
assertThat(((HandlerMethod) handlerMethod).getBeanType().getName(),
|
||||
containsString("HttpOptionsHandler"));
|
||||
return;
|
||||
}
|
||||
fail("HttpRequestMethodNotSupportedException expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e, instanceOf(HttpRequestMethodNotSupportedException.class));
|
||||
}
|
||||
HandlerExecutionChain handler = this.handlerMapping.getHandler(request);
|
||||
assertNotNull(handler);
|
||||
Object handlerMethod = handler.getHandler();
|
||||
assertNotNull(handlerMethod);
|
||||
assertThat(handlerMethod, instanceOf(HandlerMethod.class));
|
||||
assertThat(((HandlerMethod) handlerMethod).getBeanType().getName(),
|
||||
containsString("HttpOptionsHandler"));
|
||||
}
|
||||
|
||||
private CorsConfiguration getCorsConfiguration(HandlerExecutionChain chain, boolean isPreFlightRequest) {
|
||||
|
||||
@@ -4,19 +4,14 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration/http
|
||||
http://www.springframework.org/schema/integration/http/spring-integration-http.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
|
||||
|
||||
<mvc:annotation-driven/>
|
||||
|
||||
<!-- TODO SF-4.3.RC1 compatibility. TODO SF-4.3.RC1 compatibility. See https://jira.spring.io/browse/SPR-14140 -->
|
||||
<context:property-placeholder/>
|
||||
|
||||
<graph-controller path="/foo"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -34,10 +34,8 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
@@ -147,12 +145,6 @@ public class IntegrationGraphControllerTests {
|
||||
@EnableIntegrationGraphController(path = "/testIntegration")
|
||||
public static class ContextConfiguration {
|
||||
|
||||
// TODO SF-4.3.RC1 compatibility. See https://jira.spring.io/browse/SPR-14140
|
||||
@Bean
|
||||
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
|
||||
return new PropertySourcesPlaceholderConfigurer();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -79,7 +80,9 @@ import org.springframework.web.client.RestTemplate;
|
||||
public class HttpRequestExecutingMessageHandlerTests {
|
||||
|
||||
public static ParameterizedTypeReference<List<String>> testParameterizedTypeReference() {
|
||||
return new ParameterizedTypeReference<List<String>>() { };
|
||||
return new ParameterizedTypeReference<List<String>>() {
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -637,8 +640,8 @@ public class HttpRequestExecutingMessageHandlerTests {
|
||||
@Test
|
||||
public void contentTypeIsNotSetForGetRequest() throws Exception {
|
||||
// GET
|
||||
HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler(
|
||||
"http://www.springsource.org/spring-integration");
|
||||
HttpRequestExecutingMessageHandler handler =
|
||||
new HttpRequestExecutingMessageHandler("http://www.springsource.org/spring-integration");
|
||||
MockRestTemplate template = new MockRestTemplate();
|
||||
new DirectFieldAccessor(handler).setPropertyValue("restTemplate", template);
|
||||
handler.setHttpMethod(HttpMethod.GET);
|
||||
@@ -646,59 +649,54 @@ public class HttpRequestExecutingMessageHandlerTests {
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
Message<?> message = MessageBuilder.withPayload(mock(Source.class)).build();
|
||||
Exception exception = null;
|
||||
try {
|
||||
handler.handleMessage(message);
|
||||
fail("An Exception expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
exception = e;
|
||||
assertEquals("intentional", e.getCause().getMessage());
|
||||
assertNull(template.lastRequestEntity.get().getHeaders().getContentType());
|
||||
}
|
||||
assertEquals("intentional", exception.getCause().getMessage());
|
||||
HttpEntity<?> request = template.lastRequestEntity.get();
|
||||
assertNull(request.getHeaders().getContentType());
|
||||
|
||||
/*
|
||||
* TODO: reconsider the inclusion of content-type for various HttpMethods (only
|
||||
* ignoring for GET as of 2.0.5) uncomment code below accordingly (see INT-1951)
|
||||
*/
|
||||
//HEAD
|
||||
handler.setHttpMethod(HttpMethod.HEAD);
|
||||
|
||||
/*
|
||||
* //HEAD handler = new HttpRequestExecutingMessageHandler(
|
||||
* "http://www.springsource.org/spring-integration"); template = new
|
||||
* MockRestTemplate(); new
|
||||
* DirectFieldAccessor(handler).setPropertyValue("restTemplate", template);
|
||||
* handler.setHttpMethod(HttpMethod.HEAD);
|
||||
*
|
||||
* message = MessageBuilder.withPayload(mock(Source.class)).build(); exception =
|
||||
* null; try { handler.handleMessage(message); } catch (Exception e) { exception =
|
||||
* e; } assertEquals("intentional", exception.getCause().getMessage()); request =
|
||||
* template.lastRequestEntity.get();
|
||||
* assertNull(request.getHeaders().getContentType());
|
||||
*
|
||||
* //DELETE handler = new HttpRequestExecutingMessageHandler(
|
||||
* "http://www.springsource.org/spring-integration"); template = new
|
||||
* MockRestTemplate(); new
|
||||
* DirectFieldAccessor(handler).setPropertyValue("restTemplate", template);
|
||||
* handler.setHttpMethod(HttpMethod.DELETE);
|
||||
*
|
||||
* message = MessageBuilder.withPayload(mock(Source.class)).build(); exception =
|
||||
* null; try { handler.handleMessage(message); } catch (Exception e) { exception =
|
||||
* e; } assertEquals("intentional", exception.getCause().getMessage()); request =
|
||||
* template.lastRequestEntity.get();
|
||||
* assertNull(request.getHeaders().getContentType());
|
||||
*
|
||||
* //TRACE handler = new HttpRequestExecutingMessageHandler(
|
||||
* "http://www.springsource.org/spring-integration"); template = new
|
||||
* MockRestTemplate(); new
|
||||
* DirectFieldAccessor(handler).setPropertyValue("restTemplate", template);
|
||||
* handler.setHttpMethod(HttpMethod.TRACE);
|
||||
*
|
||||
* message = MessageBuilder.withPayload(mock(Source.class)).build(); exception =
|
||||
* null; try { handler.handleMessage(message); } catch (Exception e) { exception =
|
||||
* e; } assertEquals("intentional", exception.getCause().getMessage()); request =
|
||||
* template.lastRequestEntity.get();
|
||||
* assertNull(request.getHeaders().getContentType());
|
||||
*/
|
||||
message = MessageBuilder.withPayload(mock(Source.class)).build();
|
||||
try {
|
||||
handler.handleMessage(message);
|
||||
fail("An Exception expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertEquals("intentional", e.getCause().getMessage());
|
||||
assertEquals(MediaType.TEXT_XML, template.lastRequestEntity.get().getHeaders().getContentType());
|
||||
}
|
||||
|
||||
|
||||
//DELETE
|
||||
handler.setHttpMethod(HttpMethod.DELETE);
|
||||
|
||||
message = MessageBuilder.withPayload(mock(Source.class)).build();
|
||||
try {
|
||||
handler.handleMessage(message);
|
||||
fail("An Exception expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertEquals("intentional", e.getCause().getMessage());
|
||||
assertEquals(MediaType.TEXT_XML, template.lastRequestEntity.get().getHeaders().getContentType());
|
||||
}
|
||||
|
||||
//TRACE
|
||||
handler.setHttpMethod(HttpMethod.TRACE);
|
||||
|
||||
message = MessageBuilder.withPayload(mock(Source.class)).build();
|
||||
try {
|
||||
handler.handleMessage(message);
|
||||
fail("An Exception expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertEquals("intentional", e.getCause().getMessage());
|
||||
assertEquals(MediaType.TEXT_XML, template.lastRequestEntity.get().getHeaders().getContentType());
|
||||
}
|
||||
}
|
||||
|
||||
@Test // INT-2275
|
||||
|
||||
Reference in New Issue
Block a user