Top Description Inners Fields Constructors Methods
org.apache.tools.ant.taskdefs.optional.net

public Class SetProxy

extends Task
Class Inheritance
Imports
java.net.Authenticator, .PasswordAuthentication, java.util.Properties, org.apache.tools.ant.BuildException, .Project, .Task, org.apache.tools.ant.util.ProxySetup

Sets Java's web proxy properties, so that tasks and code run in the same JVM can have through-the-firewall access to remote web sites, and remote ftp sites. You can nominate an http and ftp proxy, or a socks server, reset the server settings, or do nothing at all.

Examples

<setproxy/>
do nothing
<setproxy proxyhost="firewall"/>
set the proxy to firewall:80
<setproxy proxyhost="firewall" proxyport="81"/>
set the proxy to firewall:81
<setproxy proxyhost=""/>
stop using the http proxy; don't change the socks settings
<setproxy socksproxyhost="socksy"/>
use socks via socksy:1080
<setproxy socksproxyhost=""/>
stop using the socks server.

You can set a username and password for http with the proxyHost and proxyPassword attributes. These can also be used against SOCKS5 servers.

Since
Ant 1.5
See Also
https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final int
private String
nonProxyHosts

list of non proxy hosts

protected String
proxyHost

proxy details

private String
proxyPassword

password for http only

protected int
proxyPort

name of proxy port

private String
proxyUser

user for http only

private static final int
private String
socksProxyHost

socks host.

private int
socksProxyPort

Socks proxy port.

Inherited from org.apache.tools.ant.Task:
targettaskNametaskTypewrapper

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
applyWebProxySettings()

if the proxy port and host settings are not null, then the settings get applied these settings last beyond the life of the object and apply to all network connections Relevant docs: buglist #4183340

public void
execute()

Overrides org.apache.tools.ant.Task.execute.

Does the work.
public void
setNonProxyHosts(String
lists of hosts to talk direct to
nonProxyHosts
)

A list of hosts to bypass the proxy on.

public void
setProxyHost(String
the new proxy hostname
hostname
)

the HTTP/ftp proxy host.

public void
setProxyPassword(String
password to go with the username
proxyPassword
)

Set the password for the proxy.

public void
setProxyPort(int
port number of the proxy
port
)

the HTTP/ftp proxy port number; default is 80

public void
setProxyUser(String
username
proxyUser
)

set the proxy user.

public void
setSocksProxyHost(String
The new SocksProxyHost value
host
)

The name of a Socks server.

public void
setSocksProxyPort(int
The new SocksProxyPort value
port
)

Set the ProxyPort for socks connections.

private void
traceSettingInfo()

list out what is going on

Inherited from org.apache.tools.ant.Task:
bindToOwnergetOwningTargetgetRuntimeConfigurableWrappergetTaskNamegetTaskTypegetWrapperhandleErrorFlushhandleErrorOutputhandleFlushhandleInputhandleOutputinitisInvalidloglogloglogmaybeConfigureperformreconfiguresetOwningTargetsetRuntimeConfigurableWrappersetTaskNamesetTaskType

Field Detail

HTTP_PORTback to summary
private static final int HTTP_PORT
nonProxyHostsback to summary
private String nonProxyHosts

list of non proxy hosts

proxyHostback to summary
protected String proxyHost

proxy details

proxyPasswordback to summary
private String proxyPassword

password for http only

proxyPortback to summary
protected int proxyPort

name of proxy port

proxyUserback to summary
private String proxyUser

user for http only

SOCKS_PORTback to summary
private static final int SOCKS_PORT
socksProxyHostback to summary
private String socksProxyHost

socks host.

socksProxyPortback to summary
private int socksProxyPort

Socks proxy port. Default is 1080.

Constructor Detail

SetProxyback to summary
public SetProxy()

Method Detail

applyWebProxySettingsback to summary
public void applyWebProxySettings()

if the proxy port and host settings are not null, then the settings get applied these settings last beyond the life of the object and apply to all network connections Relevant docs: buglist #4183340

executeback to summary
public void execute() throws BuildException

Overrides org.apache.tools.ant.Task.execute.

Does the work.

Annotations
@Override
Exceptions
BuildException:
thrown in unrecoverable error.
setNonProxyHostsback to summary
public void setNonProxyHosts(String nonProxyHosts)

A list of hosts to bypass the proxy on. These should be separated with the vertical bar character '|'. Only in Java 1.4 does ftp use this list. e.g. fozbot.corp.sun.com|*.eng.sun.com

Parameters
nonProxyHosts:String

lists of hosts to talk direct to

setProxyHostback to summary
public void setProxyHost(String hostname)

the HTTP/ftp proxy host. Set this to "" for the http proxy option to be disabled

Parameters
hostname:String

the new proxy hostname

setProxyPasswordback to summary
public void setProxyPassword(String proxyPassword)

Set the password for the proxy. Used only if the proxyUser is set.

Parameters
proxyPassword:String

password to go with the username

Since
Ant1.6
setProxyPortback to summary
public void setProxyPort(int port)

the HTTP/ftp proxy port number; default is 80

Parameters
port:int

port number of the proxy

setProxyUserback to summary
public void setProxyUser(String proxyUser)

set the proxy user. Probably requires a password to accompany this setting. Default=""

Parameters
proxyUser:String

username

Since
Ant1.6
setSocksProxyHostback to summary
public void setSocksProxyHost(String host)

The name of a Socks server. Set to "" to turn socks proxying off.

Parameters
host:String

The new SocksProxyHost value

setSocksProxyPortback to summary
public void setSocksProxyPort(int port)

Set the ProxyPort for socks connections. The default value is 1080

Parameters
port:int

The new SocksProxyPort value

traceSettingInfoback to summary
private void traceSettingInfo()

list out what is going on

org.apache.tools.ant.taskdefs.optional.net back to summary

private final Class SetProxy.ProxyAuth

extends Authenticator
Class Inheritance

Since
1.6.3

Field Summary

Modifier and TypeField and Description
private PasswordAuthentication

Constructor Summary

AccessConstructor and Description
private
ProxyAuth(String user, String pass)

Method Summary

Modifier and TypeMethod and Description
protected PasswordAuthentication
getPasswordAuthentication()

Overrides java.net.Authenticator.getPasswordAuthentication.

Called when password authorization is needed.
Inherited from java.net.Authenticator:
getDefaultgetRequestingHostgetRequestingPortgetRequestingPromptgetRequestingProtocolgetRequestingSchemegetRequestingSitegetRequestingURLgetRequestorTyperequestPasswordAuthenticationrequestPasswordAuthenticationrequestPasswordAuthenticationrequestPasswordAuthenticationrequestPasswordAuthenticationInstancesetDefault

Field Detail

authback to summary
private PasswordAuthentication auth

Constructor Detail

ProxyAuthback to summary
private ProxyAuth(String user, String pass)

Method Detail

getPasswordAuthenticationback to summary
protected PasswordAuthentication getPasswordAuthentication()

Overrides java.net.Authenticator.getPasswordAuthentication.

Doc from java.net.Authenticator.getPasswordAuthentication.

Called when password authorization is needed. Subclasses should override the default implementation, which returns null.

Returns:PasswordAuthentication

The PasswordAuthentication collected from the user, or null if none is provided.

Annotations
@Override