You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2011/08/12 13:28:29 UTC
svn commit: r1157055 - in
/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio:
DefaultClientIOEventDispatch.java DefaultServerIOEventDispatch.java
ssl/SSLClientIOEventDispatch.java ssl/SSLServerIOEventDispatch.java
Author: olegk
Date: Fri Aug 12 11:28:28 2011
New Revision: 1157055
URL: http://svn.apache.org/viewvc?rev=1157055&view=rev
Log:
I/O event dispatchers to shut down the I/O session in case of a runtime exception
Modified:
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIOEventDispatch.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIOEventDispatch.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLClientIOEventDispatch.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLServerIOEventDispatch.java
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIOEventDispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIOEventDispatch.java?rev=1157055&r1=1157054&r2=1157055&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIOEventDispatch.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIOEventDispatch.java Fri Aug 12 11:28:28 2011
@@ -122,23 +122,33 @@ public class DefaultClientIOEventDispatc
* @return newly created HTTP connection.
*/
protected NHttpClientIOTarget createConnection(final IOSession session) {
- return new DefaultNHttpClientConnection(
- session,
- createHttpResponseFactory(),
- this.allocator,
- this.params);
+ try {
+ return new DefaultNHttpClientConnection(
+ session,
+ createHttpResponseFactory(),
+ this.allocator,
+ this.params);
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
public void connected(final IOSession session) {
- NHttpClientIOTarget conn = createConnection(session);
- Object attachment = session.getAttribute(IOSession.ATTACHMENT_KEY);
- session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
- this.handler.connected(conn, attachment);
+ try {
+ NHttpClientIOTarget conn = createConnection(session);
+ Object attachment = session.getAttribute(IOSession.ATTACHMENT_KEY);
+ session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+ this.handler.connected(conn, attachment);
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
public void disconnected(final IOSession session) {
- NHttpClientIOTarget conn =
- (NHttpClientIOTarget) session.getAttribute(ExecutionContext.HTTP_CONNECTION);
+ NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
+ ExecutionContext.HTTP_CONNECTION);
if (conn != null) {
this.handler.closed(conn);
}
@@ -151,24 +161,39 @@ public class DefaultClientIOEventDispatc
}
public void inputReady(final IOSession session) {
- NHttpClientIOTarget conn =
- (NHttpClientIOTarget) session.getAttribute(ExecutionContext.HTTP_CONNECTION);
- ensureNotNull(conn);
- conn.consumeInput(this.handler);
+ try {
+ NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
+ ExecutionContext.HTTP_CONNECTION);
+ ensureNotNull(conn);
+ conn.consumeInput(this.handler);
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
public void outputReady(final IOSession session) {
- NHttpClientIOTarget conn =
- (NHttpClientIOTarget) session.getAttribute(ExecutionContext.HTTP_CONNECTION);
- ensureNotNull(conn);
- conn.produceOutput(this.handler);
+ try {
+ NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
+ ExecutionContext.HTTP_CONNECTION);
+ ensureNotNull(conn);
+ conn.produceOutput(this.handler);
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
public void timeout(final IOSession session) {
- NHttpClientIOTarget conn =
- (NHttpClientIOTarget) session.getAttribute(ExecutionContext.HTTP_CONNECTION);
- ensureNotNull(conn);
- this.handler.timeout(conn);
+ try {
+ NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
+ ExecutionContext.HTTP_CONNECTION);
+ ensureNotNull(conn);
+ this.handler.timeout(conn);
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIOEventDispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIOEventDispatch.java?rev=1157055&r1=1157054&r2=1157055&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIOEventDispatch.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIOEventDispatch.java Fri Aug 12 11:28:28 2011
@@ -130,14 +130,19 @@ public class DefaultServerIOEventDispatc
}
public void connected(final IOSession session) {
- NHttpServerIOTarget conn = createConnection(session);
- session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
- this.handler.connected(conn);
+ try {
+ NHttpServerIOTarget conn = createConnection(session);
+ session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+ this.handler.connected(conn);
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
public void disconnected(final IOSession session) {
- NHttpServerIOTarget conn =
- (NHttpServerIOTarget) session.getAttribute(ExecutionContext.HTTP_CONNECTION);
+ NHttpServerIOTarget conn = (NHttpServerIOTarget) session.getAttribute(
+ ExecutionContext.HTTP_CONNECTION);
if (conn != null) {
this.handler.closed(conn);
}
@@ -150,24 +155,39 @@ public class DefaultServerIOEventDispatc
}
public void inputReady(final IOSession session) {
- NHttpServerIOTarget conn =
- (NHttpServerIOTarget) session.getAttribute(ExecutionContext.HTTP_CONNECTION);
- ensureNotNull(conn);
- conn.consumeInput(this.handler);
+ try {
+ NHttpServerIOTarget conn = (NHttpServerIOTarget) session.getAttribute(
+ ExecutionContext.HTTP_CONNECTION);
+ ensureNotNull(conn);
+ conn.consumeInput(this.handler);
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
public void outputReady(final IOSession session) {
- NHttpServerIOTarget conn =
- (NHttpServerIOTarget) session.getAttribute(ExecutionContext.HTTP_CONNECTION);
- ensureNotNull(conn);
- conn.produceOutput(this.handler);
+ try {
+ NHttpServerIOTarget conn = (NHttpServerIOTarget) session.getAttribute(
+ ExecutionContext.HTTP_CONNECTION);
+ ensureNotNull(conn);
+ conn.produceOutput(this.handler);
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
public void timeout(final IOSession session) {
- NHttpServerIOTarget conn =
- (NHttpServerIOTarget) session.getAttribute(ExecutionContext.HTTP_CONNECTION);
- ensureNotNull(conn);
- this.handler.timeout(conn);
+ try {
+ NHttpServerIOTarget conn = (NHttpServerIOTarget) session.getAttribute(
+ ExecutionContext.HTTP_CONNECTION);
+ ensureNotNull(conn);
+ this.handler.timeout(conn);
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLClientIOEventDispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLClientIOEventDispatch.java?rev=1157055&r1=1157054&r2=1157055&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLClientIOEventDispatch.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLClientIOEventDispatch.java Fri Aug 12 11:28:28 2011
@@ -188,32 +188,36 @@ public class SSLClientIOEventDispatch im
}
public void connected(final IOSession session) {
-
- SSLIOSession sslSession = createSSLIOSession(
- session,
- this.sslcontext,
- this.sslHandler);
-
- NHttpClientIOTarget conn = createConnection(
- sslSession);
-
- session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
- session.setAttribute(SSL_SESSION, sslSession);
-
- Object attachment = session.getAttribute(IOSession.ATTACHMENT_KEY);
- this.handler.connected(conn, attachment);
-
- try {
- sslSession.bind(SSLMode.CLIENT, this.params);
- } catch (SSLException ex) {
- this.handler.exception(conn, ex);
- sslSession.shutdown();
- }
+ try {
+ SSLIOSession sslSession = createSSLIOSession(
+ session,
+ this.sslcontext,
+ this.sslHandler);
+
+ NHttpClientIOTarget conn = createConnection(
+ sslSession);
+
+ session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+ session.setAttribute(SSL_SESSION, sslSession);
+
+ Object attachment = session.getAttribute(IOSession.ATTACHMENT_KEY);
+ this.handler.connected(conn, attachment);
+
+ try {
+ sslSession.bind(SSLMode.CLIENT, this.params);
+ } catch (SSLException ex) {
+ this.handler.exception(conn, ex);
+ sslSession.shutdown();
+ }
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
public void disconnected(final IOSession session) {
- NHttpClientIOTarget conn =
- (NHttpClientIOTarget) session.getAttribute(ExecutionContext.HTTP_CONNECTION);
+ NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
+ ExecutionContext.HTTP_CONNECTION);
if (conn != null) {
this.handler.closed(conn);
}
@@ -232,58 +236,73 @@ public class SSLClientIOEventDispatch im
}
public void inputReady(final IOSession session) {
- NHttpClientIOTarget conn =
- (NHttpClientIOTarget) session.getAttribute(ExecutionContext.HTTP_CONNECTION);
- ensureNotNull(conn);
- SSLIOSession sslSession =
- (SSLIOSession) session.getAttribute(SSL_SESSION);
- ensureNotNull(sslSession);
-
- try {
- if (sslSession.isAppInputReady()) {
- conn.consumeInput(this.handler);
+ try {
+ NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
+ ExecutionContext.HTTP_CONNECTION);
+ ensureNotNull(conn);
+ SSLIOSession sslSession =
+ (SSLIOSession) session.getAttribute(SSL_SESSION);
+ ensureNotNull(sslSession);
+
+ try {
+ if (sslSession.isAppInputReady()) {
+ conn.consumeInput(this.handler);
+ }
+ sslSession.inboundTransport();
+ } catch (IOException ex) {
+ this.handler.exception(conn, ex);
+ sslSession.shutdown();
}
- sslSession.inboundTransport();
- } catch (IOException ex) {
- this.handler.exception(conn, ex);
- sslSession.shutdown();
- }
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
public void outputReady(final IOSession session) {
- NHttpClientIOTarget conn =
- (NHttpClientIOTarget) session.getAttribute(ExecutionContext.HTTP_CONNECTION);
- ensureNotNull(conn);
- SSLIOSession sslSession =
- (SSLIOSession) session.getAttribute(SSL_SESSION);
- ensureNotNull(sslSession);
-
- try {
- if (sslSession.isAppOutputReady()) {
- conn.produceOutput(this.handler);
+ try {
+ NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
+ ExecutionContext.HTTP_CONNECTION);
+ ensureNotNull(conn);
+ SSLIOSession sslSession =
+ (SSLIOSession) session.getAttribute(SSL_SESSION);
+ ensureNotNull(sslSession);
+
+ try {
+ if (sslSession.isAppOutputReady()) {
+ conn.produceOutput(this.handler);
+ }
+ sslSession.outboundTransport();
+ } catch (IOException ex) {
+ this.handler.exception(conn, ex);
+ sslSession.shutdown();
}
- sslSession.outboundTransport();
- } catch (IOException ex) {
- this.handler.exception(conn, ex);
- sslSession.shutdown();
- }
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
public void timeout(final IOSession session) {
- NHttpClientIOTarget conn =
- (NHttpClientIOTarget) session.getAttribute(ExecutionContext.HTTP_CONNECTION);
- ensureNotNull(conn);
- SSLIOSession sslSession =
- (SSLIOSession) session.getAttribute(SSL_SESSION);
- ensureNotNull(sslSession);
-
- this.handler.timeout(conn);
- synchronized (sslSession) {
- if (sslSession.isOutboundDone() && !sslSession.isInboundDone()) {
- // The session failed to terminate cleanly
- sslSession.shutdown();
- }
- }
+ try {
+ NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
+ ExecutionContext.HTTP_CONNECTION);
+ ensureNotNull(conn);
+ SSLIOSession sslSession =
+ (SSLIOSession) session.getAttribute(SSL_SESSION);
+ ensureNotNull(sslSession);
+
+ this.handler.timeout(conn);
+ synchronized (sslSession) {
+ if (sslSession.isOutboundDone() && !sslSession.isInboundDone()) {
+ // The session failed to terminate cleanly
+ sslSession.shutdown();
+ }
+ }
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLServerIOEventDispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLServerIOEventDispatch.java?rev=1157055&r1=1157054&r2=1157055&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLServerIOEventDispatch.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLServerIOEventDispatch.java Fri Aug 12 11:28:28 2011
@@ -188,32 +188,35 @@ public class SSLServerIOEventDispatch im
}
public void connected(final IOSession session) {
-
- SSLIOSession sslSession = createSSLIOSession(
- session,
- this.sslcontext,
- this.sslHandler);
-
- NHttpServerIOTarget conn = createConnection(
- sslSession);
-
- session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
- session.setAttribute(SSL_SESSION, sslSession);
-
- this.handler.connected(conn);
-
- try {
- sslSession.bind(SSLMode.SERVER, this.params);
- } catch (SSLException ex) {
- this.handler.exception(conn, ex);
- sslSession.shutdown();
- }
+ try {
+ SSLIOSession sslSession = createSSLIOSession(
+ session,
+ this.sslcontext,
+ this.sslHandler);
+
+ NHttpServerIOTarget conn = createConnection(
+ sslSession);
+
+ session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+ session.setAttribute(SSL_SESSION, sslSession);
+
+ this.handler.connected(conn);
+
+ try {
+ sslSession.bind(SSLMode.SERVER, this.params);
+ } catch (SSLException ex) {
+ this.handler.exception(conn, ex);
+ sslSession.shutdown();
+ }
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
public void disconnected(final IOSession session) {
- NHttpServerIOTarget conn =
- (NHttpServerIOTarget) session.getAttribute(ExecutionContext.HTTP_CONNECTION);
-
+ NHttpServerIOTarget conn = (NHttpServerIOTarget) session.getAttribute(
+ ExecutionContext.HTTP_CONNECTION);
if (conn != null) {
this.handler.closed(conn);
}
@@ -232,58 +235,73 @@ public class SSLServerIOEventDispatch im
}
public void inputReady(final IOSession session) {
- NHttpServerIOTarget conn =
- (NHttpServerIOTarget) session.getAttribute(ExecutionContext.HTTP_CONNECTION);
- ensureNotNull(conn);
- SSLIOSession sslSession =
- (SSLIOSession) session.getAttribute(SSL_SESSION);
- ensureNotNull(sslSession);
-
- try {
- if (sslSession.isAppInputReady()) {
- conn.consumeInput(this.handler);
+ try {
+ NHttpServerIOTarget conn = (NHttpServerIOTarget) session.getAttribute(
+ ExecutionContext.HTTP_CONNECTION);
+ ensureNotNull(conn);
+ SSLIOSession sslSession =
+ (SSLIOSession) session.getAttribute(SSL_SESSION);
+ ensureNotNull(sslSession);
+
+ try {
+ if (sslSession.isAppInputReady()) {
+ conn.consumeInput(this.handler);
+ }
+ sslSession.inboundTransport();
+ } catch (IOException ex) {
+ this.handler.exception(conn, ex);
+ sslSession.shutdown();
}
- sslSession.inboundTransport();
- } catch (IOException ex) {
- this.handler.exception(conn, ex);
- sslSession.shutdown();
- }
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
public void outputReady(final IOSession session) {
- NHttpServerIOTarget conn =
- (NHttpServerIOTarget) session.getAttribute(ExecutionContext.HTTP_CONNECTION);
- ensureNotNull(conn);
- SSLIOSession sslSession =
- (SSLIOSession) session.getAttribute(SSL_SESSION);
- ensureNotNull(sslSession);
-
- try {
- if (sslSession.isAppOutputReady()) {
- conn.produceOutput(this.handler);
+ try {
+ NHttpServerIOTarget conn = (NHttpServerIOTarget) session.getAttribute(
+ ExecutionContext.HTTP_CONNECTION);
+ ensureNotNull(conn);
+ SSLIOSession sslSession =
+ (SSLIOSession) session.getAttribute(SSL_SESSION);
+ ensureNotNull(sslSession);
+
+ try {
+ if (sslSession.isAppOutputReady()) {
+ conn.produceOutput(this.handler);
+ }
+ sslSession.outboundTransport();
+ } catch (IOException ex) {
+ this.handler.exception(conn, ex);
+ sslSession.shutdown();
}
- sslSession.outboundTransport();
- } catch (IOException ex) {
- this.handler.exception(conn, ex);
- sslSession.shutdown();
- }
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
public void timeout(final IOSession session) {
- NHttpServerIOTarget conn =
- (NHttpServerIOTarget) session.getAttribute(ExecutionContext.HTTP_CONNECTION);
- ensureNotNull(conn);
- SSLIOSession sslSession =
- (SSLIOSession) session.getAttribute(SSL_SESSION);
- ensureNotNull(sslSession);
-
- this.handler.timeout(conn);
- synchronized (sslSession) {
- if (sslSession.isOutboundDone() && !sslSession.isInboundDone()) {
- // The session failed to cleanly terminate
- sslSession.shutdown();
+ try {
+ NHttpServerIOTarget conn = (NHttpServerIOTarget) session.getAttribute(
+ ExecutionContext.HTTP_CONNECTION);
+ ensureNotNull(conn);
+ SSLIOSession sslSession =
+ (SSLIOSession) session.getAttribute(SSL_SESSION);
+ ensureNotNull(sslSession);
+
+ this.handler.timeout(conn);
+ synchronized (sslSession) {
+ if (sslSession.isOutboundDone() && !sslSession.isInboundDone()) {
+ // The session failed to cleanly terminate
+ sslSession.shutdown();
+ }
}
- }
+ } catch (RuntimeException ex) {
+ session.shutdown();
+ throw ex;
+ }
}
}