Merge branch 'master' of ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project
This commit is contained in:
commit
b9fd07be77
|
@ -2,6 +2,8 @@ package org.eclipse.jetty.server.handler;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.net.SocketTimeoutException;
|
||||||
import java.nio.channels.ClosedChannelException;
|
import java.nio.channels.ClosedChannelException;
|
||||||
import java.nio.channels.SelectionKey;
|
import java.nio.channels.SelectionKey;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
|
@ -225,19 +227,32 @@ public class ConnectHandler extends HandlerWrapper
|
||||||
|
|
||||||
SocketChannel channel;
|
SocketChannel channel;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
channel = connectToServer(request, host, port);
|
channel = connectToServer(request,host,port);
|
||||||
}
|
}
|
||||||
catch ( IOException ioe )
|
catch (SocketException se)
|
||||||
{
|
{
|
||||||
LOG.info("ConnectHandler: " + ioe.getMessage());
|
LOG.info("ConnectHandler: " + se.getMessage());
|
||||||
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
response.setStatus(HttpServletResponse.SC_GATEWAY_TIMEOUT);
|
||||||
baseRequest.setHandled(true);
|
baseRequest.setHandled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
catch (SocketTimeoutException ste)
|
||||||
|
{
|
||||||
|
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
|
// Transfer unread data from old connection to new connection
|
||||||
// We need to copy the data to avoid races:
|
// We need to copy the data to avoid races:
|
||||||
// 1. when this unread data is written and the server replies before the clientToProxy
|
// 1. when this unread data is written and the server replies before the clientToProxy
|
||||||
|
@ -320,12 +335,7 @@ public class ConnectHandler extends HandlerWrapper
|
||||||
// may return null
|
// may return null
|
||||||
private SocketChannel connectToServer(HttpServletRequest request, String host, int port) throws IOException
|
private SocketChannel connectToServer(HttpServletRequest request, String host, int port) throws IOException
|
||||||
{
|
{
|
||||||
SocketChannel channel = connect(request, host, port);
|
SocketChannel channel = connect(request, host, port);
|
||||||
if ( channel == null )
|
|
||||||
{
|
|
||||||
throw new IOException("unable to connector to " + host + ":" + port);
|
|
||||||
}
|
|
||||||
|
|
||||||
channel.configureBlocking(false);
|
channel.configureBlocking(false);
|
||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
@ -342,6 +352,12 @@ public class ConnectHandler extends HandlerWrapper
|
||||||
protected SocketChannel connect(HttpServletRequest request, String host, int port) throws IOException
|
protected SocketChannel connect(HttpServletRequest request, String host, int port) throws IOException
|
||||||
{
|
{
|
||||||
SocketChannel channel = SocketChannel.open();
|
SocketChannel channel = SocketChannel.open();
|
||||||
|
|
||||||
|
if (channel == null)
|
||||||
|
{
|
||||||
|
throw new IOException("unable to connect to " + host + ":" + port);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Connect to remote server
|
// Connect to remote server
|
||||||
|
|
Loading…
Reference in New Issue