Examples of ProxyHost


Examples of org.apache.commons.httpclient.ProxyHost

     *
     * @param sampleURL the URL to check proxy settings for
     * @return ProxyHost the host and port of the proxy that should be used
     */
    private static ProxyHost detectProxySettingsJDK14_JDK15_JDK16(URL sampleURL) {
        ProxyHost result = null;
        try {
            // Look around for the 1.4+ plugin proxy detection class...
            // Without it, cannot autodetect...
            Class ProxyServiceClass =
                Class.forName("com.sun.java.browser.net.ProxyService");
            Method getProxyInfoMethod =
                ProxyServiceClass.getDeclaredMethod("getProxyInfo",
                                                    new Class[] {URL.class});
            Object proxyInfoArrayObj =
                getProxyInfoMethod.invoke(null, new Object[] {sampleURL});
           
            if (proxyInfoArrayObj == null 
                    || Array.getLength(proxyInfoArrayObj) == 0) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("1.4+ reported NULL proxy (no proxy assumed)");
                }
                result = NO_PROXY_HOST;                   
            } else {
                Object proxyInfoObject = Array.get(proxyInfoArrayObj, 0);
                Class proxyInfoClass = proxyInfoObject.getClass();
                Method getHostMethod =
                    proxyInfoClass.getDeclaredMethod("getHost",null);
                String proxyIP =
                    (String)getHostMethod.invoke(proxyInfoObject, null);
                Method getPortMethod =
                    proxyInfoClass.getDeclaredMethod("getPort",null);
                Integer portInteger =
                    (Integer)getPortMethod.invoke(proxyInfoObject, null);
                int proxyPort = portInteger.intValue();
                if (LOG.isDebugEnabled()) {
                    LOG.debug("1.4+ Proxy info get Proxy:"+proxyIP+
                              " get Port:"+proxyPort);
                }
                result = new ProxyHost(proxyIP, proxyPort);
            }
        } catch (RuntimeException e) {           
            throw e;
        } catch (Exception e) {
            LOG.debug("Sun Plugin 1.4+ proxy detection class not found, " +
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.