Java http.NoProxyHosts的有效正则表达式
我想通过系统属性设置Java http.NoProxyHosts的有效正则表达式,java,regex,proxy,Java,Regex,Proxy,我想通过系统属性设置非ProxyHosts。 我希望除了两个URL之外,所有HTTP URL都可以直接访问。为此,不要为非ProxyHosts配置所有主机名,这是有风险的 我可以通过一个正则表达式来配置它吗?该正则表达式给出了所有URL减去要代理的URL 我的正则表达式可以是这样的吗 http.nonProxyHosts=[^*host1*]|[^*host2*] 从 用这种方法你可以得到一个非Proxy模式。对于两种情况,您必须将函数的返回类型更改为TRUE/FALSE,然后它就会正常运行
非ProxyHosts
。我希望除了两个URL之外,所有HTTP URL都可以直接访问。为此,不要为
非ProxyHosts
配置所有主机名,这是有风险的
我可以通过一个正则表达式来配置它吗?该正则表达式给出了所有URL减去要代理的URL
我的正则表达式可以是这样的吗
http.nonProxyHosts=[^*host1*]|[^*host2*]
从
用这种方法你可以得到一个非Proxy模式。对于两种情况,您必须将函数的返回类型更改为TRUE/FALSE
,然后它就会正常运行 在host1
和host2
之间,您使用它传递nonPoxyHost
?有什么方法可以选择吗?这一部分对meHi Jubin来说有点混乱,我希望host1和host都被代理。并将所有http请求作为非代理请求进行休息。我有一个复杂的应用程序,所以我无法在非代理中列出所有http主机。因此,我正在寻找一种方法,在非代理主机正则表达式中使用一种否定形式,这意味着你说你把所有主机都放在一个字符串中,你必须将它们精确地分开。*会得到所有的主人(如果我错了,请纠正我)。并使用一个带否定的正则表达式来获取regex[所有特定于URL的主机]。这是因为我的应用程序向许多主机发出http请求,我可能会错过在非Proxy主机中配置它们的机会。因此,我正在寻找这种方法。这种方法有效吗?您可以使用Pattern.quote()
上面的代码说,我必须将非代理主机作为参数传递给类的构造函数。但我的要求是,除了两个URL之外,我的所有请求都应该是非代理的。因此,我正在检查一个正则表达式,它提供[所有主机]-[一个主机]类似于*|[^*proxyhost*]
的内容,这对于将参数传递给类来说是不必要的,使用for
循环或while
循环,您可以逐个检查您的非代理主机
哪一个是正确的,停止该进程并使用它。您必须使用此方法来查找是否为非代理主机
。
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;
}
}