diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java index 38e2c01bb8..55d68e250f 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java @@ -253,7 +253,7 @@ public class AmqpInboundGateway extends MessagingGatewaySupport { @SuppressWarnings("unchecked") @Override - public void onMessage(final Message message, final Channel channel) throws Exception { + public void onMessage(final Message message, final Channel channel) { if (AmqpInboundGateway.this.retryTemplate == null) { try { org.springframework.messaging.Message converted = convert(message, channel); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/json/JsonPathUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/json/JsonPathUtils.java index 01b6c6eaab..765420cf35 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/json/JsonPathUtils.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/json/JsonPathUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 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. @@ -18,6 +18,7 @@ package org.springframework.integration.json; import java.io.ByteArrayInputStream; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -36,7 +37,7 @@ import com.jayway.jsonpath.Predicate; */ public final class JsonPathUtils { - public static T evaluate(Object json, String jsonPath, Predicate... predicates) throws Exception { + public static T evaluate(Object json, String jsonPath, Predicate... predicates) throws IOException { if (json instanceof String) { return JsonPath.read((String) json, jsonPath, predicates); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/mapping/InboundMessageMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/mapping/InboundMessageMapper.java index 58875b78b3..92ee38e233 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/mapping/InboundMessageMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/mapping/InboundMessageMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -35,10 +35,9 @@ public interface InboundMessageMapper { * Convert a provided object to the {@link Message}. * @param object the object for message payload or some other conversion logic * @return the message as a result of mapping - * @throws Exception the exception thrown by the underlying mapper implementation */ @Nullable - default Message toMessage(T object) throws Exception { // NOSONAR - TODO remove Exception in 5.2 + default Message toMessage(T object) { return toMessage(object, null); } @@ -48,10 +47,9 @@ public interface InboundMessageMapper { * @param object the object for message payload or some other conversion logic * @param headers additional headers for building message. Can be null * @return the message as a result of mapping - * @throws Exception the exception thrown by the underlying mapper implementation * @since 5.0 */ @Nullable - Message toMessage(T object, @Nullable Map headers) throws Exception; // NOSONAR + Message toMessage(T object, @Nullable Map headers); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/mapping/OutboundMessageMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/mapping/OutboundMessageMapper.java index d03be4a3aa..762c31b7d1 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/mapping/OutboundMessageMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/mapping/OutboundMessageMapper.java @@ -29,6 +29,6 @@ import org.springframework.messaging.Message; public interface OutboundMessageMapper { @Nullable - T fromMessage(Message message) throws Exception; // NOSONAR + T fromMessage(Message message); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/metadata/PropertiesPersistingMetadataStore.java b/spring-integration-core/src/main/java/org/springframework/integration/metadata/PropertiesPersistingMetadataStore.java index e22d8ad1d2..ccedd45d7b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/metadata/PropertiesPersistingMetadataStore.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/metadata/PropertiesPersistingMetadataStore.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -91,7 +91,7 @@ public class PropertiesPersistingMetadataStore implements ConcurrentMetadataStor } @Override - public void afterPropertiesSet() throws Exception { + public void afterPropertiesSet() { File baseDir = new File(this.baseDirectory); baseDir.mkdirs(); this.file = new File(baseDir, this.fileName); @@ -195,7 +195,7 @@ public class PropertiesPersistingMetadataStore implements ConcurrentMetadataStor } @Override - public void close() throws IOException { + public void close() { flush(); } @@ -205,7 +205,7 @@ public class PropertiesPersistingMetadataStore implements ConcurrentMetadataStor } @Override - public void destroy() throws Exception { + public void destroy() { flush(); } @@ -254,7 +254,7 @@ public class PropertiesPersistingMetadataStore implements ConcurrentMetadataStor inputStream.close(); } } - catch (Exception e2) { + catch (@SuppressWarnings("unused") Exception e2) { // non fatal this.logger.warn("Failed to close InputStream for: " + this.file.getAbsolutePath()); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/routingslip/ExpressionEvaluatingRoutingSlipRouteStrategy.java b/spring-integration-core/src/main/java/org/springframework/integration/routingslip/ExpressionEvaluatingRoutingSlipRouteStrategy.java index dec8a8a6bd..51fb599bba 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/routingslip/ExpressionEvaluatingRoutingSlipRouteStrategy.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/routingslip/ExpressionEvaluatingRoutingSlipRouteStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2019 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. @@ -90,7 +90,7 @@ public class ExpressionEvaluatingRoutingSlipRouteStrategy } @Override - public void afterPropertiesSet() throws Exception { + public void afterPropertiesSet() { if (this.evaluationContext == null) { this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.beanFactory); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupStoreReaper.java b/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupStoreReaper.java index 31c2712eda..7b4fb072ac 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupStoreReaper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupStoreReaper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -90,12 +90,12 @@ public class MessageGroupStoreReaper implements Runnable, DisposableBean, Initia } @Override - public void afterPropertiesSet() throws Exception { + public void afterPropertiesSet() { Assert.state(this.messageGroupStore != null, "A MessageGroupStore must be provided"); } @Override - public void destroy() throws Exception { + public void destroy() { if (this.expireOnDestroy) { if (this.isRunning()) { logger.info("Expiring all messages from message group store: " + this.messageGroupStore); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/converter/SimpleMessageConverter.java b/spring-integration-core/src/main/java/org/springframework/integration/support/converter/SimpleMessageConverter.java index 0bd8c5bef0..3d7a18ea58 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/converter/SimpleMessageConverter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/converter/SimpleMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -134,7 +134,7 @@ public class SimpleMessageConverter implements MessageConverter, BeanFactoryAwar } @Override - public Message toMessage(Object object, @Nullable Map headers) throws Exception { + public Message toMessage(Object object, @Nullable Map headers) { if (object == null) { return null; } @@ -157,7 +157,7 @@ public class SimpleMessageConverter implements MessageConverter, BeanFactoryAwar } @Override - public Object fromMessage(Message message) throws Exception { + public Object fromMessage(Message message) { return (message != null) ? message.getPayload() : null; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJacksonJsonMessageParser.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJacksonJsonMessageParser.java index 224b549ab1..f17f2b470a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJacksonJsonMessageParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJacksonJsonMessageParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -69,15 +69,15 @@ abstract class AbstractJacksonJsonMessageParser

implements JsonInboundMessage } @Override - public Message doInParser(JsonInboundMessageMapper messageMapper, String jsonMessage, - @Nullable Map headers) throws Exception { + public Message doInParser(JsonInboundMessageMapper messageMapperToUse, String jsonMessage, + @Nullable Map headers) { if (this.messageMapper == null) { - this.messageMapper = messageMapper; + this.messageMapper = messageMapperToUse; } P parser = this.createJsonParser(jsonMessage); - if (messageMapper.isMapToPayload()) { + if (messageMapperToUse.isMapToPayload()) { Object payload = readPayload(parser, jsonMessage); return getMessageBuilderFactory() .withPayload(payload) @@ -89,7 +89,7 @@ abstract class AbstractJacksonJsonMessageParser

implements JsonInboundMessage } } - protected Object readPayload(P parser, String jsonMessage) throws Exception { + protected Object readPayload(P parser, String jsonMessage) { try { return this.objectMapper.fromJson(parser, this.messageMapper.getPayloadType()); } @@ -99,7 +99,7 @@ abstract class AbstractJacksonJsonMessageParser

implements JsonInboundMessage } } - protected Object readHeader(P parser, String headerName, String jsonMessage) throws Exception { + protected Object readHeader(P parser, String headerName, String jsonMessage) { Class headerType = this.messageMapper.getHeaderTypes().getOrDefault(headerName, Object.class); try { return this.objectMapper.fromJson(parser, (Type) headerType); @@ -111,8 +111,8 @@ abstract class AbstractJacksonJsonMessageParser

implements JsonInboundMessage } protected abstract Message parseWithHeaders(P parser, String jsonMessage, - @Nullable Map headers) throws Exception; + @Nullable Map headers); - protected abstract P createJsonParser(String jsonMessage) throws Exception; + protected abstract P createJsonParser(String jsonMessage); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJacksonJsonObjectMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJacksonJsonObjectMapper.java index 81c19a31d6..7f56c77515 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJacksonJsonObjectMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJacksonJsonObjectMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2013-2019 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. @@ -17,6 +17,7 @@ package org.springframework.integration.support.json; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.lang.reflect.Type; @@ -57,17 +58,17 @@ public abstract class AbstractJacksonJsonObjectMapper extends JsonObjec } @Override - public T fromJson(Object json, Class valueType) throws Exception { - return this.fromJson(json, this.constructType(valueType)); + public T fromJson(Object json, Class valueType) throws IOException { + return fromJson(json, this.constructType(valueType)); } @Override - public T fromJson(Object json, Map javaTypes) throws Exception { - J javaType = this.extractJavaType(javaTypes); + public T fromJson(Object json, Map javaTypes) throws IOException { + J javaType = extractJavaType(javaTypes); return this.fromJson(json, javaType); } - protected J createJavaType(Map javaTypes, String javaTypeKey) throws Exception { + protected J createJavaType(Map javaTypes, String javaTypeKey) { Object classValue = javaTypes.get(javaTypeKey); if (classValue == null) { throw new IllegalArgumentException("Could not resolve '" + javaTypeKey + "' in 'javaTypes'."); @@ -78,16 +79,21 @@ public abstract class AbstractJacksonJsonObjectMapper extends JsonObjec aClass = (Class) classValue; } else { - aClass = ClassUtils.forName(classValue.toString(), this.classLoader); + try { + aClass = ClassUtils.forName(classValue.toString(), this.classLoader); + } + catch (ClassNotFoundException | LinkageError e) { + throw new IllegalStateException(e); + } } return this.constructType(aClass); } } - protected abstract T fromJson(Object json, J type) throws Exception; + protected abstract T fromJson(Object json, J type) throws IOException; - protected abstract J extractJavaType(Map javaTypes) throws Exception; + protected abstract J extractJavaType(Map javaTypes); protected abstract J constructType(Type type); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJsonInboundMessageMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJsonInboundMessageMapper.java index 8345646afd..b5ca59477f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJsonInboundMessageMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJsonInboundMessageMapper.java @@ -66,8 +66,8 @@ public abstract class AbstractJsonInboundMessageMapper

implements InboundMess this.mapToPayload = mapToPayload; } - protected abstract Object readPayload(P parser, String jsonMessage) throws Exception; + protected abstract Object readPayload(P parser, String jsonMessage); - protected abstract Map readHeaders(P parser, String jsonMessage) throws Exception; + protected abstract Map readHeaders(P parser, String jsonMessage); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/BoonJsonObjectMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/BoonJsonObjectMapper.java index 9cf0afa99f..82862ad7a7 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/BoonJsonObjectMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/BoonJsonObjectMapper.java @@ -18,6 +18,7 @@ package org.springframework.integration.support.json; import java.io.File; import java.io.FileReader; +import java.io.IOException; import java.io.InputStream; import java.io.PipedReader; import java.io.PipedWriter; @@ -80,7 +81,7 @@ public class BoonJsonObjectMapper extends JsonObjectMapperAdapter toJsonNode(final Object value) throws Exception { + public Map toJsonNode(final Object value) throws IOException { PipedReader in = new PipedReader(); final PipedWriter out = new PipedWriter(in); Executors.newSingleThreadExecutor().execute(() -> toJson(value, out)); @@ -99,7 +100,7 @@ public class BoonJsonObjectMapper extends JsonObjectMapperAdapter T fromJson(Object json, Class type) throws Exception { + public T fromJson(Object json, Class type) { if (json instanceof String) { return this.objectMapper.readValue((String) json, type); } @@ -126,14 +127,14 @@ public class BoonJsonObjectMapper extends JsonObjectMapperAdapter T fromJson(Object json, Map javaTypes) throws Exception { + public T fromJson(Object json, Map javaTypes) throws IOException { JsonParserAndMapper parser = this.objectMapper.parser(); - Class classType = this.createJavaType(javaTypes, JsonHeaders.TYPE_ID); + Class classType = createJavaType(javaTypes, JsonHeaders.TYPE_ID); - Class contentClassType = this.createJavaType(javaTypes, JsonHeaders.CONTENT_TYPE_ID); + Class contentClassType = createJavaType(javaTypes, JsonHeaders.CONTENT_TYPE_ID); - Class keyClassType = this.createJavaType(javaTypes, JsonHeaders.KEY_TYPE_ID); + Class keyClassType = createJavaType(javaTypes, JsonHeaders.KEY_TYPE_ID); if (keyClassType != null) { logger.warn("Boon doesn't support the Map 'key' conversion. Will be returned raw Map"); @@ -190,13 +191,18 @@ public class BoonJsonObjectMapper extends JsonObjectMapperAdapter createJavaType(Map javaTypes, String javaTypeKey) throws Exception { + protected Class createJavaType(Map javaTypes, String javaTypeKey) { Object classValue = javaTypes.get(javaTypeKey); if (classValue instanceof Class) { return (Class) classValue; } else if (classValue != null) { - return ClassUtils.forName(classValue.toString(), this.classLoader); + try { + return ClassUtils.forName(classValue.toString(), this.classLoader); + } + catch (ClassNotFoundException | LinkageError e) { + throw new IllegalStateException(e); + } } else { return null; @@ -204,7 +210,7 @@ public class BoonJsonObjectMapper extends JsonObjectMapperAdapter T fromJson(Object parser, Type valueType) throws Exception { + public T fromJson(Object parser, Type valueType) { throw new UnsupportedOperationException("Boon doesn't support JSON reader parser abstraction"); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/EmbeddedJsonHeadersMessageMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/EmbeddedJsonHeadersMessageMapper.java index e956be9f0e..4199c74a59 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/EmbeddedJsonHeadersMessageMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/EmbeddedJsonHeadersMessageMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2018 the original author or authors. + * Copyright 2017-2019 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. @@ -17,6 +17,7 @@ package org.springframework.integration.support.json; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Collection; @@ -36,6 +37,7 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.support.GenericMessage; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; /** @@ -154,9 +156,8 @@ public class EmbeddedJsonHeadersMessageMapper implements BytesMessageMapper { return Arrays.asList(this.headerPatterns); } - @SuppressWarnings("unchecked") @Override - public byte[] fromMessage(Message message) throws Exception { + public byte[] fromMessage(Message message) { Map headersToEncode = this.allHeaders ? message.getHeaders() @@ -179,7 +180,12 @@ public class EmbeddedJsonHeadersMessageMapper implements BytesMessageMapper { messageToEncode = new MutableMessage<>(message.getPayload(), headersToEncode); } - return this.objectMapper.writeValueAsBytes(messageToEncode); + try { + return this.objectMapper.writeValueAsBytes(messageToEncode); + } + catch (JsonProcessingException e) { + throw new UncheckedIOException(e); + } } } @@ -197,14 +203,19 @@ public class EmbeddedJsonHeadersMessageMapper implements BytesMessageMapper { : PatternMatchUtils.smartMatchIgnoreCase(header, this.headerPatterns)); } - private byte[] fromBytesPayload(byte[] payload, Map headersToEncode) throws Exception { - byte[] headers = this.objectMapper.writeValueAsBytes(headersToEncode); - ByteBuffer buffer = ByteBuffer.wrap(new byte[8 + headers.length + payload.length]); - buffer.putInt(headers.length); - buffer.put(headers); - buffer.putInt(payload.length); - buffer.put(payload); - return buffer.array(); + private byte[] fromBytesPayload(byte[] payload, Map headersToEncode) { + try { + byte[] headers = this.objectMapper.writeValueAsBytes(headersToEncode); + ByteBuffer buffer = ByteBuffer.wrap(new byte[8 + headers.length + payload.length]); + buffer.putInt(headers.length); + buffer.put(headers); + buffer.putInt(payload.length); + buffer.put(payload); + return buffer.array(); + } + catch (JsonProcessingException e) { + throw new UncheckedIOException(e); + } } @Override @@ -213,7 +224,7 @@ public class EmbeddedJsonHeadersMessageMapper implements BytesMessageMapper { try { message = decodeNativeFormat(bytes, headers); } - catch (Exception e) { + catch (@SuppressWarnings("unused") Exception e) { // empty } if (message == null) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonMessageParser.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonMessageParser.java index 1fb6361ff4..bffc81c193 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonMessageParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonMessageParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -17,6 +17,8 @@ package org.springframework.integration.support.json; +import java.io.IOException; +import java.io.UncheckedIOException; import java.util.LinkedHashMap; import java.util.Map; @@ -49,42 +51,52 @@ public class Jackson2JsonMessageParser extends AbstractJacksonJsonMessageParser< } @Override - protected JsonParser createJsonParser(String jsonMessage) throws Exception { - return new JsonFactory().createParser(jsonMessage); + protected JsonParser createJsonParser(String jsonMessage) { + try { + return new JsonFactory().createParser(jsonMessage); + } + catch (IOException e) { + throw new UncheckedIOException(e); + } } @Override protected Message parseWithHeaders(JsonParser parser, String jsonMessage, - @Nullable Map headersToAdd) throws Exception { + @Nullable Map headersToAdd) { - String error = AbstractJsonInboundMessageMapper.MESSAGE_FORMAT_ERROR + jsonMessage; - Assert.isTrue(JsonToken.START_OBJECT == parser.nextToken(), error); - Map headers = null; - Object payload = null; - while (JsonToken.END_OBJECT != parser.nextToken()) { - Assert.isTrue(JsonToken.FIELD_NAME == parser.getCurrentToken(), error); - boolean isHeadersToken = "headers".equals(parser.getCurrentName()); - boolean isPayloadToken = "payload".equals(parser.getCurrentName()); - Assert.isTrue(isHeadersToken || isPayloadToken, error); - if (isHeadersToken) { - Assert.isTrue(parser.nextToken() == JsonToken.START_OBJECT, error); - headers = readHeaders(parser, jsonMessage); - } - else if (isPayloadToken) { - parser.nextToken(); - payload = this.readPayload(parser, jsonMessage); + try { + String error = AbstractJsonInboundMessageMapper.MESSAGE_FORMAT_ERROR + jsonMessage; + Assert.isTrue(JsonToken.START_OBJECT == parser.nextToken(), error); + Map headers = null; + Object payload = null; + while (JsonToken.END_OBJECT != parser.nextToken()) { + Assert.isTrue(JsonToken.FIELD_NAME == parser.getCurrentToken(), error); + boolean isHeadersToken = "headers".equals(parser.getCurrentName()); + boolean isPayloadToken = "payload".equals(parser.getCurrentName()); + Assert.isTrue(isHeadersToken || isPayloadToken, error); + if (isHeadersToken) { + Assert.isTrue(parser.nextToken() == JsonToken.START_OBJECT, error); + headers = readHeaders(parser, jsonMessage); + } + else if (isPayloadToken) { + parser.nextToken(); + payload = this.readPayload(parser, jsonMessage); + } } + Assert.notNull(headers, error); + + return getMessageBuilderFactory() + .withPayload(payload) + .copyHeaders(headers) + .copyHeadersIfAbsent(headersToAdd) + .build(); + } + catch (IOException e) { + throw new UncheckedIOException(e); } - Assert.notNull(headers, error); - - return getMessageBuilderFactory() - .withPayload(payload) - .copyHeaders(headers) - .copyHeadersIfAbsent(headersToAdd) - .build(); } - private Map readHeaders(JsonParser parser, String jsonMessage) throws Exception { + private Map readHeaders(JsonParser parser, String jsonMessage) throws IOException { Map headers = new LinkedHashMap<>(); while (JsonToken.END_OBJECT != parser.nextToken()) { String headerName = parser.getCurrentName(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonObjectMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonObjectMapper.java index 6dfa23182f..680787237b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonObjectMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonObjectMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2019 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. @@ -17,6 +17,7 @@ package org.springframework.integration.support.json; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.io.Writer; @@ -32,6 +33,7 @@ import org.springframework.util.ClassUtils; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; @@ -82,17 +84,17 @@ public class Jackson2JsonObjectMapper extends AbstractJacksonJsonObjectMapper T fromJson(Object json, JavaType type) throws Exception { + protected T fromJson(Object json, JavaType type) throws IOException { if (json instanceof String) { return this.objectMapper.readValue((String) json, type); } @@ -150,13 +152,13 @@ public class Jackson2JsonObjectMapper extends AbstractJacksonJsonObjectMapper T fromJson(JsonParser parser, Type valueType) throws Exception { + public T fromJson(JsonParser parser, Type valueType) throws IOException { return this.objectMapper.readValue(parser, constructType(valueType)); } @Override @SuppressWarnings({ "unchecked" }) - protected JavaType extractJavaType(Map javaTypes) throws Exception { + protected JavaType extractJavaType(Map javaTypes) { JavaType classType = this.createJavaType(javaTypes, JsonHeaders.TYPE_ID); if (!classType.isContainerType() || classType.isArrayType()) { return classType; @@ -169,7 +171,7 @@ public class Jackson2JsonObjectMapper extends AbstractJacksonJsonObjectMapper>) classType.getRawClass(), keyClassType, contentClassType); } @@ -186,7 +188,7 @@ public class Jackson2JsonObjectMapper extends AbstractJacksonJsonObjectMapper toMessage(String jsonMessage, @Nullable Map headers) throws Exception { + public Message toMessage(String jsonMessage, @Nullable Map headers) { return this.messageParser.doInParser(this, jsonMessage, headers); } @Override - protected Map readHeaders(JsonMessageParser parser, String jsonMessage) throws Exception { + protected Map readHeaders(JsonMessageParser parser, String jsonMessage) { //No-op return null; } @Override - protected Object readPayload(JsonMessageParser parser, String jsonMessage) throws Exception { + protected Object readPayload(JsonMessageParser parser, String jsonMessage) { //No-op return null; } - public interface JsonMessageParser

{ + public interface JsonMessageParser

{ // NOSONAR unused P Message doInParser(JsonInboundMessageMapper messageMapper, String jsonMessage, - @Nullable Map headers) throws Exception; + @Nullable Map headers); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/JsonObjectMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/JsonObjectMapper.java index b8183f2342..9824d4da68 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/JsonObjectMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/JsonObjectMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2019 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. @@ -16,6 +16,7 @@ package org.springframework.integration.support.json; +import java.io.IOException; import java.io.Writer; import java.lang.reflect.Type; import java.util.Map; @@ -32,17 +33,17 @@ import java.util.Map; */ public interface JsonObjectMapper { - String toJson(Object value) throws Exception; + String toJson(Object value) throws IOException; - void toJson(Object value, Writer writer) throws Exception; + void toJson(Object value, Writer writer) throws IOException; - N toJsonNode(Object value) throws Exception; + N toJsonNode(Object value) throws IOException; - T fromJson(Object json, Class valueType) throws Exception; + T fromJson(Object json, Class valueType) throws IOException; - T fromJson(Object json, Map javaTypes) throws Exception; + T fromJson(Object json, Map javaTypes) throws IOException; - T fromJson(P parser, Type valueType) throws Exception; + T fromJson(P parser, Type valueType) throws IOException; void populateJavaTypes(Map map, Object object); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/JsonObjectMapperAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/JsonObjectMapperAdapter.java index fe3f8e705b..53a00a31ae 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/JsonObjectMapperAdapter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/JsonObjectMapperAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2019 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. @@ -16,6 +16,7 @@ package org.springframework.integration.support.json; +import java.io.IOException; import java.io.Writer; import java.lang.reflect.Type; import java.util.Collection; @@ -34,31 +35,31 @@ import org.springframework.integration.mapping.support.JsonHeaders; public abstract class JsonObjectMapperAdapter implements JsonObjectMapper { @Override - public String toJson(Object value) throws Exception { + public String toJson(Object value) throws IOException { return null; } @Override - public void toJson(Object value, Writer writer) throws Exception { + public void toJson(Object value, Writer writer) throws IOException { } @Override - public N toJsonNode(Object value) throws Exception { + public N toJsonNode(Object value) throws IOException { return null; } @Override - public T fromJson(Object json, Class valueType) throws Exception { + public T fromJson(Object json, Class valueType) throws IOException { return null; } @Override - public T fromJson(P parser, Type valueType) throws Exception { + public T fromJson(P parser, Type valueType) throws IOException { return null; } @Override - public T fromJson(Object json, Map javaTypes) throws Exception { + public T fromJson(Object json, Map javaTypes) throws IOException { return null; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/JsonOutboundMessageMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/JsonOutboundMessageMapper.java index 676f47596a..bef6f287ab 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/JsonOutboundMessageMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/JsonOutboundMessageMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -16,6 +16,9 @@ package org.springframework.integration.support.json; +import java.io.IOException; +import java.io.UncheckedIOException; + import org.springframework.integration.mapping.OutboundMessageMapper; import org.springframework.messaging.Message; import org.springframework.util.Assert; @@ -53,8 +56,13 @@ public class JsonOutboundMessageMapper implements OutboundMessageMapper } @Override - public String fromMessage(Message message) throws Exception { - return this.jsonObjectMapper.toJson(this.shouldExtractPayload ? message.getPayload() : message); + public String fromMessage(Message message) { + try { + return this.jsonObjectMapper.toJson(this.shouldExtractPayload ? message.getPayload() : message); + } + catch (IOException e) { + throw new UncheckedIOException(e); + } } } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractServerConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractServerConnectionFactory.java index 64dd5f68a6..442e6179c3 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractServerConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractServerConnectionFactory.java @@ -89,7 +89,7 @@ public abstract class AbstractServerConnectionFactory extends AbstractConnection * method cannot discriminate. */ @Override - public TcpConnection getConnection() throws Exception { + public TcpConnection getConnection() { throw new UnsupportedOperationException("Getting a connection from a server factory is not supported"); } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/ConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/ConnectionFactory.java index b506dc168e..c62a3511d6 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/ConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/ConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2011 the original author or authors. + * Copyright 2001-2019 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. @@ -29,6 +29,6 @@ import org.springframework.context.Lifecycle; */ public interface ConnectionFactory extends Lifecycle { - TcpConnection getConnection() throws Exception; + TcpConnection getConnection() throws InterruptedException; } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/MessageConvertingTcpMessageMapper.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/MessageConvertingTcpMessageMapper.java index 4368a65d1f..691ed0eb09 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/MessageConvertingTcpMessageMapper.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/MessageConvertingTcpMessageMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -42,7 +42,7 @@ public class MessageConvertingTcpMessageMapper extends TcpMessageMapper { } @Override - public Message toMessage(TcpConnection connection, @Nullable Map headers) throws Exception { + public Message toMessage(TcpConnection connection, @Nullable Map headers) { Object data = connection.getPayload(); if (data != null) { @@ -70,7 +70,7 @@ public class MessageConvertingTcpMessageMapper extends TcpMessageMapper { } @Override - public Object fromMessage(Message message) throws Exception { + public Object fromMessage(Message message) { return this.messageConverter.fromMessage(message, Object.class); } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpMessageMapper.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpMessageMapper.java index 641ea18e98..46007ec81b 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpMessageMapper.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpMessageMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -171,7 +171,7 @@ public class TcpMessageMapper implements @SuppressWarnings("unchecked") @Override - public Message toMessage(TcpConnection connection, @Nullable Map headers) throws Exception { + public Message toMessage(TcpConnection connection, @Nullable Map headers) { Message message = null; Object payload = connection.getPayload(); if (payload != null) { @@ -244,7 +244,7 @@ public class TcpMessageMapper implements } @Override - public Object fromMessage(Message message) throws Exception { + public Object fromMessage(Message message) { if (this.bytesMessageMapper != null) { return this.bytesMessageMapper.fromMessage(message); } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java index def3484bba..754cc24c5a 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java @@ -339,10 +339,10 @@ public class TcpNioConnection extends TcpConnectionSupport { * Blocks until a complete message has been assembled. * Synchronized to avoid concurrency. * @return The Message or null if no data is available. - * @throws IOException + * @throws IOException an IO exception */ @Nullable - private synchronized Message convert() throws Exception { + private synchronized Message convert() throws IOException { if (logger.isTraceEnabled()) { logger.trace(getConnectionId() + " checking data avail (convert): " + this.channelInputStream.available() + " pending: " + (this.writingToPipe)); @@ -369,13 +369,13 @@ public class TcpNioConnection extends TcpConnectionSupport { } catch (Exception e) { closeConnection(true); - if (e instanceof SocketTimeoutException) { + if (e instanceof SocketTimeoutException) { // NOSONAR instanceof if (logger.isDebugEnabled()) { logger.debug("Closing socket after timeout " + getConnectionId()); } } else { - if (!(e instanceof SoftEndOfStreamException)) { + if (!(e instanceof SoftEndOfStreamException)) { // NOSONAR instanceof throw e; } } @@ -409,7 +409,7 @@ public class TcpNioConnection extends TcpConnectionSupport { } } - private void doRead() throws Exception { + private void doRead() throws IOException { if (this.rawBuffer == null) { this.rawBuffer = allocate(this.maxMessageSize); } @@ -447,7 +447,7 @@ public class TcpNioConnection extends TcpConnectionSupport { catch (RejectedExecutionException e) { throw e; } - catch (Exception e) { + catch (IOException e) { publishConnectionExceptionEvent(e); throw e; } diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/SocketSupportTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/SocketSupportTests.java index b86c47e462..f698f9fbd4 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/SocketSupportTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/SocketSupportTests.java @@ -473,7 +473,7 @@ public class SocketSupportTests { assertThatExceptionOfType(MessagingException.class) .isThrownBy(() -> testNioClientAndServerSSLDifferentContexts(true)) .withMessageMatching(".*(Socket closed during SSL Handshake|Broken pipe" - + "|Connection reset by peer|AsynchronousCloseException).*"); + + "|Connection reset by peer|AsynchronousCloseException|ClosedChannelException).*"); } private void testNioClientAndServerSSLDifferentContexts(boolean badClient) throws Exception { diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcChannelMessageStore.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcChannelMessageStore.java index f9cb2ff164..bb24d117e8 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcChannelMessageStore.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcChannelMessageStore.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -391,10 +391,9 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto * is not 1, a warning will be logged. When using the {@link JdbcChannelMessageStore} * with Oracle, the fetchSize value of 1 is needed to ensure FIFO characteristics * of polled messages. Please see the Oracle {@link ChannelMessageStoreQueryProvider} for more details. - * @throws Exception Any Exception. */ @Override - public void afterPropertiesSet() throws Exception { + public void afterPropertiesSet() { Assert.state(this.jdbcTemplate != null, "A DataSource or JdbcTemplate must be provided"); Assert.notNull(this.channelMessageStoreQueryProvider, "A channelMessageStoreQueryProvider must be provided."); @@ -428,7 +427,7 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto ps -> this.preparedStatementSetter.setValues(ps, message, groupId, this.region, this.priorityEnabled)); } - catch (DuplicateKeyException e) { + catch (@SuppressWarnings("unused") DuplicateKeyException e) { if (logger.isDebugEnabled()) { String messageId = getKey(message.getHeaders().getId()); logger.debug("The Message with id [" + messageId + "] already exists.\nIgnoring INSERT..."); diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java index 9e84b1483d..70e68fe991 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java @@ -507,11 +507,11 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp "No requestDestination, requestDestinationName, or requestDestinationExpression has been configured."); } - private Destination resolveRequestDestination(String requestDestinationName, Session session) throws JMSException { + private Destination resolveRequestDestination(String reqDestinationName, Session session) throws JMSException { Assert.notNull(this.destinationResolver, "DestinationResolver is required when relying upon the 'requestDestinationName' property."); return this.destinationResolver.resolveDestinationName( - session, requestDestinationName, this.requestPubSubDomain); + session, reqDestinationName, this.requestPubSubDomain); } private Destination determineReplyDestination(Message message, Session session) throws JMSException { @@ -536,11 +536,11 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp return session.createTemporaryQueue(); } - private Destination resolveReplyDestination(String replyDestinationName, Session session) throws JMSException { + private Destination resolveReplyDestination(String repDestinationName, Session session) throws JMSException { Assert.notNull(this.destinationResolver, "DestinationResolver is required when relying upon the 'replyDestinationName' property."); return this.destinationResolver.resolveDestinationName( - session, replyDestinationName, this.replyPubSubDomain); + session, repDestinationName, this.replyPubSubDomain); } @Override @@ -929,11 +929,11 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp * Creates the MessageConsumer before sending the request Message since we are generating * our own correlationId value for the MessageSelector. */ - private javax.jms.Message doSendAndReceiveWithGeneratedCorrelationId(Destination requestDestination, + private javax.jms.Message doSendAndReceiveWithGeneratedCorrelationId(Destination reqDestination, javax.jms.Message jmsRequest, Destination replyTo, Session session, int priority) throws JMSException { MessageProducer messageProducer = null; try { - messageProducer = session.createProducer(requestDestination); + messageProducer = session.createProducer(reqDestination); Assert.state(this.correlationKey != null, "correlationKey must not be null"); String messageSelector = null; if (!this.correlationKey.equals("JMSCorrelationID*") || jmsRequest.getJMSCorrelationID() == null) { @@ -963,12 +963,13 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp /** * Creates the MessageConsumer before sending the request Message since we do not need any correlation. */ - private javax.jms.Message doSendAndReceiveWithTemporaryReplyToDestination(Destination requestDestination, + private javax.jms.Message doSendAndReceiveWithTemporaryReplyToDestination(Destination reqDestination, javax.jms.Message jmsRequest, Destination replyTo, Session session, int priority) throws JMSException { + MessageProducer messageProducer = null; MessageConsumer messageConsumer = null; try { - messageProducer = session.createProducer(requestDestination); + messageProducer = session.createProducer(reqDestination); messageConsumer = session.createConsumer(replyTo); this.sendRequestMessage(jmsRequest, messageProducer, priority); return this.receiveReplyMessage(messageConsumer); @@ -983,8 +984,9 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp * Creates the MessageConsumer after sending the request Message since we need * the MessageID for correlation with a MessageSelector. */ - private javax.jms.Message doSendAndReceiveWithMessageIdCorrelation(Destination requestDestination, + private javax.jms.Message doSendAndReceiveWithMessageIdCorrelation(Destination reqDestination, javax.jms.Message jmsRequest, Destination replyTo, Session session, int priority) throws JMSException { + if (replyTo instanceof Topic && logger.isWarnEnabled()) { logger.warn("Relying on the MessageID for correlation is not recommended when using a Topic as the replyTo Destination " + "because that ID can only be provided to a MessageSelector after the request Message has been sent thereby " + @@ -994,7 +996,7 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp } MessageProducer messageProducer = null; try { - messageProducer = session.createProducer(requestDestination); + messageProducer = session.createProducer(reqDestination); this.sendRequestMessage(jmsRequest, messageProducer, priority); String messageId = jmsRequest.getJMSMessageID().replaceAll("'", "''"); String messageSelector = "JMSCorrelationID = '" + messageId + "'"; @@ -1053,7 +1055,7 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp try { Thread.sleep(1000); } - catch (InterruptedException e1) { + catch (@SuppressWarnings("unused") InterruptedException e1) { Thread.currentThread().interrupt(); return null; } @@ -1079,13 +1081,13 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp } } - private Object doSendAndReceiveAsync(Destination requestDestination, javax.jms.Message jmsRequest, Session session, + private Object doSendAndReceiveAsync(Destination reqDestination, javax.jms.Message jmsRequest, Session session, int priority) throws JMSException { String correlation = null; MessageProducer messageProducer = null; try { - messageProducer = session.createProducer(requestDestination); + messageProducer = session.createProducer(reqDestination); correlation = this.gatewayCorrelation + "_" + Long.toString(this.correlationId.incrementAndGet()); if (this.correlationKey.equals("JMSCorrelationID")) { jmsRequest.setJMSCorrelationID(correlation); @@ -1129,14 +1131,14 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp } } - private javax.jms.Message doSendAndReceiveAsyncDefaultCorrelation(Destination requestDestination, + private javax.jms.Message doSendAndReceiveAsyncDefaultCorrelation(Destination reqDestination, javax.jms.Message jmsRequest, Session session, int priority) throws JMSException { String correlation = null; MessageProducer messageProducer = null; try { - messageProducer = session.createProducer(requestDestination); + messageProducer = session.createProducer(reqDestination); LinkedBlockingQueue replyQueue = new LinkedBlockingQueue(1); this.sendRequestMessage(jmsRequest, messageProducer, priority); @@ -1171,7 +1173,7 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp } } - private javax.jms.Message obtainReplyFromContainer(String correlationId, + private javax.jms.Message obtainReplyFromContainer(String correlnId, LinkedBlockingQueue replyQueue) { javax.jms.Message reply = null; @@ -1190,28 +1192,28 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp if (logger.isDebugEnabled()) { if (reply == null) { logger.debug(this.getComponentName() + " Timed out waiting for reply with CorrelationId " - + correlationId); + + correlnId); } else { - logger.debug(this.getComponentName() + " Obtained reply with CorrelationId " + correlationId); + logger.debug(this.getComponentName() + " Obtained reply with CorrelationId " + correlnId); } } return reply; } - private SettableListenableFuture> createFuture(final String correlationId) { + private SettableListenableFuture> createFuture(final String correlnId) { SettableListenableFuture> future = new SettableListenableFuture>(); - this.futures.put(correlationId, future); + this.futures.put(correlnId, future); if (this.receiveTimeout > 0) { - getTaskScheduler().schedule((Runnable) () -> expire(correlationId), + getTaskScheduler().schedule((Runnable) () -> expire(correlnId), new Date(System.currentTimeMillis() + this.receiveTimeout)); } return future; } - private void expire(String correlationId) { - final SettableListenableFuture> future = this.futures.remove(correlationId); + private void expire(String correlnId) { + final SettableListenableFuture> future = this.futures.remove(correlnId); if (future != null) { try { if (getRequiresReply()) { @@ -1219,12 +1221,12 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp } else { if (logger.isDebugEnabled()) { - logger.debug("Reply expired and reply not required for " + correlationId); + logger.debug("Reply expired and reply not required for " + correlnId); } } } catch (Exception e) { - logger.error("Exception while expiring future"); + logger.error("Exception while expiring future", e); } } } @@ -1257,7 +1259,7 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp ((TemporaryTopic) destination).delete(); } } - catch (JMSException e) { + catch (@SuppressWarnings("unused") JMSException e) { // ignore } } @@ -1313,50 +1315,50 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp } } - private void onMessageAsync(javax.jms.Message message, String correlationId) throws Exception { - SettableListenableFuture> future = this.futures.remove(correlationId); + private void onMessageAsync(javax.jms.Message message, String correlnId) throws JMSException { + SettableListenableFuture> future = this.futures.remove(correlnId); if (future != null) { message.setJMSCorrelationID(null); future.set(buildReply(message)); } else { - logger.warn("Late reply for " + correlationId); + logger.warn("Late reply for " + correlnId); } } - private void onMessageSync(javax.jms.Message message, String correlationId) { + private void onMessageSync(javax.jms.Message message, String correlnId) { try { - LinkedBlockingQueue queue = this.replies.get(correlationId); + LinkedBlockingQueue queue = this.replies.get(correlnId); if (queue == null) { if (this.correlationKey != null) { Log debugLogger = LogFactory.getLog("si.jmsgateway.debug"); if (debugLogger.isDebugEnabled()) { Object siMessage = this.messageConverter.fromMessage(message); debugLogger.debug("No pending reply for " + siMessage + " with correlationId: " - + correlationId + " pending replies: " + this.replies.keySet()); + + correlnId + " pending replies: " + this.replies.keySet()); } throw new RuntimeException("No sender waiting for reply"); } synchronized (this.earlyOrLateReplies) { - queue = this.replies.get(correlationId); + queue = this.replies.get(correlnId); if (queue == null) { if (logger.isDebugEnabled()) { - logger.debug("Reply for correlationId " + correlationId + " received early or late"); + logger.debug("Reply for correlationId " + correlnId + " received early or late"); } - this.earlyOrLateReplies.put(correlationId, new TimedReply(message)); + this.earlyOrLateReplies.put(correlnId, new TimedReply(message)); } } } if (queue != null) { if (logger.isDebugEnabled()) { - logger.debug("Received reply with correlationId " + correlationId); + logger.debug("Received reply with correlationId " + correlnId); } queue.add(message); } } catch (Exception e) { if (logger.isWarnEnabled()) { - logger.warn("Failed to consume reply with correlationId " + correlationId, e); + logger.warn("Failed to consume reply with correlationId " + correlnId, e); } } } @@ -1408,7 +1410,7 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp try { Thread.sleep(100); } - catch (InterruptedException e) { + catch (@SuppressWarnings("unused") InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException("Container did not establish a destination"); } diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsChannelFactoryBean.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsChannelFactoryBean.java index e3bc9320af..b17e23f4e3 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsChannelFactoryBean.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsChannelFactoryBean.java @@ -26,13 +26,13 @@ import javax.jms.Session; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanNameAware; -import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.config.AbstractFactoryBean; import org.springframework.context.SmartLifecycle; import org.springframework.integration.jms.AbstractJmsChannel; import org.springframework.integration.jms.DynamicJmsTemplate; import org.springframework.integration.jms.PollableJmsChannel; import org.springframework.integration.jms.SubscribableJmsChannel; +import org.springframework.integration.util.JavaUtils; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.listener.AbstractMessageListenerContainer; import org.springframework.jms.listener.DefaultMessageListenerContainer; @@ -54,7 +54,7 @@ import org.springframework.util.StringUtils; * @since 2.0 */ public class JmsChannelFactoryBean extends AbstractFactoryBean - implements SmartLifecycle, DisposableBean, BeanNameAware { + implements SmartLifecycle, BeanNameAware { private volatile AbstractJmsChannel channel; @@ -372,7 +372,7 @@ public class JmsChannelFactoryBean extends AbstractFactoryBean { - JmsDefaultListenerContainerSpec() throws Exception { + JmsDefaultListenerContainerSpec() { super(DefaultMessageListenerContainer.class); } diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsListenerContainerSpec.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsListenerContainerSpec.java index a0df78825c..6e9dfd21f6 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsListenerContainerSpec.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsListenerContainerSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 the original author or authors. + * Copyright 2016-2019 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. @@ -37,13 +37,22 @@ import org.springframework.util.ErrorHandler; public class JmsListenerContainerSpec, C extends AbstractMessageListenerContainer> extends JmsDestinationAccessorSpec { - JmsListenerContainerSpec(Class aClass) throws Exception { - super(aClass.newInstance()); + JmsListenerContainerSpec(Class aClass) { + super(newInstance(aClass)); if (DefaultMessageListenerContainer.class.isAssignableFrom(aClass)) { this.target.setSessionTransacted(true); } } + private static C newInstance(Class aClass) { + try { + return aClass.newInstance(); + } + catch (InstantiationException | IllegalAccessException e) { + throw new IllegalStateException(e); + } + } + /** * @param destination the destination. * @return the spec. diff --git a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/AbstractConfigurableMongoDbMessageStore.java b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/AbstractConfigurableMongoDbMessageStore.java index fb79b03b78..14391e6894 100644 --- a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/AbstractConfigurableMongoDbMessageStore.java +++ b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/AbstractConfigurableMongoDbMessageStore.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2018 the original author or authors. + * Copyright 2014-2019 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. @@ -126,7 +126,7 @@ public abstract class AbstractConfigurableMongoDbMessageStore extends AbstractMe } @Override - public void afterPropertiesSet() throws Exception { + public void afterPropertiesSet() { if (this.mongoTemplate == null) { if (this.mappingMongoConverter == null) { this.mappingMongoConverter = new MappingMongoConverter(new DefaultDbRefResolver(this.mongoDbFactory), diff --git a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/MongoDbChannelMessageStore.java b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/MongoDbChannelMessageStore.java index fc0ed2900a..c66d916144 100644 --- a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/MongoDbChannelMessageStore.java +++ b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/MongoDbChannelMessageStore.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2018 the original author or authors. + * Copyright 2014-2019 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. @@ -88,7 +88,7 @@ public class MongoDbChannelMessageStore extends AbstractConfigurableMongoDbMessa } @Override - public void afterPropertiesSet() throws Exception { + public void afterPropertiesSet() { super.afterPropertiesSet(); this.mongoTemplate.indexOps(this.collectionName) .ensureIndex(new Index(MessageDocumentFields.GROUP_ID, Sort.Direction.ASC) diff --git a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/MongoDbMessageStore.java b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/MongoDbMessageStore.java index 6356033bb3..1eed97d8ef 100644 --- a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/MongoDbMessageStore.java +++ b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/MongoDbMessageStore.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -190,7 +190,7 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore } @Override - public void afterPropertiesSet() throws Exception { + public void afterPropertiesSet() { if (this.applicationContext != null) { this.converter.setApplicationContext(this.applicationContext); } @@ -353,7 +353,6 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore Query query = Query.query(Criteria.where(GROUP_ID_KEY).exists(true)); - @SuppressWarnings("rawtypes") Iterable groupIds = this.template.getCollection(this.collectionName) .distinct(GROUP_ID_KEY, query.getQueryObject(), String.class); diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/outbound/ExpressionArgumentsStrategy.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/outbound/ExpressionArgumentsStrategy.java index f44fdbb0af..e33d909f02 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/outbound/ExpressionArgumentsStrategy.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/outbound/ExpressionArgumentsStrategy.java @@ -74,7 +74,7 @@ public class ExpressionArgumentsStrategy implements ArgumentsStrategy, BeanFacto } @Override - public void afterPropertiesSet() throws Exception { + public void afterPropertiesSet() { if (this.evaluationContext == null) { this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.beanFactory); } diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/outbound/RedisStoreWritingMessageHandler.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/outbound/RedisStoreWritingMessageHandler.java index f97b14df06..0010776ba2 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/outbound/RedisStoreWritingMessageHandler.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/outbound/RedisStoreWritingMessageHandler.java @@ -321,7 +321,7 @@ public class RedisStoreWritingMessageHandler extends AbstractMessageHandler { } @SuppressWarnings("unchecked") - private void writeToZset(RedisZSet zset, final Message message) throws Exception { + private void writeToZset(RedisZSet zset, final Message message) { final Object payload = message.getPayload(); final BoundZSetOperations ops = (BoundZSetOperations) this.redisTemplate.boundZSetOps(zset.getKey()); diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/store/RedisChannelMessageStore.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/store/RedisChannelMessageStore.java index 0859bc44df..47497c6aa5 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/store/RedisChannelMessageStore.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/store/RedisChannelMessageStore.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2018 the original author or authors. + * Copyright 2014-2019 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. @@ -107,7 +107,7 @@ public class RedisChannelMessageStore implements ChannelMessageStore, BeanNameAw } @Override - public void afterPropertiesSet() throws Exception { + public void afterPropertiesSet() { Assert.notNull(this.beanName, "'beanName' must not be null"); } diff --git a/spring-integration-rmi/src/main/java/org/springframework/integration/rmi/RmiInboundGateway.java b/spring-integration-rmi/src/main/java/org/springframework/integration/rmi/RmiInboundGateway.java index 0ed2398fbd..ad2c3b833c 100644 --- a/spring-integration-rmi/src/main/java/org/springframework/integration/rmi/RmiInboundGateway.java +++ b/spring-integration-rmi/src/main/java/org/springframework/integration/rmi/RmiInboundGateway.java @@ -19,7 +19,6 @@ package org.springframework.integration.rmi; import java.rmi.RemoteException; import java.rmi.registry.Registry; -import org.springframework.beans.factory.InitializingBean; import org.springframework.integration.gateway.MessagingGatewaySupport; import org.springframework.integration.gateway.RequestReplyExchanger; import org.springframework.integration.support.context.NamedComponent; @@ -39,7 +38,7 @@ import org.springframework.util.StringUtils; * @author Gary Russell */ public class RmiInboundGateway extends MessagingGatewaySupport - implements RequestReplyExchanger, InitializingBean { + implements RequestReplyExchanger { public static final String SERVICE_NAME_PREFIX = "org.springframework.integration.rmiGateway."; diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java index 14472c7d4a..40555cf127 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java @@ -16,6 +16,7 @@ package org.springframework.integration.sftp.session; +import java.io.IOException; import java.util.Arrays; import java.util.Properties; import java.util.concurrent.locks.ReadWriteLock; @@ -394,7 +395,7 @@ public class DefaultSftpSessionFactory implements SessionFactory, Share } } - private com.jcraft.jsch.Session initJschSession() throws Exception { + private com.jcraft.jsch.Session initJschSession() throws JSchException, IOException { if (this.port <= 0) { this.port = 22; } diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/JschProxyFactoryBean.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/JschProxyFactoryBean.java index a71da71467..eeed4946b1 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/JschProxyFactoryBean.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/JschProxyFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2019 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. @@ -69,7 +69,7 @@ public class JschProxyFactoryBean extends AbstractFactoryBean { } @Override - protected Proxy createInstance() throws Exception { + protected Proxy createInstance() { switch (this.type) { case SOCKS5: ProxySOCKS5 socks5proxy = new ProxySOCKS5(this.host, this.port);