[Bug 383251] socket timeout exception returns 504, ioexception returns 500 in connector handler
This commit is contained in:
parent
82a02c578c
commit
9ddd3e5e04
|
@ -2,6 +2,7 @@ package org.eclipse.jetty.server.handler;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
@ -227,16 +228,22 @@ public class ConnectHandler extends HandlerWrapper
|
|||
|
||||
try
|
||||
{
|
||||
channel = connectToServer(request, host, port);
|
||||
channel = connectToServer(request,host,port);
|
||||
}
|
||||
catch ( IOException ioe )
|
||||
catch (SocketTimeoutException ste)
|
||||
{
|
||||
LOG.info("ConnectHandler: " + ioe.getMessage());
|
||||
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
baseRequest.setHandled(true);
|
||||
LOG.info("ConnectHandler: " + ste.getMessage());
|
||||
response.setStatus(HttpServletResponse.SC_GATEWAY_TIMEOUT);
|
||||
baseRequest.setHandled(true);
|
||||
return;
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
LOG.info("ConnectHandler: " + ioe.getMessage());
|
||||
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
baseRequest.setHandled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Transfer unread data from old connection to new connection
|
||||
// We need to copy the data to avoid races:
|
||||
|
@ -321,11 +328,6 @@ public class ConnectHandler extends HandlerWrapper
|
|||
private SocketChannel connectToServer(HttpServletRequest request, String host, int port) throws IOException
|
||||
{
|
||||
SocketChannel channel = connect(request, host, port);
|
||||
if ( channel == null )
|
||||
{
|
||||
throw new IOException("unable to connector to " + host + ":" + port);
|
||||
}
|
||||
|
||||
channel.configureBlocking(false);
|
||||
return channel;
|
||||
}
|
||||
|
@ -342,6 +344,12 @@ public class ConnectHandler extends HandlerWrapper
|
|||
protected SocketChannel connect(HttpServletRequest request, String host, int port) throws IOException
|
||||
{
|
||||
SocketChannel channel = SocketChannel.open();
|
||||
|
||||
if (channel == null)
|
||||
{
|
||||
throw new IOException("unable to connect to " + host + ":" + port);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Connect to remote server
|
||||
|
|
Loading…
Reference in New Issue