INT-3156: Resolve deprecations according to SPR 4
JIRA: https://jira.springsource.org/browse/INT-3156 * Resolve `@SuppressWarnings("deprecation")` for HTTP, JDBC modules * Remove `ParameterizedTypeReference` * Add `@SuppressWarnings("deprecation")` to `HttpRequestHandlingEndpointSupport` for `MappingJacksonHttpMessageConverter`
This commit is contained in:
@@ -30,6 +30,7 @@ import org.hamcrest.Factory;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.integration.message.MessageMatcher;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.json.JacksonJsonObjectMapperProvider;
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.json;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Copy of {@link org.springframework.core.ParameterizedTypeReference} from Spring Framework 3.2
|
||||
* @author Artem Bilan
|
||||
* @since 3.0
|
||||
*/
|
||||
//TODO Remove it after upgrade to Spring Framework 3.2 in favor to use org.springframework.core.ParameterizedTypeReference
|
||||
public abstract class ParameterizedTypeReference<T> {
|
||||
|
||||
private final Type type;
|
||||
|
||||
protected ParameterizedTypeReference() {
|
||||
Class<?> parameterizedTypeReferenceSubClass = findParameterizedTypeReferenceSubClass(getClass());
|
||||
|
||||
Type type = parameterizedTypeReferenceSubClass.getGenericSuperclass();
|
||||
Assert.isInstanceOf(ParameterizedType.class, type);
|
||||
|
||||
ParameterizedType parameterizedType = (ParameterizedType) type;
|
||||
Assert.isTrue(parameterizedType.getActualTypeArguments().length == 1);
|
||||
|
||||
this.type = parameterizedType.getActualTypeArguments()[0];
|
||||
}
|
||||
|
||||
private static Class<?> findParameterizedTypeReferenceSubClass(Class<?> child) {
|
||||
|
||||
Class<?> parent = child.getSuperclass();
|
||||
|
||||
if (Object.class.equals(parent)) {
|
||||
throw new IllegalStateException("Expected ParameterizedTypeReference superclass");
|
||||
}
|
||||
else if (ParameterizedTypeReference.class.equals(parent)) {
|
||||
return child;
|
||||
}
|
||||
else {
|
||||
return findParameterizedTypeReferenceSubClass(parent);
|
||||
}
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o instanceof ParameterizedTypeReference) {
|
||||
ParameterizedTypeReference<?> other = (ParameterizedTypeReference<?>) o;
|
||||
return this.type.equals(other.type);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.type.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ParameterizedTypeReference<" + this.type + ">";
|
||||
}
|
||||
}
|
||||
@@ -115,7 +115,7 @@ public class GroovyCommandMessageProcessor extends AbstractScriptExecutingMessag
|
||||
if (this.beanFactory != null) {
|
||||
factory.setBeanFactory(this.beanFactory);
|
||||
}
|
||||
Object result = factory.getScriptedObject(scriptSource, null);
|
||||
Object result = factory.getScriptedObject(scriptSource);
|
||||
return (result instanceof GString) ? result.toString() : result;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.http.converter.HttpMessageNotWritableException;
|
||||
import org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter;
|
||||
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
|
||||
import org.springframework.integration.http.multipart.DefaultMultipartFileReader;
|
||||
import org.springframework.integration.http.multipart.MultipartFileReader;
|
||||
import org.springframework.integration.http.multipart.MultipartHttpInputMessage;
|
||||
@@ -38,18 +38,17 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* An {@link HttpMessageConverter} implementation that delegates to an instance of
|
||||
* {@link XmlAwareFormHttpMessageConverter} while adding the capability to <i>read</i>
|
||||
* {@link AllEncompassingFormHttpMessageConverter} while adding the capability to <i>read</i>
|
||||
* <code>multipart/form-data</code> content in an HTTP request.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MultipartAwareFormHttpMessageConverter implements HttpMessageConverter<MultiValueMap<String, ?>> {
|
||||
|
||||
private volatile MultipartFileReader<?> multipartFileReader = new DefaultMultipartFileReader();
|
||||
|
||||
private final XmlAwareFormHttpMessageConverter wrappedConverter = new XmlAwareFormHttpMessageConverter();
|
||||
private final AllEncompassingFormHttpMessageConverter wrappedConverter = new AllEncompassingFormHttpMessageConverter();
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,14 +44,10 @@ import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.http.converter.feed.AtomFeedHttpMessageConverter;
|
||||
import org.springframework.http.converter.feed.RssChannelHttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
|
||||
import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter;
|
||||
import org.springframework.http.converter.xml.SourceHttpMessageConverter;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.http.server.ServletServerHttpResponse;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.integration.context.OrderlyShutdownCapable;
|
||||
import org.springframework.integration.expression.ExpressionUtils;
|
||||
import org.springframework.integration.gateway.MessagingGatewaySupport;
|
||||
@@ -61,6 +57,9 @@ import org.springframework.integration.http.support.DefaultHttpHeaderMapper;
|
||||
import org.springframework.integration.mapping.HeaderMapper;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.json.JacksonJsonUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -145,6 +144,7 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
|
||||
this(true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public HttpRequestHandlingEndpointSupport(boolean expectReply) {
|
||||
this.expectReply = expectReply;
|
||||
this.defaultMessageConverters.add(new MultipartAwareFormHttpMessageConverter());
|
||||
@@ -169,7 +169,7 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
|
||||
}
|
||||
}
|
||||
else if (JacksonJsonUtils.isJacksonPresent()) {
|
||||
this.defaultMessageConverters.add(new MappingJacksonHttpMessageConverter());
|
||||
this.defaultMessageConverters.add(new org.springframework.http.converter.json.MappingJacksonHttpMessageConverter());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("'MappingJacksonHttpMessageConverter' was added to the 'defaultMessageConverters'.");
|
||||
}
|
||||
|
||||
@@ -906,8 +906,7 @@ public class DefaultHttpHeaderMapper implements HeaderMapper<HttpHeaders>, BeanF
|
||||
return source.getIfNoneMatch();
|
||||
}
|
||||
else if (IF_MODIFIED_SINCE.equalsIgnoreCase(name)) {
|
||||
@SuppressWarnings("deprecation")
|
||||
long modifiedSince = source.getIfNotModifiedSince();
|
||||
long modifiedSince = source.getIfModifiedSince();
|
||||
return (modifiedSince > -1) ? modifiedSince : null;
|
||||
}
|
||||
else if (IF_UNMODIFIED_SINCE.equalsIgnoreCase(name)) {
|
||||
|
||||
@@ -110,14 +110,13 @@ public class HttpProxyScenarioTests {
|
||||
RestTemplate template = Mockito.spy(new RestTemplate());
|
||||
|
||||
Mockito.doAnswer(new Answer<ResponseEntity<?>>() {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public ResponseEntity<?> answer(InvocationOnMock invocation) throws Throwable {
|
||||
URI uri = (URI) invocation.getArguments()[0];
|
||||
assertEquals(new URI("http://testServer/test?foo=bar&FOO=BAR"), uri);
|
||||
HttpEntity<?> httpEntity = (HttpEntity<?>) invocation.getArguments()[2];
|
||||
HttpHeaders httpHeaders = httpEntity.getHeaders();
|
||||
assertEquals(ifModifiedSince, httpHeaders.getIfNotModifiedSince());
|
||||
assertEquals(ifModifiedSince, httpHeaders.getIfModifiedSince());
|
||||
assertEquals(ifUnmodifiedSinceValue, httpHeaders.getFirst("If-Unmodified-Since"));
|
||||
assertEquals("Keep-Alive", httpHeaders.getFirst("Connection"));
|
||||
|
||||
|
||||
@@ -386,7 +386,6 @@ public class DefaultHttpHeaderMapperFromMessageOutboundTests {
|
||||
|
||||
// If-Modified-Since tests
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void validateIfModifiedSinceAsNumber() throws ParseException{
|
||||
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.outboundMapper();
|
||||
@@ -397,10 +396,9 @@ public class DefaultHttpHeaderMapperFromMessageOutboundTests {
|
||||
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
|
||||
|
||||
assertEquals(simpleDateFormat.parse("Thu, 01 Jan 1970 03:25:45 GMT").getTime(), headers.getIfNotModifiedSince());
|
||||
assertEquals(simpleDateFormat.parse("Thu, 01 Jan 1970 03:25:45 GMT").getTime(), headers.getIfModifiedSince());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void validateIfModifiedSinceAsString() throws ParseException{
|
||||
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.outboundMapper();
|
||||
@@ -411,9 +409,8 @@ public class DefaultHttpHeaderMapperFromMessageOutboundTests {
|
||||
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
|
||||
|
||||
assertEquals(simpleDateFormat.parse("Thu, 01 Jan 1970 03:25:45 GMT").getTime(), headers.getIfNotModifiedSince());
|
||||
assertEquals(simpleDateFormat.parse("Thu, 01 Jan 1970 03:25:45 GMT").getTime(), headers.getIfModifiedSince());
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void validateIfModifiedSinceAsDate() throws ParseException{
|
||||
HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.outboundMapper();
|
||||
@@ -424,7 +421,7 @@ public class DefaultHttpHeaderMapperFromMessageOutboundTests {
|
||||
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
|
||||
|
||||
assertEquals(simpleDateFormat.parse("Thu, 01 Jan 1970 03:25:45 GMT").getTime(), headers.getIfNotModifiedSince());
|
||||
assertEquals(simpleDateFormat.parse("Thu, 01 Jan 1970 03:25:45 GMT").getTime(), headers.getIfModifiedSince());
|
||||
}
|
||||
|
||||
// If-None-Match
|
||||
@@ -676,7 +673,6 @@ public class DefaultHttpHeaderMapperFromMessageOutboundTests {
|
||||
assertEquals(0, messageHeaders.size());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testInt2995IfModifiedSince() throws Exception{
|
||||
Date ifModifiedSince = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", Locale.US);
|
||||
@@ -689,7 +685,7 @@ public class DefaultHttpHeaderMapperFromMessageOutboundTests {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(ifModifiedSince);
|
||||
c.set(Calendar.MILLISECOND, 0);
|
||||
assertEquals(c.getTimeInMillis(), headers.getIfNotModifiedSince());
|
||||
assertEquals(c.getTimeInMillis(), headers.getIfModifiedSince());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -309,11 +309,10 @@ public class JdbcMessageStore extends AbstractMessageGroupStore implements Messa
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@ManagedAttribute
|
||||
public long getMessageCount() {
|
||||
return jdbcTemplate.queryForInt(getQuery(Query.GET_MESSAGE_COUNT), region);
|
||||
return jdbcTemplate.queryForObject(getQuery(Query.GET_MESSAGE_COUNT), Integer.class, region);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -367,8 +366,7 @@ public class JdbcMessageStore extends AbstractMessageGroupStore implements Messa
|
||||
public MessageGroup addMessageToGroup(Object groupId, Message<?> message) {
|
||||
final String groupKey = getKey(groupId);
|
||||
final String messageId = getKey(message.getHeaders().getId());
|
||||
@SuppressWarnings("deprecation")
|
||||
boolean groupNotExist = jdbcTemplate.queryForInt(this.getQuery(Query.GROUP_EXISTS), groupKey, region) < 1;
|
||||
boolean groupNotExist = jdbcTemplate.queryForObject(this.getQuery(Query.GROUP_EXISTS), Integer.class, groupKey, region) < 1;
|
||||
|
||||
final Timestamp updatedDate = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
@@ -405,26 +403,23 @@ public class JdbcMessageStore extends AbstractMessageGroupStore implements Messa
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@ManagedAttribute
|
||||
public int getMessageGroupCount() {
|
||||
return jdbcTemplate.queryForInt(getQuery(Query.COUNT_ALL_GROUPS), region);
|
||||
return jdbcTemplate.queryForObject(getQuery(Query.COUNT_ALL_GROUPS), Integer.class, region);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@ManagedAttribute
|
||||
public int getMessageCountForAllMessageGroups() {
|
||||
return jdbcTemplate.queryForInt(getQuery(Query.COUNT_ALL_MESSAGES_IN_GROUPS), region);
|
||||
return jdbcTemplate.queryForObject(getQuery(Query.COUNT_ALL_MESSAGES_IN_GROUPS), Integer.class, region);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@ManagedAttribute
|
||||
public int messageGroupSize(Object groupId) {
|
||||
String key = getKey(groupId);
|
||||
return jdbcTemplate.queryForInt(getQuery(Query.COUNT_ALL_MESSAGES_IN_GROUP), key, region);
|
||||
return jdbcTemplate.queryForObject(getQuery(Query.COUNT_ALL_MESSAGES_IN_GROUP), Integer.class, key, region);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -577,11 +577,11 @@ public class JdbcChannelMessageStore extends AbstractMessageGroupStore implement
|
||||
* and the specified region ({@link #setRegion(String)}).
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
@ManagedAttribute
|
||||
public int messageGroupSize(Object groupId) {
|
||||
final String key = getKey(groupId);
|
||||
return jdbcTemplate.queryForInt(getQuery(channelMessageStoreQueryProvider.getCountAllMessagesInGroupQuery()), key, this.region);
|
||||
return jdbcTemplate.queryForObject(getQuery(channelMessageStoreQueryProvider.getCountAllMessagesInGroupQuery()),
|
||||
Integer.class, key, this.region);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -166,16 +166,14 @@ public class JdbcPollingChannelAdapterIntegrationTests {
|
||||
assertEquals("Wrong id", 1, item.getId());
|
||||
assertEquals("Wrong status", 2, item.getStatus());
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
int countOfStatusTwo = this.jdbcTemplate
|
||||
.queryForInt("select count(*) from item where status = 2");
|
||||
.queryForObject("select count(*) from item where status = 2", Integer.class);
|
||||
assertEquals(
|
||||
"Status not updated incorect number of rows with status 2", 0,
|
||||
countOfStatusTwo);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
int countOfStatusTen = this.jdbcTemplate
|
||||
.queryForInt("select count(*) from item where status = 10");
|
||||
.queryForObject("select count(*) from item where status = 10", Integer.class);
|
||||
assertEquals(
|
||||
"Status not updated incorect number of rows with status 10", 2,
|
||||
countOfStatusTen);
|
||||
@@ -204,16 +202,14 @@ public class JdbcPollingChannelAdapterIntegrationTests {
|
||||
assertEquals("Wrong id", 1, item.getId());
|
||||
assertEquals("Wrong status", 2, item.getStatus());
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
int countOfStatusTwo = this.jdbcTemplate
|
||||
.queryForInt("select count(*) from item where status = 2");
|
||||
.queryForObject("select count(*) from item where status = 2", Integer.class);
|
||||
assertEquals(
|
||||
"Status not updated incorect number of rows with status 2", 0,
|
||||
countOfStatusTwo);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
int countOfStatusTen = this.jdbcTemplate
|
||||
.queryForInt("select count(*) from item where status = 10");
|
||||
.queryForObject("select count(*) from item where status = 10", Integer.class);
|
||||
assertEquals(
|
||||
"Status not updated incorect number of rows with status 10", 2,
|
||||
countOfStatusTen);
|
||||
@@ -245,16 +241,14 @@ public class JdbcPollingChannelAdapterIntegrationTests {
|
||||
assertEquals("Wrong id", 2, item.getId());
|
||||
assertEquals("Wrong status", 2, item.getStatus());
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
int countOfStatusTwo = this.jdbcTemplate
|
||||
.queryForInt("select count(*) from item where status = 2");
|
||||
.queryForObject("select count(*) from item where status = 2", Integer.class);
|
||||
assertEquals(
|
||||
"Status not updated incorect number of rows with status 2", 2,
|
||||
countOfStatusTwo);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
int countOfStatusTen = this.jdbcTemplate
|
||||
.queryForInt("select count(*) from copy where status = 10");
|
||||
.queryForObject("select count(*) from copy where status = 10", Integer.class);
|
||||
assertEquals(
|
||||
"Status not updated incorect number of rows with status 10", 2,
|
||||
countOfStatusTen);
|
||||
@@ -285,16 +279,14 @@ public class JdbcPollingChannelAdapterIntegrationTests {
|
||||
assertEquals("Wrong id", 2, item.getId());
|
||||
assertEquals("Wrong status", 2, item.getStatus());
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
int countOfStatusTwo = this.jdbcTemplate
|
||||
.queryForInt("select count(*) from item where status = 2");
|
||||
.queryForObject("select count(*) from item where status = 2", Integer.class);
|
||||
assertEquals(
|
||||
"Status not updated incorect number of rows with status 2", 0,
|
||||
countOfStatusTwo);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
int countOfStatusTen = this.jdbcTemplate
|
||||
.queryForInt("select count(*) from item where status = 10");
|
||||
.queryForObject("select count(*) from item where status = 10", Integer.class);
|
||||
assertEquals(
|
||||
"Status not updated incorect number of rows with status 10", 2,
|
||||
countOfStatusTen);
|
||||
|
||||
Reference in New Issue
Block a user