Improved exception handling during connect to remote server.

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2942 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Simone Bordet 2011-03-31 14:33:11 +00:00
parent f7a0d7d134
commit 215bf562aa
1 changed files with 22 additions and 6 deletions

View File

@ -329,13 +329,29 @@ public class ConnectHandler extends HandlerWrapper
*/
protected SocketChannel connect(HttpServletRequest request, String host, int port) throws IOException
{
_logger.debug("Establishing connection to {}:{}", host, port);
// Connect to remote server
SocketChannel channel = SocketChannel.open();
channel.socket().setTcpNoDelay(true);
channel.socket().connect(new InetSocketAddress(host, port), getConnectTimeout());
_logger.debug("Established connection to {}:{}", host, port);
return channel;
try
{
// Connect to remote server
_logger.debug("Establishing connection to {}:{}", host, port);
channel.socket().setTcpNoDelay(true);
channel.socket().connect(new InetSocketAddress(host, port), getConnectTimeout());
_logger.debug("Established connection to {}:{}", host, port);
return channel;
}
catch (IOException x)
{
_logger.debug("Failed to establish connection to " + host + ":" + port, x);
try
{
channel.close();
}
catch (IOException xx)
{
Log.ignore(xx);
}
throw x;
}
}
protected void prepareContext(HttpServletRequest request, ConcurrentMap<String, Object> context)