Avoid throws Exception where possible - Phase III
This commit is contained in:
committed by
Artem Bilan
parent
b138ab80f8
commit
78199dca9b
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 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.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.integration.mapping.support.JsonHeaders;
|
||||
import org.springframework.integration.support.AbstractIntegrationMessageBuilder;
|
||||
@@ -79,16 +82,21 @@ public class JsonToObjectTransformer extends AbstractTransformer implements Bean
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doTransform(Message<?> message) throws Exception {
|
||||
if (this.targetClass != null) {
|
||||
return this.jsonObjectMapper.fromJson(message.getPayload(), this.targetClass);
|
||||
protected Object doTransform(Message<?> message) {
|
||||
try {
|
||||
if (this.targetClass != null) {
|
||||
return this.jsonObjectMapper.fromJson(message.getPayload(), this.targetClass);
|
||||
}
|
||||
else {
|
||||
Object result = this.jsonObjectMapper.fromJson(message.getPayload(), message.getHeaders());
|
||||
AbstractIntegrationMessageBuilder<Object> messageBuilder = this.getMessageBuilderFactory().withPayload(result)
|
||||
.copyHeaders(message.getHeaders())
|
||||
.removeHeaders(JsonHeaders.HEADERS.toArray(new String[3]));
|
||||
return messageBuilder.build();
|
||||
}
|
||||
}
|
||||
else {
|
||||
Object result = this.jsonObjectMapper.fromJson(message.getPayload(), message.getHeaders());
|
||||
AbstractIntegrationMessageBuilder<Object> messageBuilder = this.getMessageBuilderFactory().withPayload(result)
|
||||
.copyHeaders(message.getHeaders())
|
||||
.removeHeaders(JsonHeaders.HEADERS.toArray(new String[3]));
|
||||
return messageBuilder.build();
|
||||
catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -17,7 +17,9 @@
|
||||
package org.springframework.integration.json;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.integration.support.json.JsonObjectMapper;
|
||||
@@ -111,7 +113,7 @@ public class ObjectToJsonTransformer extends AbstractTransformer {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doTransform(Message<?> message) throws Exception {
|
||||
protected Object doTransform(Message<?> message) {
|
||||
Object payload = buildJsonPayload(message.getPayload());
|
||||
|
||||
Map<String, Object> headers = new LinkedCaseInsensitiveMap<>();
|
||||
@@ -137,23 +139,28 @@ public class ObjectToJsonTransformer extends AbstractTransformer {
|
||||
.build();
|
||||
}
|
||||
|
||||
private Object buildJsonPayload(Object payload) throws Exception {
|
||||
switch (this.resultType) {
|
||||
private Object buildJsonPayload(Object payload) {
|
||||
try {
|
||||
switch (this.resultType) {
|
||||
|
||||
case STRING:
|
||||
return this.jsonObjectMapper.toJson(payload);
|
||||
case STRING:
|
||||
return this.jsonObjectMapper.toJson(payload);
|
||||
|
||||
case NODE:
|
||||
return this.jsonObjectMapper.toJsonNode(payload);
|
||||
case NODE:
|
||||
return this.jsonObjectMapper.toJsonNode(payload);
|
||||
|
||||
case BYTES:
|
||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||
this.jsonObjectMapper.toJson(payload, new OutputStreamWriter(baos));
|
||||
return baos.toByteArray();
|
||||
}
|
||||
case BYTES:
|
||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||
this.jsonObjectMapper.toJson(payload, new OutputStreamWriter(baos));
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported ResultType provided: " + this.resultType);
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported ResultType provided: " + this.resultType);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
*/
|
||||
public class Jackson2JsonObjectMapper extends AbstractJacksonJsonObjectMapper<JsonNode, JsonParser, JavaType> {
|
||||
|
||||
private static final String UNUSED = "unused";
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public Jackson2JsonObjectMapper() {
|
||||
@@ -188,7 +190,7 @@ public class Jackson2JsonObjectMapper extends AbstractJacksonJsonObjectMapper<Js
|
||||
ClassUtils.forName("com.fasterxml.jackson.datatype.jdk7.Jdk7Module", getClassLoader());
|
||||
this.objectMapper.registerModule(BeanUtils.instantiateClass(jdk7Module));
|
||||
}
|
||||
catch (@SuppressWarnings("unused") ClassNotFoundException ex) {
|
||||
catch (@SuppressWarnings(UNUSED) ClassNotFoundException ex) {
|
||||
// jackson-datatype-jdk7 not available
|
||||
}
|
||||
|
||||
@@ -197,7 +199,7 @@ public class Jackson2JsonObjectMapper extends AbstractJacksonJsonObjectMapper<Js
|
||||
ClassUtils.forName("com.fasterxml.jackson.datatype.jdk8.Jdk8Module", getClassLoader());
|
||||
this.objectMapper.registerModule(BeanUtils.instantiateClass(jdk8Module));
|
||||
}
|
||||
catch (@SuppressWarnings("unused") ClassNotFoundException ex) {
|
||||
catch (@SuppressWarnings(UNUSED) ClassNotFoundException ex) {
|
||||
// jackson-datatype-jdk8 not available
|
||||
}
|
||||
|
||||
@@ -206,7 +208,7 @@ public class Jackson2JsonObjectMapper extends AbstractJacksonJsonObjectMapper<Js
|
||||
ClassUtils.forName("com.fasterxml.jackson.datatype.jsr310.JavaTimeModule", getClassLoader());
|
||||
this.objectMapper.registerModule(BeanUtils.instantiateClass(javaTimeModule));
|
||||
}
|
||||
catch (@SuppressWarnings("unused") ClassNotFoundException ex) {
|
||||
catch (@SuppressWarnings(UNUSED) ClassNotFoundException ex) {
|
||||
// jackson-datatype-jsr310 not available
|
||||
}
|
||||
|
||||
@@ -217,7 +219,7 @@ public class Jackson2JsonObjectMapper extends AbstractJacksonJsonObjectMapper<Js
|
||||
ClassUtils.forName("com.fasterxml.jackson.datatype.joda.JodaModule", getClassLoader());
|
||||
this.objectMapper.registerModule(BeanUtils.instantiateClass(jodaModule));
|
||||
}
|
||||
catch (@SuppressWarnings("unused") ClassNotFoundException ex) {
|
||||
catch (@SuppressWarnings(UNUSED) ClassNotFoundException ex) {
|
||||
// jackson-datatype-joda not available
|
||||
}
|
||||
}
|
||||
@@ -229,7 +231,7 @@ public class Jackson2JsonObjectMapper extends AbstractJacksonJsonObjectMapper<Js
|
||||
ClassUtils.forName("com.fasterxml.jackson.module.kotlin.KotlinModule", getClassLoader());
|
||||
this.objectMapper.registerModule(BeanUtils.instantiateClass(kotlinModule));
|
||||
}
|
||||
catch (@SuppressWarnings("unused") ClassNotFoundException ex) {
|
||||
catch (@SuppressWarnings(UNUSED) ClassNotFoundException ex) {
|
||||
//jackson-module-kotlin not available
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -355,7 +355,7 @@ public class LockRegistryLeaderInitiator implements SmartLifecycle, DisposableBe
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
public Void call() {
|
||||
try {
|
||||
while (isRunning()) {
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
* Copyright 2015-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.
|
||||
@@ -67,6 +67,15 @@ public interface IntegrationManagement extends DisposableBean {
|
||||
// no op
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
default void destroy() {
|
||||
// no op
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Toggles to inform the management configurer to not set these properties since
|
||||
* the user has manually configured them in a bean definition. If true, the
|
||||
|
||||
@@ -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.
|
||||
@@ -188,7 +188,7 @@ public class LifecycleMessageHandlerMetrics implements MessageHandlerMetrics, Li
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
public void destroy() {
|
||||
this.delegate.destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -127,7 +127,7 @@ public class LifecycleMessageSourceMetrics implements MessageSourceMetrics, Life
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
public void destroy() {
|
||||
this.delegate.destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -165,7 +165,7 @@ public class TransactionSynchronizationFactoryBean implements FactoryBean<Defaul
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultTransactionSynchronizationFactory getObject() throws Exception {
|
||||
public DefaultTransactionSynchronizationFactory getObject() {
|
||||
if (this.channelResolver == null) {
|
||||
this.channelResolver = new BeanFactoryMessageChannelDestinationResolver(this.beanFactory);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -28,11 +28,12 @@ import org.springframework.messaging.Message;
|
||||
*/
|
||||
public abstract class AbstractPayloadTransformer<T, U> extends AbstractTransformer {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public final U doTransform(Message<?> message) throws Exception {
|
||||
public final U doTransform(Message<?> message) {
|
||||
return this.transformPayload((T) message.getPayload());
|
||||
}
|
||||
|
||||
protected abstract U transformPayload(T payload) throws Exception;
|
||||
protected abstract U transformPayload(T payload);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -53,8 +53,7 @@ public abstract class AbstractTransformer extends IntegrationObjectSupport imple
|
||||
*
|
||||
* @param message The message.
|
||||
* @return The result of the transformation.
|
||||
* @throws Exception Any exception.
|
||||
*/
|
||||
protected abstract Object doTransform(Message<?> message) throws Exception;
|
||||
protected abstract Object doTransform(Message<?> message);
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -51,7 +51,7 @@ public class ClaimCheckInTransformer extends AbstractTransformer {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doTransform(Message<?> message) throws Exception {
|
||||
protected Object doTransform(Message<?> message) {
|
||||
Assert.notNull(message, "message must not be null");
|
||||
UUID id = message.getHeaders().getId();
|
||||
Assert.notNull(id, "ID header must not be null");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -60,7 +60,7 @@ public class ClaimCheckOutTransformer extends AbstractTransformer {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doTransform(Message<?> message) throws Exception {
|
||||
protected Object doTransform(Message<?> message) {
|
||||
Assert.notNull(message, "message must not be null");
|
||||
Assert.isTrue(message.getPayload() instanceof UUID, "payload must be a UUID");
|
||||
UUID id = (UUID) message.getPayload();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
* Copyright 2015-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.transformer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.integration.codec.Codec;
|
||||
@@ -79,10 +82,15 @@ public class DecodingTransformer<T> extends AbstractTransformer {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T doTransform(Message<?> message) throws Exception {
|
||||
protected T doTransform(Message<?> message) {
|
||||
Assert.isTrue(message.getPayload() instanceof byte[], "Message payload must be byte[]");
|
||||
byte[] bytes = (byte[]) message.getPayload();
|
||||
return this.codec.decode(bytes, this.type != null ? this.type : type(message));
|
||||
try {
|
||||
return this.codec.decode(bytes, this.type != null ? this.type : type(message));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
* Copyright 2015-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.transformer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
import org.springframework.integration.codec.Codec;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -37,8 +40,13 @@ public class EncodingPayloadTransformer<T> extends AbstractPayloadTransformer<T,
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] transformPayload(T payload) throws Exception {
|
||||
return this.codec.encode(payload);
|
||||
protected byte[] transformPayload(T payload) {
|
||||
try {
|
||||
return this.codec.encode(payload);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -20,13 +20,8 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.context.IntegrationObjectSupport;
|
||||
import org.springframework.integration.handler.MessageProcessor;
|
||||
import org.springframework.integration.support.AbstractIntegrationMessageBuilder;
|
||||
@@ -46,9 +41,7 @@ import org.springframework.messaging.MessageHeaders;
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
*/
|
||||
public class HeaderEnricher extends IntegrationObjectSupport implements Transformer, BeanNameAware, InitializingBean {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(HeaderEnricher.class);
|
||||
public class HeaderEnricher extends IntegrationObjectSupport implements Transformer {
|
||||
|
||||
private final Map<String, ? extends HeaderValueMessageProcessor<?>> headersToAdd;
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -76,7 +76,7 @@ public class MapToObjectTransformer extends AbstractPayloadTransformer<Map<?, ?>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object transformPayload(Map<?, ?> payload) throws Exception {
|
||||
protected Object transformPayload(Map<?, ?> payload) {
|
||||
Object target = (this.targetClass != null)
|
||||
? BeanUtils.instantiateClass(this.targetClass)
|
||||
: this.getBeanFactory().getBean(this.targetBeanName);
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.integration.transformer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -93,8 +95,14 @@ public class ObjectToMapTransformer extends AbstractPayloadTransformer<Object, M
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Map<String, Object> transformPayload(Object payload) throws Exception {
|
||||
Map<String, Object> result = this.jsonObjectMapper.fromJson(this.jsonObjectMapper.toJson(payload), Map.class);
|
||||
protected Map<String, Object> transformPayload(Object payload) {
|
||||
Map<String, Object> result;
|
||||
try {
|
||||
result = this.jsonObjectMapper.fromJson(this.jsonObjectMapper.toJson(payload), Map.class);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
if (this.shouldFlattenKeys) {
|
||||
result = this.flattenMap(result);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 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,8 @@
|
||||
|
||||
package org.springframework.integration.transformer;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
@@ -52,9 +54,14 @@ public class ObjectToStringTransformer extends AbstractPayloadTransformer<Object
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String transformPayload(Object payload) throws Exception {
|
||||
protected String transformPayload(Object payload) {
|
||||
if (payload instanceof byte[]) {
|
||||
return new String((byte[]) payload, this.charset);
|
||||
try {
|
||||
return new String((byte[]) payload, this.charset);
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
else if (payload instanceof char[]) {
|
||||
return new String((char[]) payload);
|
||||
|
||||
@@ -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.
|
||||
@@ -18,7 +18,9 @@ package org.springframework.integration.transformer;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
import org.springframework.integration.StaticMessageHeaderAccessor;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -55,16 +57,21 @@ public class StreamTransformer extends AbstractTransformer {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doTransform(Message<?> message) throws Exception {
|
||||
Assert.isTrue(message.getPayload() instanceof InputStream, "payload must be an InputStream");
|
||||
InputStream stream = (InputStream) message.getPayload();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
FileCopyUtils.copy(stream, baos);
|
||||
Closeable closeableResource = StaticMessageHeaderAccessor.getCloseableResource(message);
|
||||
if (closeableResource != null) {
|
||||
closeableResource.close();
|
||||
protected Object doTransform(Message<?> message) {
|
||||
try {
|
||||
Assert.isTrue(message.getPayload() instanceof InputStream, "payload must be an InputStream");
|
||||
InputStream stream = (InputStream) message.getPayload();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
FileCopyUtils.copy(stream, baos);
|
||||
Closeable closeableResource = StaticMessageHeaderAccessor.getCloseableResource(message);
|
||||
if (closeableResource != null) {
|
||||
closeableResource.close();
|
||||
}
|
||||
return this.charset == null ? baos.toByteArray() : baos.toString(this.charset);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return this.charset == null ? baos.toByteArray() : baos.toString(this.charset);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -62,7 +62,7 @@ public class SyslogToMapTransformer extends AbstractPayloadTransformer<Object, M
|
||||
private final Pattern pattern = Pattern.compile("<([^>]+)>(.{15}) ([^ ]+) ([a-zA-Z0-9]{0,32})(.*)", Pattern.DOTALL);
|
||||
|
||||
@Override
|
||||
protected Map<String, ?> transformPayload(Object payload) throws Exception {
|
||||
protected Map<String, ?> transformPayload(Object payload) {
|
||||
boolean isByteArray = payload instanceof byte[];
|
||||
boolean isString = payload instanceof String;
|
||||
Assert.isTrue(isByteArray || isString, "payload must be String or byte[]");
|
||||
@@ -80,7 +80,7 @@ public class SyslogToMapTransformer extends AbstractPayloadTransformer<Object, M
|
||||
try {
|
||||
payload = new String(payloadBytes, "UTF-8");
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
catch (@SuppressWarnings("unused") UnsupportedEncodingException e) {
|
||||
payload = new String(payloadBytes);
|
||||
}
|
||||
return transform(payload);
|
||||
@@ -120,7 +120,7 @@ public class SyslogToMapTransformer extends AbstractPayloadTransformer<Object, M
|
||||
}
|
||||
map.put(TIMESTAMP, calendar.getTime());
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (@SuppressWarnings("unused") Exception e) {
|
||||
/*
|
||||
* If we can't parse the timestamp, return it as an
|
||||
* unmodified String. (Postel's law).
|
||||
|
||||
@@ -294,7 +294,7 @@ public class DelegatingConsumerParserTests {
|
||||
public static class MyTransformer extends AbstractTransformer {
|
||||
|
||||
@Override
|
||||
protected Object doTransform(Message<?> message) throws Exception {
|
||||
protected Object doTransform(Message<?> message) {
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,9 +61,9 @@ public class PayloadTransformerTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer transformPayload(String s) throws Exception {
|
||||
public Integer transformPayload(String s) {
|
||||
if (s.equals("bad")) {
|
||||
throw new Exception("bad input!");
|
||||
throw new IllegalStateException("bad input!");
|
||||
}
|
||||
return s.length();
|
||||
}
|
||||
|
||||
@@ -352,12 +352,13 @@ public abstract class AbstractInboundFileSynchronizer<F>
|
||||
}
|
||||
|
||||
private int copyIfNotNull(File localDirectory, Session<F> session, boolean filteringOneByOne, List<F> filteredFiles,
|
||||
int copied, F file) throws IOException {
|
||||
int copied, @Nullable F file) throws IOException {
|
||||
|
||||
boolean renamedFailed = false;
|
||||
try {
|
||||
if (file != null && !copyFileToLocalDirectory(this.evaluatedRemoteDirectory, file,
|
||||
localDirectory, session)) {
|
||||
copied--;
|
||||
renamedFailed = false;
|
||||
}
|
||||
}
|
||||
catch (RuntimeException | IOException e1) {
|
||||
@@ -369,7 +370,7 @@ public abstract class AbstractInboundFileSynchronizer<F>
|
||||
}
|
||||
throw e1;
|
||||
}
|
||||
return copied;
|
||||
return renamedFailed ? copied - 1 : copied;
|
||||
}
|
||||
|
||||
private List<F> applyFilter(F[] files, boolean haveFilter, boolean filteringOneByOne, int maxFetchSize) {
|
||||
@@ -483,14 +484,12 @@ public abstract class AbstractInboundFileSynchronizer<F>
|
||||
try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(tempFile))) {
|
||||
session.read(remoteFilePath, outputStream);
|
||||
}
|
||||
catch (RuntimeException e) { // NOSONAR catch and throw
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof RuntimeException) {
|
||||
throw (RuntimeException) e;
|
||||
}
|
||||
else {
|
||||
throw new MessagingException("Failure occurred while copying '" + remoteFilePath
|
||||
+ "' from the remote to the local directory", e);
|
||||
}
|
||||
throw new MessagingException("Failure occurred while copying '" + remoteFilePath
|
||||
+ "' from the remote to the local directory", e);
|
||||
}
|
||||
|
||||
renamed = tempFile.renameTo(localFile);
|
||||
|
||||
@@ -56,6 +56,10 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class StoredProcExecutor implements BeanFactoryAware, InitializingBean {
|
||||
|
||||
private static final int DEFAULT_CACHE_SIZE = 10;
|
||||
|
||||
private static final float LOAD_FACTOR = 0.75f;
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
private Map<String, RowMapper<?>> returningResultSetRowMappers = new HashMap<>(0);
|
||||
@@ -64,7 +68,7 @@ public class StoredProcExecutor implements BeanFactoryAware, InitializingBean {
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
private int jdbcCallOperationsCacheSize = 10;
|
||||
private int jdbcCallOperationsCacheSize = DEFAULT_CACHE_SIZE;
|
||||
|
||||
private Map<String, SimpleJdbcCallOperations> jdbcCallOperationsMap;
|
||||
|
||||
@@ -185,7 +189,7 @@ public class StoredProcExecutor implements BeanFactoryAware, InitializingBean {
|
||||
}
|
||||
|
||||
private Map<String, SimpleJdbcCallOperations> buildJdbcCallOperationsMap() {
|
||||
return new LinkedHashMap<String, SimpleJdbcCallOperations>(this.jdbcCallOperationsCacheSize + 1, 0.75f,
|
||||
return new LinkedHashMap<String, SimpleJdbcCallOperations>(this.jdbcCallOperationsCacheSize + 1, LOAD_FACTOR,
|
||||
true) {
|
||||
|
||||
private static final long serialVersionUID = 3801124242820219131L;
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.integration.file.remote.session.SessionFactory;
|
||||
import org.springframework.integration.file.remote.session.SharedSessionCapable;
|
||||
import org.springframework.integration.util.JavaUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -415,40 +416,25 @@ public class DefaultSftpSessionFactory implements SessionFactory<LsEntry>, Share
|
||||
}
|
||||
}
|
||||
com.jcraft.jsch.Session jschSession = this.jsch.getSession(this.user, this.host, this.port);
|
||||
if (this.sessionConfig != null) {
|
||||
jschSession.setConfig(this.sessionConfig);
|
||||
}
|
||||
String pw = this.userInfoWrapper.getPassword();
|
||||
if (StringUtils.hasText(pw)) {
|
||||
jschSession.setPassword(pw);
|
||||
}
|
||||
JavaUtils.INSTANCE
|
||||
.acceptIfNotNull(this.sessionConfig, jschSession::setConfig)
|
||||
.acceptIfHasText(this.userInfoWrapper.getPassword(), jschSession::setPassword);
|
||||
jschSession.setUserInfo(this.userInfoWrapper);
|
||||
|
||||
try {
|
||||
if (this.proxy != null) {
|
||||
jschSession.setProxy(this.proxy);
|
||||
}
|
||||
if (this.socketFactory != null) {
|
||||
jschSession.setSocketFactory(this.socketFactory);
|
||||
}
|
||||
if (this.timeout != null) {
|
||||
jschSession.setTimeout(this.timeout);
|
||||
}
|
||||
if (StringUtils.hasText(this.clientVersion)) {
|
||||
jschSession.setClientVersion(this.clientVersion);
|
||||
}
|
||||
if (StringUtils.hasText(this.hostKeyAlias)) {
|
||||
jschSession.setHostKeyAlias(this.hostKeyAlias);
|
||||
}
|
||||
if (this.serverAliveInterval != null) {
|
||||
jschSession.setServerAliveInterval(this.serverAliveInterval);
|
||||
}
|
||||
if (this.serverAliveCountMax != null) {
|
||||
jschSession.setServerAliveCountMax(this.serverAliveCountMax);
|
||||
}
|
||||
if (this.enableDaemonThread != null) {
|
||||
jschSession.setDaemonThread(this.enableDaemonThread);
|
||||
}
|
||||
JavaUtils.INSTANCE
|
||||
.acceptIfNotNull(this.proxy, jschSession::setProxy)
|
||||
.acceptIfNotNull(this.socketFactory, jschSession::setSocketFactory)
|
||||
.acceptIfHasText(this.clientVersion, jschSession::setClientVersion)
|
||||
.acceptIfHasText(this.hostKeyAlias, jschSession::setHostKeyAlias)
|
||||
.acceptIfNotNull(this.serverAliveCountMax, jschSession::setServerAliveCountMax)
|
||||
.acceptIfNotNull(this.enableDaemonThread, jschSession::setDaemonThread);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new BeanCreationException("Attempt to set additional properties of " +
|
||||
|
||||
@@ -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.
|
||||
@@ -83,7 +83,7 @@ public class DefaultMessageConverter implements MessageConverter, BeanFactoryAwa
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message<?> fromSyslog(Message<?> message) throws Exception {
|
||||
public Message<?> fromSyslog(Message<?> message) {
|
||||
Map<String, ?> map = this.transformer.doTransform(message);
|
||||
Map<String, Object> out = new HashMap<String, Object>();
|
||||
for (Entry<String, ?> entry : map.entrySet()) {
|
||||
|
||||
@@ -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.
|
||||
@@ -29,5 +29,6 @@ import org.springframework.messaging.Message;
|
||||
@FunctionalInterface
|
||||
public interface MessageConverter {
|
||||
|
||||
Message<?> fromSyslog(Message<?> syslog) throws Exception;
|
||||
Message<?> fromSyslog(Message<?> syslog);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 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.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.syslog;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.integration.support.AbstractIntegrationMessageBuilder;
|
||||
@@ -61,13 +62,18 @@ public class RFC5424MessageConverter extends DefaultMessageConverter {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Message<?> fromSyslog(Message<?> message) throws Exception {
|
||||
public Message<?> fromSyslog(Message<?> message) {
|
||||
boolean isMap = message.getPayload() instanceof Map;
|
||||
Map<String, ?> map;
|
||||
Object originalContent;
|
||||
if (!isMap) {
|
||||
Assert.isInstanceOf(byte[].class, message.getPayload(), "Only byte[] and Map payloads are supported");
|
||||
map = this.parser.parse(new String(((byte[]) message.getPayload()), this.charset), 0, false);
|
||||
try {
|
||||
map = this.parser.parse(new String(((byte[]) message.getPayload()), this.charset), 0, false);
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
originalContent = message.getPayload();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -215,7 +215,7 @@ public class SyslogReceivingChannelAdapterParserTests {
|
||||
public static class PassThruConverter implements MessageConverter {
|
||||
|
||||
@Override
|
||||
public Message<?> fromSyslog(Message<?> syslog) throws Exception {
|
||||
public Message<?> fromSyslog(Message<?> syslog) {
|
||||
return syslog;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.ws;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -59,7 +60,8 @@ public abstract class AbstractWebServiceInboundGateway extends MessagingGatewayS
|
||||
return this.headerMapper;
|
||||
}
|
||||
|
||||
public void invoke(MessageContext messageContext) throws Exception {
|
||||
@Override
|
||||
public void invoke(MessageContext messageContext) throws Exception { // NOSONAR - external interface
|
||||
if (!isRunning()) {
|
||||
throw new ServiceUnavailableException("503 Service Unavailable");
|
||||
}
|
||||
@@ -116,6 +118,6 @@ public abstract class AbstractWebServiceInboundGateway extends MessagingGatewayS
|
||||
return this.activeCount.get();
|
||||
}
|
||||
|
||||
protected abstract void doInvoke(MessageContext messageContext) throws Exception; // NOSONAR any exception
|
||||
protected abstract void doInvoke(MessageContext messageContext) throws IOException;
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.integration.ws;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.integration.support.AbstractIntegrationMessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
@@ -94,7 +96,7 @@ public class MarshallingWebServiceInboundGateway extends AbstractWebServiceInbou
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInvoke(MessageContext messageContext) throws Exception {
|
||||
protected void doInvoke(MessageContext messageContext) throws IOException {
|
||||
WebServiceMessage request = messageContext.getRequest();
|
||||
Assert.notNull(request, "Invalid message context: request was null.");
|
||||
Object requestObject = MarshallingUtils.unmarshal(this.unmarshaller, request);
|
||||
|
||||
@@ -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.
|
||||
@@ -49,7 +49,7 @@ public class SimpleWebServiceInboundGateway extends AbstractWebServiceInboundGat
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInvoke(MessageContext messageContext) throws Exception {
|
||||
protected void doInvoke(MessageContext messageContext) {
|
||||
|
||||
WebServiceMessage request = messageContext.getRequest();
|
||||
Assert.notNull(request, "Invalid message context: request was null.");
|
||||
@@ -85,7 +85,12 @@ public class SimpleWebServiceInboundGateway extends AbstractWebServiceInboundGat
|
||||
"The actual type was [" + replyPayload.getClass().getName() + "]");
|
||||
}
|
||||
WebServiceMessage response = messageContext.getResponse();
|
||||
this.transformerSupportDelegate.transformSourceToResult(responseSource, response.getPayloadResult());
|
||||
try {
|
||||
this.transformerSupportDelegate.transformSourceToResult(responseSource, response.getPayloadResult());
|
||||
}
|
||||
catch (TransformerException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
toSoapHeaders(response, replyMessage);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class XPathMessageSplitter extends AbstractMessageSplitter {
|
||||
|
||||
private Properties outputProperties;
|
||||
|
||||
private boolean iterator = true;
|
||||
private boolean returnIterator = true;
|
||||
|
||||
public XPathMessageSplitter(String expression) {
|
||||
this(expression, new HashMap<>());
|
||||
@@ -182,7 +182,7 @@ public class XPathMessageSplitter extends AbstractMessageSplitter {
|
||||
* @since 4.2
|
||||
*/
|
||||
public void setIterator(boolean iterator) {
|
||||
this.iterator = iterator;
|
||||
this.returnIterator = iterator;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,9 +200,9 @@ public class XPathMessageSplitter extends AbstractMessageSplitter {
|
||||
@Override
|
||||
protected void doInit() {
|
||||
super.doInit();
|
||||
if (this.iterator && this.jaxpExpression == null) {
|
||||
if (this.returnIterator && this.jaxpExpression == null) {
|
||||
logger.info("The 'iterator' option isn't available for an external XPathExpression. Will be ignored");
|
||||
this.iterator = false;
|
||||
this.returnIterator = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ public class XPathMessageSplitter extends AbstractMessageSplitter {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object splitDocument(Document document) throws Exception {
|
||||
private Object splitDocument(Document document) throws ParserConfigurationException, TransformerException {
|
||||
Object nodes = splitNode(document);
|
||||
final Transformer transformer;
|
||||
synchronized (this.transformerFactory) {
|
||||
@@ -282,7 +282,7 @@ public class XPathMessageSplitter extends AbstractMessageSplitter {
|
||||
}
|
||||
|
||||
private Object splitNode(Node node) throws ParserConfigurationException {
|
||||
if (this.iterator) {
|
||||
if (this.returnIterator) {
|
||||
try {
|
||||
NodeList nodeList = (NodeList) this.jaxpExpression.evaluate(node, XPathConstants.NODESET);
|
||||
return new NodeListIterator(nodeList);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -112,7 +112,7 @@ public class XPathTransformer extends AbstractTransformer {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doTransform(Message<?> message) throws Exception {
|
||||
protected Object doTransform(Message<?> message) {
|
||||
Node node = this.converter.convertToNode(message.getPayload());
|
||||
Object result = null;
|
||||
if (this.nodeMapper != null) {
|
||||
|
||||
@@ -250,7 +250,7 @@ public class XsltPayloadTransformer extends AbstractXmlTransformer implements Be
|
||||
try {
|
||||
transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "file,jar:file");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
catch (@SuppressWarnings("unused") IllegalArgumentException ex) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("The '" + XMLConstants.ACCESS_EXTERNAL_STYLESHEET + "' property is not supported by "
|
||||
+ transformerFactory.getClass().getCanonicalName());
|
||||
@@ -260,33 +260,38 @@ public class XsltPayloadTransformer extends AbstractXmlTransformer implements Be
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doTransform(Message<?> message) throws Exception {
|
||||
Transformer transformer = buildTransformer(message);
|
||||
Object payload;
|
||||
if (this.alwaysUseSourceFactory) {
|
||||
payload = this.sourceFactory.createSource(message.getPayload());
|
||||
protected Object doTransform(Message<?> message) {
|
||||
try {
|
||||
Transformer transformer = buildTransformer(message);
|
||||
Object payload;
|
||||
if (this.alwaysUseSourceFactory) {
|
||||
payload = this.sourceFactory.createSource(message.getPayload());
|
||||
}
|
||||
else {
|
||||
payload = message.getPayload();
|
||||
}
|
||||
Object transformedPayload = null;
|
||||
if (this.alwaysUseResultFactory) {
|
||||
transformedPayload = transformUsingResultFactory(payload, transformer);
|
||||
}
|
||||
else if (payload instanceof String) {
|
||||
transformedPayload = transformString((String) payload, transformer);
|
||||
}
|
||||
else if (payload instanceof Document) {
|
||||
transformedPayload = transformDocument((Document) payload, transformer);
|
||||
}
|
||||
else if (payload instanceof Source) {
|
||||
transformedPayload = transformSource((Source) payload, payload, transformer);
|
||||
}
|
||||
else {
|
||||
// fall back to trying factories
|
||||
transformedPayload = transformUsingResultFactory(payload, transformer);
|
||||
}
|
||||
return transformedPayload;
|
||||
}
|
||||
else {
|
||||
payload = message.getPayload();
|
||||
catch (TransformerException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
Object transformedPayload = null;
|
||||
if (this.alwaysUseResultFactory) {
|
||||
transformedPayload = transformUsingResultFactory(payload, transformer);
|
||||
}
|
||||
else if (payload instanceof String) {
|
||||
transformedPayload = transformString((String) payload, transformer);
|
||||
}
|
||||
else if (payload instanceof Document) {
|
||||
transformedPayload = transformDocument((Document) payload, transformer);
|
||||
}
|
||||
else if (payload instanceof Source) {
|
||||
transformedPayload = transformSource((Source) payload, payload, transformer);
|
||||
}
|
||||
else {
|
||||
// fall back to trying factories
|
||||
transformedPayload = transformUsingResultFactory(payload, transformer);
|
||||
}
|
||||
return transformedPayload;
|
||||
}
|
||||
|
||||
private Object transformUsingResultFactory(Object payload, Transformer transformer) throws TransformerException {
|
||||
|
||||
@@ -61,7 +61,7 @@ public class XPathSplitterParserTests {
|
||||
public void testXpathSplitterConfig() {
|
||||
assertThat(TestUtils.getPropertyValue(this.xpathSplitter, "createDocuments", Boolean.class)).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(this.xpathSplitter, "applySequence", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(this.xpathSplitter, "iterator", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(this.xpathSplitter, "returnIterator", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(this.xpathSplitter, "outputProperties")).isSameAs(this.outputProperties);
|
||||
assertThat(TestUtils.getPropertyValue(this.xpathSplitter,
|
||||
"xpathExpression.xpathExpression.xpath.m_patternString",
|
||||
|
||||
@@ -60,7 +60,7 @@ import org.springframework.xml.transform.StringSource;
|
||||
*/
|
||||
public class XsltPayloadTransformerTests {
|
||||
|
||||
private XsltPayloadTransformer transformer;
|
||||
private XsltPayloadTransformer testTransformer;
|
||||
|
||||
private final String docAsString =
|
||||
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><order><orderItem>test</orderItem></order>";
|
||||
@@ -72,16 +72,16 @@ public class XsltPayloadTransformerTests {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.transformer = new XsltPayloadTransformer(getXslTemplates());
|
||||
this.transformer.setBeanFactory(Mockito.mock(BeanFactory.class));
|
||||
this.transformer.setAlwaysUseResultFactory(false);
|
||||
this.transformer.afterPropertiesSet();
|
||||
this.testTransformer = new XsltPayloadTransformer(getXslTemplates());
|
||||
this.testTransformer.setBeanFactory(Mockito.mock(BeanFactory.class));
|
||||
this.testTransformer.setAlwaysUseResultFactory(false);
|
||||
this.testTransformer.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDocumentAsPayload() throws Exception {
|
||||
Message<?> message = new GenericMessage<>(XmlTestUtil.getDocumentForString(this.docAsString));
|
||||
Object transformed = this.transformer.doTransform(message);
|
||||
Object transformed = this.testTransformer.doTransform(message);
|
||||
assertThat(transformed)
|
||||
.as("Wrong return type for document payload")
|
||||
.isInstanceOf(Document.class);
|
||||
@@ -92,7 +92,7 @@ public class XsltPayloadTransformerTests {
|
||||
@Test
|
||||
public void testSourceAsPayload() throws Exception {
|
||||
GenericMessage<?> message = new GenericMessage<>(new StringSource(this.docAsString));
|
||||
Object transformed = transformer.doTransform(message);
|
||||
Object transformed = testTransformer.doTransform(message);
|
||||
|
||||
assertThat(transformed)
|
||||
.as("Wrong return type for document payload")
|
||||
@@ -105,8 +105,8 @@ public class XsltPayloadTransformerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringAsPayload() throws Exception {
|
||||
Object transformed = this.transformer.doTransform(new GenericMessage<>(this.docAsString));
|
||||
public void testStringAsPayload() {
|
||||
Object transformed = this.testTransformer.doTransform(new GenericMessage<>(this.docAsString));
|
||||
|
||||
assertThat(transformed)
|
||||
.as("Wrong return type for document payload")
|
||||
@@ -120,8 +120,8 @@ public class XsltPayloadTransformerTests {
|
||||
|
||||
@Test
|
||||
public void testStringAsPayloadUseResultFactoryTrue() throws Exception {
|
||||
this.transformer.setAlwaysUseResultFactory(true);
|
||||
Object transformed = transformer.doTransform(new GenericMessage<>(this.docAsString));
|
||||
this.testTransformer.setAlwaysUseResultFactory(true);
|
||||
Object transformed = testTransformer.doTransform(new GenericMessage<>(this.docAsString));
|
||||
|
||||
assertThat(transformed)
|
||||
.as("Wrong return type for useFactories true")
|
||||
@@ -171,18 +171,19 @@ public class XsltPayloadTransformerTests {
|
||||
|
||||
@Test
|
||||
public void testNonXmlString() {
|
||||
assertThatExceptionOfType(TransformerException.class)
|
||||
.isThrownBy(() -> this.transformer.doTransform(new GenericMessage<>("test")));
|
||||
assertThatExceptionOfType(IllegalStateException.class)
|
||||
.isThrownBy(() -> this.testTransformer.doTransform(new GenericMessage<>("test")))
|
||||
.withCauseInstanceOf(TransformerException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedPayloadType() {
|
||||
assertThatExceptionOfType(MessagingException.class)
|
||||
.isThrownBy(() -> this.transformer.doTransform(new GenericMessage<>(12)));
|
||||
.isThrownBy(() -> this.testTransformer.doTransform(new GenericMessage<>(12)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXsltWithImports() throws Exception {
|
||||
public void testXsltWithImports() {
|
||||
Resource resource = new ClassPathResource("transform-with-import.xsl", getClass());
|
||||
XsltPayloadTransformer transformer = new XsltPayloadTransformer(resource);
|
||||
transformer.setBeanFactory(Mockito.mock(BeanFactory.class));
|
||||
@@ -271,6 +272,7 @@ public class XsltPayloadTransformerTests {
|
||||
this.objectToReturn = objectToReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object transformResult(Result result) {
|
||||
return objectToReturn;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.roster.Roster;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
import org.jxmpp.util.XmppStringUtils;
|
||||
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
@@ -134,7 +135,7 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnectio
|
||||
}
|
||||
|
||||
@Override
|
||||
protected XMPPConnection createInstance() throws Exception {
|
||||
protected XMPPConnection createInstance() throws XmppStringprepException {
|
||||
XMPPTCPConnectionConfiguration connectionConfig = this.connectionConfiguration;
|
||||
if (connectionConfig == null) {
|
||||
XMPPTCPConnectionConfiguration.Builder builder =
|
||||
|
||||
@@ -58,7 +58,7 @@ public class XmppConnectionFactoryBeanTests {
|
||||
new XmppConnectionFactoryBean() {
|
||||
|
||||
@Override
|
||||
protected XMPPConnection createInstance() throws Exception {
|
||||
protected XMPPConnection createInstance() {
|
||||
return mock(XMPPTCPConnection.class);
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public class XmppConnectionFactoryBeanTests {
|
||||
new XmppConnectionFactoryBean() {
|
||||
|
||||
@Override
|
||||
protected XMPPConnection createInstance() throws Exception {
|
||||
protected XMPPConnection createInstance() {
|
||||
return mock(XMPPTCPConnection.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -247,7 +247,7 @@ public class LeaderInitiator implements SmartLifecycle {
|
||||
protected class LeaderListener extends LeaderSelectorListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void takeLeadership(CuratorFramework framework) throws Exception {
|
||||
public void takeLeadership(CuratorFramework framework) {
|
||||
try {
|
||||
LeaderInitiator.this.candidate.onGranted(LeaderInitiator.this.context);
|
||||
if (LeaderInitiator.this.leaderEventPublisher != null) {
|
||||
@@ -265,7 +265,7 @@ public class LeaderInitiator implements SmartLifecycle {
|
||||
// candidate is no longer leader
|
||||
Thread.sleep(Long.MAX_VALUE);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
catch (@SuppressWarnings("unused") InterruptedException e) {
|
||||
// InterruptedException, like any other runtime exception,
|
||||
// is handled by the finally block below. No need to
|
||||
// reset the interrupt flag as the interrupt is handled.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2017 the original author or authors.
|
||||
* Copyright 2015-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.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.integration.zookeeper.lock;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -157,7 +156,7 @@ public class ZookeeperLockRegistry implements ExpirableLockRegistry, DisposableB
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
public void destroy() {
|
||||
if (!this.mutexTaskExecutorExplicitlySet) {
|
||||
((ExecutorConfigurationSupport) this.mutexTaskExecutor).shutdown();
|
||||
}
|
||||
@@ -266,7 +265,7 @@ public class ZookeeperLockRegistry implements ExpirableLockRegistry, DisposableB
|
||||
try {
|
||||
return tryLock(1, TimeUnit.SECONDS);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
catch (@SuppressWarnings("unused") InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
}
|
||||
@@ -278,13 +277,13 @@ public class ZookeeperLockRegistry implements ExpirableLockRegistry, DisposableB
|
||||
try {
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
future = this.mutexTaskExecutor.submit(new Callable<Boolean>() {
|
||||
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
future = this.mutexTaskExecutor.submit(() -> {
|
||||
try {
|
||||
return ZkLock.this.client.checkExists().forPath("/") != null;
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
});
|
||||
|
||||
long waitTime = unit.toMillis(time);
|
||||
@@ -300,10 +299,16 @@ public class ZookeeperLockRegistry implements ExpirableLockRegistry, DisposableB
|
||||
return this.mutex.acquire(waitTime, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
catch (TimeoutException e) {
|
||||
future.cancel(true);
|
||||
catch (@SuppressWarnings("unused") TimeoutException e) {
|
||||
if (future != null) {
|
||||
future.cancel(true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new MessagingException("Failed to acquire mutex at " + this.path, e);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2018 the original author or authors.
|
||||
* Copyright 2015-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.
|
||||
@@ -48,6 +48,8 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLifecycle {
|
||||
|
||||
private static final String UNUSED = "unused";
|
||||
|
||||
private final Object lifecycleMonitor = new Object();
|
||||
|
||||
private final CuratorFramework client;
|
||||
@@ -120,14 +122,15 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif
|
||||
createNode(key, value);
|
||||
return null;
|
||||
}
|
||||
catch (KeeperException.NodeExistsException e) {
|
||||
catch (@SuppressWarnings(UNUSED) KeeperException.NodeExistsException e) {
|
||||
// so the data actually exists, we can read it
|
||||
try {
|
||||
byte[] bytes = this.client.getData().forPath(getPath(key));
|
||||
return IntegrationUtils.bytesToString(bytes, this.encoding);
|
||||
}
|
||||
catch (Exception exceptionDuringGet) {
|
||||
throw new ZookeeperMetadataStoreException("Exception while reading node with key '" + key + "':", e);
|
||||
throw new ZookeeperMetadataStoreException("Exception while reading node with key '" + key + "':",
|
||||
exceptionDuringGet);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
@@ -150,16 +153,16 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (KeeperException.NoNodeException e) {
|
||||
catch (@SuppressWarnings(UNUSED) KeeperException.NoNodeException e) {
|
||||
// ignore, the node doesn't exist there's nothing to replace
|
||||
return false;
|
||||
}
|
||||
catch (KeeperException.BadVersionException e) {
|
||||
catch (@SuppressWarnings(UNUSED) KeeperException.BadVersionException e) {
|
||||
// ignore
|
||||
return false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ZookeeperMetadataStoreException("Cannot replace value");
|
||||
throw new ZookeeperMetadataStoreException("Cannot replace value", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -186,7 +189,7 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif
|
||||
try {
|
||||
createNode(key, value);
|
||||
}
|
||||
catch (KeeperException.NodeExistsException e) {
|
||||
catch (@SuppressWarnings(UNUSED) KeeperException.NodeExistsException e) {
|
||||
updateNode(key, value, -1);
|
||||
}
|
||||
}
|
||||
@@ -240,7 +243,7 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif
|
||||
this.updateMap.put(key, new LocalChildData(null, Integer.MAX_VALUE));
|
||||
return IntegrationUtils.bytesToString(bytes, this.encoding);
|
||||
}
|
||||
catch (KeeperException.NoNodeException e) {
|
||||
catch (@SuppressWarnings(UNUSED) KeeperException.NoNodeException e) {
|
||||
// ignore - the node doesn't exist
|
||||
return null;
|
||||
}
|
||||
@@ -250,13 +253,13 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif
|
||||
}
|
||||
}
|
||||
|
||||
private void updateNode(String key, String value, int version) throws Exception {
|
||||
private void updateNode(String key, String value, int version) throws Exception { // NOSONAR external lib throws
|
||||
Stat stat = this.client.setData().withVersion(version).forPath(getPath(key),
|
||||
IntegrationUtils.stringToBytes(value, this.encoding));
|
||||
this.updateMap.put(key, new LocalChildData(value, stat.getVersion()));
|
||||
}
|
||||
|
||||
private void createNode(String key, String value) throws Exception {
|
||||
private void createNode(String key, String value) throws Exception { // NOSONAR external lib throws
|
||||
this.client.create().forPath(getPath(key), IntegrationUtils.stringToBytes(value, this.encoding));
|
||||
this.updateMap.put(key, new LocalChildData(value, 0));
|
||||
}
|
||||
@@ -359,7 +362,7 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif
|
||||
}
|
||||
|
||||
@Override
|
||||
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
|
||||
public void childEvent(CuratorFramework framework, PathChildrenCacheEvent event) {
|
||||
synchronized (ZookeeperMetadataStore.this.updateMap) {
|
||||
String eventPath = event.getData().getPath();
|
||||
String eventKey = getKey(eventPath);
|
||||
|
||||
Reference in New Issue
Block a user