Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Add support for nonProxyHosts #1203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public Options() {
// Proxy setting.
private String proxyHost = null;
private String proxyPort = null;
private String nonProxyHosts = null;
public String proxyAuth = null;

/**
Expand Down Expand Up @@ -681,6 +682,10 @@ public int parseArgument(String[] args, int i) throws BadCommandLineException {
proxyPort = requireArgument("-port", args, ++i);
return 2;
}
if (args[i].equals("-nonProxyHosts")){
nonProxyHosts = requireArgument("-nonProxyHosts", args, ++i);
return 2;
}
if (args[i].equals("-catalog")) {
// use Sun's "XML Entity and URI Resolvers" by Norman Walsh
// to resolve external entities.
Expand Down Expand Up @@ -884,6 +889,9 @@ public void parseArguments(String[] args) throws BadCommandLineException {
if (proxyAuth != null) {
DefaultAuthenticator.getAuthenticator().setProxyAuth(proxyAuth);
}
if(nonProxyHosts != null){
System.setProperty("http.nonProxyHosts", nonProxyHosts);
}
}

if (grammars.isEmpty())
Expand Down
19 changes: 19 additions & 0 deletions jaxb-ri/xjc/src/test/java/com/sun/tools/xjc/OptionsJUTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public void testProxySettings() throws Exception {
opts.parseArguments(new String[]{"-httpproxy", "www.proxy", grammar.getAbsolutePath()});
assertEquals("www.proxy", getField("proxyHost", opts));
assertEquals("80", getField("proxyPort", opts));
assertNull(getField("nonProxyHosts", opts));
assertNull(opts.proxyAuth);
} catch (BadCommandLineException ex) {
Logger.getLogger(OptionsJUTest.class.getName()).log(Level.SEVERE, null, ex);
Expand All @@ -151,6 +152,22 @@ public void testProxySettings() throws Exception {
opts.parseArguments(new String[]{"-httpproxy", "www.proxy1:4321", grammar.getAbsolutePath()});
assertEquals("www.proxy1", getField("proxyHost", opts));
assertEquals("4321", getField("proxyPort", opts));
assertNull(getField("nonProxyHosts", opts));
assertNull(opts.proxyAuth);
} catch (BadCommandLineException ex) {
Logger.getLogger(OptionsJUTest.class.getName()).log(Level.SEVERE, null, ex);
fail();
} finally {
if (opts.proxyAuth != null) {
DefaultAuthenticator.reset();
}
}
opts = new Options();
try {
opts.parseArguments(new String[]{"-httpproxy", "www.proxy2:4321", "-nonProxyHosts", "localhost|*.example.com", grammar.getAbsolutePath()});
assertEquals("www.proxy2", getField("proxyHost", opts));
assertEquals("4321", getField("proxyPort", opts));
assertEquals("localhost|*.example.com",getField("nonProxyHosts", opts));
assertNull(opts.proxyAuth);
} catch (BadCommandLineException ex) {
Logger.getLogger(OptionsJUTest.class.getName()).log(Level.SEVERE, null, ex);
Expand All @@ -165,6 +182,7 @@ public void testProxySettings() throws Exception {
opts.parseArguments(new String[]{"-httpproxy", "user:pwd@www.proxy3:7890", grammar.getAbsolutePath()});
assertEquals("www.proxy3", getField("proxyHost", opts));
assertEquals("7890", getField("proxyPort", opts));
assertNull(getField("nonProxyHosts", opts));
assertEquals("user:pwd", opts.proxyAuth);
} catch (BadCommandLineException ex) {
Logger.getLogger(OptionsJUTest.class.getName()).log(Level.SEVERE, null, ex);
Expand All @@ -179,6 +197,7 @@ public void testProxySettings() throws Exception {
opts.parseArguments(new String[]{"-httpproxy", "duke:s@cr@t@proxy98", grammar.getAbsolutePath()});
assertEquals("proxy98", getField("proxyHost", opts));
assertEquals("80", getField("proxyPort", opts));
assertNull(getField("nonProxyHosts", opts));
assertEquals("duke:s@cr@t", opts.proxyAuth);
} catch (BadCommandLineException ex) {
Logger.getLogger(OptionsJUTest.class.getName()).log(Level.SEVERE, null, ex);
Expand Down