0

I want to set up nonProxyHosts through System properties.
I want all the HTTP URLS to be accessed directly except two URLS. For this, instead of configuring all the host names for nonProxyHosts, which is risky
Can I configure this through a regular expression which gives all URLS minus the URLS that are to be proxied.

Can my regex be something like this?

http.nonProxyHosts=[^*host1*]|[^*host2*]
5
  • between host1 and host2 which you use to pass in nonPoxyHost? any method to choose one? that part is little confusing for me Jul 12, 2013 at 13:06
  • Hi Jubin, I want both host1 and host to be proxied. and rest all http requests as non proxied. I have a complex application so that I cannot list all the http hosts in non proxy. So I am looking for a way where I can use a negation kind of thing in the non proxy hosts regular expression Jul 14, 2013 at 6:16
  • oh that mean you say you have all host in one string and you have to divide them separate Jul 15, 2013 at 4:40
  • Yes Jubin exactly. * would get all the hosts (correct me if I am wrong). And use a regular expression with negation to get a regex [all urls - specific host]. This is because my application makes http requests to many hosts and there is a chance that I may miss configuring them in the nonProxyHosts. So I am looking for this approach. Jul 15, 2013 at 6:54
  • Did this ever work?
    – badera
    Aug 22, 2019 at 18:53

1 Answer 1

1
protected Pattern createNonProxyPattern(String nonProxyHosts) {
        if (nonProxyHosts == null || nonProxyHosts.equals("")) return null;

        // "*.fedora-commons.org" -> ".*?\.fedora-commons\.org" 
        nonProxyHosts = nonProxyHosts.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*?");

        // a|b|*.c -> (a)|(b)|(.*?\.c)
        nonProxyHosts = "(" + nonProxyHosts.replaceAll("\\|", ")|(") + ")";

        try {
            return Pattern.compile(nonProxyHosts);

            //we don't want to bring down the whole server by misusing the nonProxy pattern
            //therefore the error is logged and the web client moves on.
        } catch (Exception e) {
            log
                    .error("Creating the nonProxyHosts pattern failed for http.nonProxyHosts="
                            + nonProxyHosts
                            + " with the following exception: "
                            + e);
            return null;
        }
    }

get full info/code from here
with this way you can get one nonproxy Pattern. For two you have to change return type of function to TRUE/FALSE and then it will go OK.

3
  • You can just use Pattern.quote()
    – fge
    Jul 12, 2013 at 13:06
  • The above code says that I have to pass the non proxy hosts as param to the constructor of the Class. But my requirement is that, all my requests should be non proxy except for two urls. So I am checking for a regex which gives [all hosts] - [one host] Something like *|[^*proxyhost*] Jul 12, 2013 at 13:26
  • this not necessary to pass param to class, with for loop OR while loop you can check one by one all your non proxy host which one you get right stop the process from that and use that.you have to use this method to find is itnonproxy or not. Jul 13, 2013 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.