Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option http.nonProxyHosts is not taken into consideration #390

Closed
cjmachado opened this issue Feb 26, 2016 · 3 comments
Closed

Option http.nonProxyHosts is not taken into consideration #390

cjmachado opened this issue Feb 26, 2016 · 3 comments

Comments

@cjmachado
Copy link

Hi,

Our company runs tests for in-house applications located both in our intranet and internet. We have a proxy to access the internet, so the big picture is:

BMP
|----- Intranet App? -----> App Server (direct connection)
|----- Internet App? -----> Corporate Proxy ------> App Server

So, I must be able to specify that all intranet app servers should bypass our corporate proxy (in this example, it's on 192.168.0.0 network). I'm launching browsermob-proxy in the command line using the provided script with the following options (consider that our corporate proxy has IP 192.168.1.1 and it's listening on port 80):

JAVA_OPTS="-Dhttp.proxyHost=192.168.1.1 -Dhttps.proxyHost=192.168.1.1 -Dhttp.nonProxyHosts="localhost|127.0.0.|192.168.0." ./browsermob-proxy -proxyPortRange '8081-8085'

If I point the browser to a port between 8081 and 8085, it's possible to reach the Internet Apps, but not the Intranet Apps. It seems that the proxyHost options are taken into consideration, but the nonProxyHosts is not.
I tried specifying -Djava.net.useSystemProxies=true but it also didn't work (we use RedHat 6.7).

Actually, we are trying to run browsermob as a service, so I'm sharing the init.d script that we use.
browsermob-proxy.txt

Thanks in advance for any help.

@cjmachado
Copy link
Author

I'm trying to workaround this for myself but it's been a struggle. I tried to create a BrowserMobProxyServer and set a ChainedProxyManager, but it's not working either. Here's the code I'm using for the ChainedProxyManager:

`public class DefaultChainedProxyManager implements ChainedProxyManager {

private static final Logger LOGGER = Logger.getLogger(DefaultChainedProxyManager.class.getName());

private final ProxySelector selector;

public DefaultChainedProxyManager() {
    this.selector = ProxySelector.getDefault();
}

@Override
public void lookupChainedProxies(final HttpRequest hr, final Queue<ChainedProxy> queue) {
    try {
        final URI uri = new URI(hr.getUri());
        final List<Proxy> proxies = selector.select(uri);
        if (proxies.size() > 0) {
            final Proxy firstProxy = proxies.get(0);
            if (firstProxy.type() == Proxy.Type.DIRECT) {
                queue.offer(ChainedProxyAdapter.FALLBACK_TO_DIRECT_CONNECTION);
            } else {
                for (final Proxy proxy : proxies) {
                    queue.offer(new ProxyAdapter(proxy));
                }                    
            }
        }
    } catch (URISyntaxException ex) {
        LOGGER.log(Level.WARNING, String.format("Failed to parse the following uri: %s. Using direct connection.", hr.getUri()), ex);
        queue.offer(ChainedProxyAdapter.FALLBACK_TO_DIRECT_CONNECTION);
    }
}

static final class ProxyAdapter extends ChainedProxyAdapter {

    private final InetSocketAddress address;

    public ProxyAdapter(final Proxy proxy) {
        address = (InetSocketAddress) proxy.address();
        LOGGER.log(Level.INFO, "Using proxy with address {0}", address);            
    }

    @Override
    public InetSocketAddress getChainedProxyAddress() {
        return address;
    }

    @Override
    public void connectionSucceeded() {
        LOGGER.log(Level.INFO, "Connection succeeded to {0}", address);
    }

    @Override
    public void connectionFailed(Throwable cause) {
        LOGGER.log(Level.INFO, String.format("Connection failed to %s", address), cause);
    }

    @Override
    public void disconnected() {
        LOGGER.log(Level.INFO, "Disconnected from {0}", address);
    }
}

}`
And this is the main code that launches the BrowserMobProxyServer:

public class Main { public static void main(String[] args) { BrowserMobProxyServer server = new BrowserMobProxyServer(); server.setChainedProxyManager(new DefaultChainedProxyManager()); server.setTrustAllServers(true); server.start(5564); } }

I run the server like this:

java -Dhttp.proxyHost=192.168.0.1 -Dhttp.proxyPort=80 -Dhttps.proxyHost=192.168.0.1 -Dhttps.proxyHost=80 -Dhttp.nonProxyHosts="localhost|127.0.0.*|192.168.1.*" -jar browsermob-chained.jar

And whenever the the outgoing proxy is chosen I get this exception:
`
Feb 28, 2016 9:24:34 PM DefaultChainedProxyManager$ProxyAdapter
INFO: Using proxy with address 192.168.0.1:80
Feb 28, 2016 9:24:34 PM DefaultChainedProxyManager$ProxyAdapter connectionFailed
INFO: Connection failed to 192.168.0.1:8080
java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Net.java:107)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:649)
at io.netty.channel.socket.nio.NioSocketChannel.doConnect(NioSocketChannel.java:209)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.connect(AbstractNioChannel.java:207)
at io.netty.channel.DefaultChannelPipeline$HeadContext.connect(DefaultChannelPipeline.java:1097)
at io.netty.channel.AbstractChannelHandlerContext.invokeConnect(AbstractChannelHandlerContext.java:481)
at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:466)
at io.netty.channel.ChannelOutboundHandlerAdapter.connect(ChannelOutboundHandlerAdapter.java:47)
at io.netty.channel.AbstractChannelHandlerContext.invokeConnect(AbstractChannelHandlerContext.java:481)
at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:466)
at io.netty.channel.ChannelOutboundHandlerAdapter.connect(ChannelOutboundHandlerAdapter.java:47)
at io.netty.channel.AbstractChannelHandlerContext.invokeConnect(AbstractChannelHandlerContext.java:481)
at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:466)
at io.netty.channel.ChannelOutboundHandlerAdapter.connect(ChannelOutboundHandlerAdapter.java:47)
at io.netty.channel.AbstractChannelHandlerContext.invokeConnect(AbstractChannelHandlerContext.java:481)
at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:466)
at io.netty.channel.ChannelDuplexHandler.connect(ChannelDuplexHandler.java:50)
at io.netty.channel.AbstractChannelHandlerContext.invokeConnect(AbstractChannelHandlerContext.java:481)
at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:466)
at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:448)
at io.netty.channel.DefaultChannelPipeline.connect(DefaultChannelPipeline.java:908)
at io.netty.channel.AbstractChannel.connect(AbstractChannel.java:203)
at io.netty.bootstrap.Bootstrap$2.run(Bootstrap.java:166)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:358)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
at java.lang.Thread.run(Thread.java:745)

`

@jekh
Copy link
Collaborator

jekh commented Apr 2, 2016

I'm not sure where the http.nonProxyHosts option is coming from, but neither BMP nor LP have any knowledge of it. Perhaps you're thinking of the browser's option to skip the proxy for specified hostnames?

@jekh jekh closed this as completed Apr 2, 2016
@jun1983
Copy link

jun1983 commented Jun 4, 2018

@cjmachado hi mate, sorry for leave a message after 2 years time. I am facing the same issue, do you any workaround or substitute tool suggestion? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants