INT-1280 (partial) - Move java serializer implementations to subpackage
This commit is contained in:
@@ -14,24 +14,25 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.commons.serializer;
|
||||
package org.springframework.commons.serializer.java;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.commons.serializer.DeserializationFailureException;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
|
||||
/**
|
||||
* Delegates to a {@link JavaSerializationConverter} to deserialize data
|
||||
* Delegates to a {@link JavaStreamingConverter} to deserialize data
|
||||
* in a byte[] to an object.
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public class JavaDeserializingConverter implements Converter<byte[], Object> {
|
||||
public class DeserializingConverter implements Converter<byte[], Object> {
|
||||
|
||||
private JavaSerializationConverter converter = new JavaSerializationConverter();
|
||||
private JavaStreamingConverter converter = new JavaStreamingConverter();
|
||||
|
||||
public Object convert(byte[] source) {
|
||||
ByteArrayInputStream byteStream = new ByteArrayInputStream(source);
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.commons.serializer;
|
||||
package org.springframework.commons.serializer.java;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -22,6 +22,9 @@ import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.springframework.commons.serializer.InputStreamingConverter;
|
||||
import org.springframework.commons.serializer.OutputStreamingConverter;
|
||||
|
||||
|
||||
/**
|
||||
* Converter that implements both input and output streaming using Java
|
||||
@@ -31,7 +34,7 @@ import java.io.OutputStream;
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public class JavaSerializationConverter
|
||||
public class JavaStreamingConverter
|
||||
implements InputStreamingConverter<Object>,
|
||||
OutputStreamingConverter<Object> {
|
||||
|
||||
@@ -14,25 +14,26 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.commons.serializer;
|
||||
package org.springframework.commons.serializer.java;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.commons.serializer.SerializationFailureException;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Delegates to a {@link JavaSerializationConverter} to serialize an object
|
||||
* Delegates to a {@link JavaStreamingConverter} to serialize an object
|
||||
* to a byte[]. Source object must implement {@link Serializable}.
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public class JavaSerializingConverter implements Converter<Object, byte[]> {
|
||||
public class SerializingConverter implements Converter<Object, byte[]> {
|
||||
|
||||
private JavaSerializationConverter converter = new JavaSerializationConverter();
|
||||
private JavaStreamingConverter converter = new JavaStreamingConverter();
|
||||
|
||||
public byte[] convert(Object source) {
|
||||
Assert.isTrue(source instanceof Serializable, this.getClass().getName()
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Implementations of In/Out JavaStreamingConverter and
|
||||
* Converter using standard Java Serialization.
|
||||
*/
|
||||
package org.springframework.commons.serializer.java;
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
package org.springframework.integration.transformer;
|
||||
|
||||
import org.springframework.commons.serializer.JavaDeserializingConverter;
|
||||
import org.springframework.commons.serializer.java.DeserializingConverter;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Transformer that deserializes the inbound byte array payload to an object by delegating to a
|
||||
* Converter<byte[], Object>. Default delegate is a {@link JavaDeserializingConverter}.
|
||||
* Converter<byte[], Object>. Default delegate is a {@link DeserializingConverter}.
|
||||
* <p>The byte array payload must be a result of equivalent serialization.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
@@ -32,7 +32,7 @@ import org.springframework.util.Assert;
|
||||
public class PayloadDeserializingTransformer extends PayloadTypeConvertingTransformer<byte[], Object> {
|
||||
|
||||
public PayloadDeserializingTransformer() {
|
||||
this.converter = new JavaDeserializingConverter();
|
||||
this.converter = new DeserializingConverter();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
package org.springframework.integration.transformer;
|
||||
|
||||
import org.springframework.commons.serializer.JavaSerializingConverter;
|
||||
import org.springframework.commons.serializer.java.SerializingConverter;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Transformer that serializes the inbound payload into a byte array by delegating to a
|
||||
* Converter<Object, byte[]>. Default delegate is a {@link JavaSerializingConverter}.
|
||||
* Converter<Object, byte[]>. Default delegate is a {@link SerializingConverter}.
|
||||
*
|
||||
* <p>The payload instance must be Serializable if the default converter is used.
|
||||
*
|
||||
@@ -34,7 +34,7 @@ public class PayloadSerializingTransformer extends PayloadTypeConvertingTransfor
|
||||
|
||||
|
||||
public PayloadSerializingTransformer() {
|
||||
this.converter = new JavaSerializingConverter();
|
||||
this.converter = new SerializingConverter();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,6 +22,8 @@ import static org.junit.Assert.fail;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.commons.serializer.java.DeserializingConverter;
|
||||
import org.springframework.commons.serializer.java.SerializingConverter;
|
||||
|
||||
|
||||
/**
|
||||
@@ -33,15 +35,15 @@ public class JavaSerializationTests {
|
||||
|
||||
@Test
|
||||
public void testGood() {
|
||||
JavaSerializingConverter toBytes = new JavaSerializingConverter();
|
||||
SerializingConverter toBytes = new SerializingConverter();
|
||||
byte[] bytes = toBytes.convert("Testing");
|
||||
JavaDeserializingConverter fromBytes = new JavaDeserializingConverter();
|
||||
DeserializingConverter fromBytes = new DeserializingConverter();
|
||||
assertEquals("Testing", fromBytes.convert(bytes));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadSerializeNotSerializable() {
|
||||
JavaSerializingConverter toBytes = new JavaSerializingConverter();
|
||||
SerializingConverter toBytes = new SerializingConverter();
|
||||
try {
|
||||
toBytes.convert(new Object());
|
||||
fail("Expected IllegalArgumentException");
|
||||
@@ -51,7 +53,7 @@ public class JavaSerializationTests {
|
||||
|
||||
@Test
|
||||
public void testBadSerializeNotSerializableField() {
|
||||
JavaSerializingConverter toBytes = new JavaSerializingConverter();
|
||||
SerializingConverter toBytes = new SerializingConverter();
|
||||
try {
|
||||
toBytes.convert(new UnSerializable());
|
||||
fail("Expected SerializationFailureException");
|
||||
@@ -61,7 +63,7 @@ public class JavaSerializationTests {
|
||||
|
||||
@Test
|
||||
public void testBadDeserialize() {
|
||||
JavaDeserializingConverter fromBytes = new JavaDeserializingConverter();
|
||||
DeserializingConverter fromBytes = new DeserializingConverter();
|
||||
try {
|
||||
fromBytes.convert("Junk".getBytes());
|
||||
fail("Expected DeserializationFailureException");
|
||||
|
||||
@@ -320,7 +320,7 @@
|
||||
using-direct-buffers="true"
|
||||
/>
|
||||
|
||||
<bean id="serial" class="org.springframework.commons.serializer.JavaSerializationConverter" />
|
||||
<bean id="serial" class="org.springframework.commons.serializer.java.JavaStreamingConverter" />
|
||||
|
||||
<ip:tcp-outbound-channel-adapter id="tcpNewOut1"
|
||||
channel="tcpChannel"
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
<bean id="tcpIpUtils" class="org.springframework.integration.ip.util.SocketUtils" />
|
||||
|
||||
<bean id="serializer" class="org.springframework.commons.serializer.JavaSerializationConverter" />
|
||||
<bean id="serializer" class="org.springframework.commons.serializer.java.JavaStreamingConverter" />
|
||||
|
||||
<int-ip:tcp-connection-factory id="server"
|
||||
type="server"
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import javax.net.ServerSocketFactory;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.commons.serializer.JavaSerializationConverter;
|
||||
import org.springframework.commons.serializer.java.JavaStreamingConverter;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory;
|
||||
@@ -548,7 +548,7 @@ public class TcpSendingMessageHandlerTests {
|
||||
}
|
||||
});
|
||||
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", port);
|
||||
JavaSerializationConverter converter = new JavaSerializationConverter();
|
||||
JavaStreamingConverter converter = new JavaStreamingConverter();
|
||||
ccf.setInputConverter(converter);
|
||||
ccf.setOutputConverter(converter);
|
||||
ccf.setSoTimeout(10000);
|
||||
@@ -597,7 +597,7 @@ public class TcpSendingMessageHandlerTests {
|
||||
}
|
||||
});
|
||||
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost", port);
|
||||
JavaSerializationConverter converter = new JavaSerializationConverter();
|
||||
JavaStreamingConverter converter = new JavaStreamingConverter();
|
||||
ccf.setInputConverter(converter);
|
||||
ccf.setOutputConverter(converter);
|
||||
ccf.setSoTimeout(10000);
|
||||
|
||||
Reference in New Issue
Block a user