FileDocCategorySizeDatePackage
ProxyDiagnostics.javaAPI DocApache Ant 1.703655Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.util.java15

ProxyDiagnostics

public class ProxyDiagnostics extends Object
This class exists to create a string that tells diagnostics about the current state of proxy diagnostics. It does this in its toString operator. Java1.5+ is needed to compile this class; its interface is classic typeless Java.
since
Ant 1.7

Fields Summary
private String
destination
private URI
destURI
public static final String
DEFAULT_DESTINATION
{@value}
Constructors Summary
public ProxyDiagnostics(String destination)
create a diagnostics binding for a specific URI

param
destination dest to bind to
throws
BuildException if the URI is malformed.


                              
       
        this.destination = destination;
        try {
            this.destURI = new URI(destination);
        } catch (URISyntaxException e) {
            throw new BuildException(e);
        }
    
public ProxyDiagnostics()
create a proxy diagnostics tool bound to {@link #DEFAULT_DESTINATION}

        this(DEFAULT_DESTINATION);
    
Methods Summary
public java.lang.StringtoString()
Get the diagnostics for proxy information.

return
the information.

        ProxySelector selector = ProxySelector.getDefault();
        List list = selector.select(destURI);
        StringBuffer result = new StringBuffer();
        Iterator proxies = list.listIterator();
        while (proxies.hasNext()) {
            Proxy proxy = (Proxy) proxies.next();
            SocketAddress address = proxy.address();
            if (address == null) {
                result.append("Direct connection\n");
            } else {
                result.append(proxy.toString());
                if (address instanceof InetSocketAddress) {
                    InetSocketAddress ina = (InetSocketAddress) address;
                    result.append(' ");
                    result.append(ina.getHostName());
                    result.append(':");
                    result.append(ina.getPort());
                    if (ina.isUnresolved()) {
                        result.append(" [unresolved]");
                    } else {
                        InetAddress addr = ina.getAddress();
                        result.append(" [");
                        result.append(addr.getHostAddress());
                        result.append(']");
                    }
                }
                result.append('\n");
            }
        }
        return result.toString();