Author: hiranya
Date: Wed Aug 14 21:54:44 2013
New Revision: 1514063
URL: http://svn.apache.org/r1514063
Log:
Handled the endOfInput event properly in the PT TargetHandler
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/SourceHandler.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetContext.java
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetHandler.java
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/SourceHandler.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/SourceHandler.java?rev=1514063&r1=1514062&r2=1514063&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/SourceHandler.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/SourceHandler.java
Wed Aug 14 21:54:44 2013
@@ -261,14 +261,14 @@ public class SourceHandler implements NH
if (state == ProtocolState.REQUEST_READY || state ==
ProtocolState.RESPONSE_DONE) {
if (log.isDebugEnabled()) {
- log.debug("Keep-Alive connection was closed at the remote end:
" + conn);
+ log.debug("Keep-Alive connection was closed by the client: " +
conn);
}
} else if (state == ProtocolState.REQUEST_BODY || state ==
ProtocolState.REQUEST_HEAD) {
informReaderError(conn);
- log.warn("Connection closed at the remote end while reading the
request: " + conn);
+ log.warn("Connection closed by the client while reading the
request: " + conn);
} else if (state == ProtocolState.RESPONSE_BODY || state ==
ProtocolState.RESPONSE_HEAD) {
informWriterError(conn);
- log.warn("Connection closed at the remote end while writing the
response: " + conn);
+ log.warn("Connection closed by the client end while writing the
response: " + conn);
} else if (state == ProtocolState.REQUEST_DONE) {
log.warn("Connection closed by the client after request is read: "
+ conn);
}
@@ -424,7 +424,7 @@ public class SourceHandler implements NH
informWriterError(conn);
log.warn("Connection closed while writing the response: " + conn);
} else if (state == ProtocolState.REQUEST_DONE) {
- log.warn("Connection closed by the client after request is read: "
+ conn);
+ log.warn("Connection closed after request is read: " + conn);
}
metrics.disconnected();
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetContext.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetContext.java?rev=1514063&r1=1514062&r2=1514063&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetContext.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetContext.java
Wed Aug 14 21:54:44 2013
@@ -108,7 +108,10 @@ public class TargetContext {
public void reset() {
request = null;
response = null;
- state = ProtocolState.REQUEST_READY;
+ if (state != ProtocolState.CLOSED) {
+ // The connection is still not closed - Prepare to send more
requests on this
+ state = ProtocolState.REQUEST_READY;
+ }
if (writer != null) {
ByteBuffer buffer = writer.getBuffer();
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetHandler.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetHandler.java?rev=1514063&r1=1514062&r2=1514063&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetHandler.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetHandler.java
Wed Aug 14 21:54:44 2013
@@ -241,9 +241,7 @@ public class TargetHandler implements NH
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
-
informReaderError(conn);
-
TargetContext.updateState(conn, ProtocolState.CLOSED);
targetConfiguration.getConnections().shutdownConnection(conn);
}
@@ -292,16 +290,12 @@ public class TargetHandler implements NH
}
} catch (IOException e) {
logIOException(conn, e);
-
informReaderError(conn);
-
TargetContext.updateState(conn, ProtocolState.CLOSED);
targetConfiguration.getConnections().shutdownConnection(conn);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
-
informReaderError(conn);
-
TargetContext.updateState(conn, ProtocolState.CLOSED);
targetConfiguration.getConnections().shutdownConnection(conn);
}
@@ -318,15 +312,15 @@ public class TargetHandler implements NH
}
} else if (state == ProtocolState.REQUEST_HEAD || state ==
ProtocolState.REQUEST_BODY) {
informWriterError(conn);
- log.warn("Connection closed by target host while sending the
request");
+ log.warn("Connection closed while sending the request");
sendFault = true;
} else if (state == ProtocolState.RESPONSE_HEAD || state ==
ProtocolState.RESPONSE_BODY) {
informReaderError(conn);
- log.warn("Connection closed by target host while receiving the
response");
+ log.warn("Connection closed while receiving the response");
sendFault = false;
} else if (state == ProtocolState.REQUEST_DONE) {
informWriterError(conn);
- log.warn("Connection closed by target host before receiving the
request");
+ log.warn("Connection closed before receiving the request");
sendFault = true;
}
@@ -343,8 +337,10 @@ public class TargetHandler implements NH
metrics.disconnected();
- TargetContext.updateState(conn, ProtocolState.CLOSED);
- targetConfiguration.getConnections().shutdownConnection(conn);
+ if (state != ProtocolState.CLOSED) {
+ TargetContext.updateState(conn, ProtocolState.CLOSED);
+ targetConfiguration.getConnections().shutdownConnection(conn);
+ }
}
public void exception(NHttpClientConnection conn, IOException e) {
@@ -450,7 +446,40 @@ public class TargetHandler implements NH
}
public void endOfInput(NHttpClientConnection conn) throws IOException {
- closed(conn);
+ ProtocolState state = TargetContext.getState(conn);
+ boolean sendFault = false;
+
+ if (state == ProtocolState.REQUEST_READY || state ==
ProtocolState.RESPONSE_DONE) {
+ if (log.isDebugEnabled()) {
+ log.debug("Keep-Alive Connection closed by the target host");
+ }
+ } else if (state == ProtocolState.REQUEST_HEAD || state ==
ProtocolState.REQUEST_BODY) {
+ informWriterError(conn);
+ log.warn("Connection closed by the target host while sending the
request");
+ sendFault = true;
+ } else if (state == ProtocolState.RESPONSE_HEAD || state ==
ProtocolState.RESPONSE_BODY) {
+ informReaderError(conn);
+ log.warn("Connection closed by the target host while receiving the
response");
+ sendFault = false;
+ } else if (state == ProtocolState.REQUEST_DONE) {
+ informWriterError(conn);
+ log.warn("Connection closed by the target host before receiving
the request");
+ sendFault = true;
+ }
+
+ if (sendFault) {
+ MessageContext requestMsgCtx =
TargetContext.get(conn).getRequestMsgCtx();
+ if (requestMsgCtx != null) {
+ targetErrorHandler.handleError(requestMsgCtx,
+ ErrorCodes.CONNECTION_CLOSED,
+ "Error in Sender",
+ null,
+ state);
+ }
+ }
+
+ TargetContext.updateState(conn, ProtocolState.CLOSED);
+ targetConfiguration.getConnections().shutdownConnection(conn);
}
public void exception(NHttpClientConnection conn, Exception e) {