IDEA-91436

This commit is contained in:
Vladimir Krivosheev
2012-10-09 18:11:05 +04:00
parent aae31b45a5
commit ff789de44c
@@ -13,7 +13,9 @@ import org.jboss.netty.channel.group.DefaultChannelGroup;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
import org.jboss.netty.handler.codec.http.*;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.List;
import java.util.concurrent.Executor;
@@ -64,10 +66,26 @@ public class WebServer {
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setPipelineFactory(new ChannelPipelineFactoryImpl(pipelineConsumers, new DefaultHandler(openChannels)));
// IDEA-91436 idea <121 binds to 127.0.0.1, but >=121 must be available not only from localhost
// but if we bind only to any local port (0.0.0.0), instance of idea <121 can bind to our ports and any request to us will be intercepted
// so, we bind to 127.0.0.1 and 0.0.0.0
int port = bind(firstPort, portsCount, tryAnyPort, bootstrap);
if (port != -1) {
try {
openChannels.add(bootstrap.bind(new InetSocketAddress(port)));
}
catch (ChannelException e) {
LOG.error(e);
}
}
return port;
}
private int bind(int firstPort, int portsCount, boolean tryAnyPort, ServerBootstrap bootstrap) {
for (int i = 0; i < portsCount; i++) {
int port = firstPort + i;
try {
openChannels.add(bootstrap.bind(new InetSocketAddress(port)));
openChannels.add(bootstrap.bind(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), port)));
return port;
}
catch (ChannelException e) {
@@ -78,6 +96,9 @@ public class WebServer {
LOG.error(e);
}
}
catch (UnknownHostException e) {
LOG.error(e);
}
}
if (tryAnyPort) {