Merge pull request #749 from garyrussell/INT-2936
* INT-2936: Fix TCP Binary DeSerialization with NIO
This commit is contained in:
@@ -69,7 +69,7 @@ public class TcpNioConnection extends TcpConnectionSupport {
|
||||
|
||||
private volatile long lastSend;
|
||||
|
||||
private AtomicInteger executionControl = new AtomicInteger();
|
||||
private final AtomicInteger executionControl = new AtomicInteger();
|
||||
|
||||
private volatile boolean writingToPipe;
|
||||
|
||||
@@ -560,7 +560,7 @@ public class TcpNioConnection extends TcpConnectionSupport {
|
||||
}
|
||||
}
|
||||
int bite;
|
||||
bite = this.currentBuffer[this.currentOffset++];
|
||||
bite = this.currentBuffer[this.currentOffset++] & 0xff;
|
||||
this.available.decrementAndGet();
|
||||
if (this.currentOffset >= this.currentBuffer.length) {
|
||||
this.currentBuffer = null;
|
||||
|
||||
@@ -23,6 +23,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.Socket;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -31,7 +32,9 @@ import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.integration.ip.tcp.connection.TcpNioConnection.ChannelInputStream;
|
||||
import org.springframework.integration.ip.tcp.serializer.ByteArrayStxEtxSerializer;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
|
||||
/**
|
||||
* @author Gary Russell
|
||||
@@ -68,4 +71,15 @@ public class TcpNetConnectionTests {
|
||||
log.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBinary() throws Exception {
|
||||
SocketChannel socketChannel = mock(SocketChannel.class);
|
||||
Socket socket = mock(Socket.class);
|
||||
when(socketChannel.socket()).thenReturn(socket);
|
||||
TcpNioConnection connection = new TcpNioConnection(socketChannel, true, false, null, null);
|
||||
ChannelInputStream inputStream = TestUtils.getPropertyValue(connection, "channelInputStream", ChannelInputStream.class);
|
||||
inputStream.write(new byte[] {(byte) 0x80}, 1);
|
||||
assertEquals(0x80, inputStream.read());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user