Skip to content

Commit

Permalink
INTEXT-45 Add Work Around for INT-2936
Browse files Browse the repository at this point in the history
Need to check for closed stream with NIO.
  • Loading branch information
garyrussell committed Feb 16, 2013
1 parent eb8f24f commit b1448bd
Showing 1 changed file with 27 additions and 0 deletions.
Expand Up @@ -28,6 +28,7 @@
import java.util.Set;

import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.core.serializer.Serializer;
import org.springframework.integration.MessagingException;
import org.springframework.integration.ip.tcp.serializer.SoftEndOfStreamException;
Expand Down Expand Up @@ -202,6 +203,7 @@ private DataFrame doDeserialize(InputStream inputStream, DataFrame protoFrame) t
while (!done ) {
bite = inputStream.read() & 0xff;
// logger.debug("Read:" + Integer.toHexString(bite));
bite = checkclosed(bite, inputStream);
if (bite < 0 && n == 0) {
throw new SoftEndOfStreamException("Stream closed between payloads");
}
Expand Down Expand Up @@ -416,6 +418,31 @@ else if (close) {
return frame;
}

/**
* TODO: workaround for INT-2936
*/
private int checkclosed(int bite, InputStream inputStream) {
int theBite = bite;
if (theBite == 0xff) { // possibly a closed stream
String streamClass = inputStream.getClass().getName();
if (streamClass.endsWith("TcpNioConnection$ChannelInputStream")) {
DirectFieldAccessor dfa = new DirectFieldAccessor(inputStream);
try {
if ((Boolean) dfa.getPropertyValue("isClosed") &&
inputStream.available() == 0) {
theBite = -1;
}
}
catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to check closed", e);
}
}
}
}
return theBite;
}

private boolean validateUtf8IfNecessary(byte[] buffer, int offset, String data) {
if (this.validateUtf8) {
try {
Expand Down

0 comments on commit b1448bd

Please sign in to comment.