Package org.apache.commons.httpclient

Examples of org.apache.commons.httpclient.ProxyHost


        if (!urlString.startsWith("http://")) {
            urlString = "http://" + urlString;
        }
        try {
            URL url = new URL(urlString);
            ProxyHost hostInfo = PluginProxyUtil.detectProxy(url);
            if (hostInfo != null) {
                hostLabel.setText(hostInfo.getHostName());
                portLabel.setText(""+hostInfo.getPort());
            } else {
                hostLabel.setText("none");
                portLabel.setText("none");
            }
            grid.validate();
View Full Code Here


   
    public String getProxyHost(String urlString) {
        String result = urlString;
        try {
            URL url = new URL(urlString);
            ProxyHost hostInfo = PluginProxyUtil.detectProxy(url);
            if (hostInfo != null) {
                result = hostInfo.getHostName();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
View Full Code Here

    public int getProxyPort(String urlString) {
        int result = 80;
        try {
            URL url = new URL(urlString);
            ProxyHost hostInfo = PluginProxyUtil.detectProxy(url);
            if (hostInfo != null) {
                result = hostInfo.getPort();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
View Full Code Here

     */
    public static ProxyHost detectProxy(URL sampleURL)
        throws ProxyDetectionException
    {
       
        ProxyHost result = null;
        String javaVers = System.getProperty("java.runtime.version");
       
        if (LOG.isDebugEnabled()) {
            LOG.debug("About to attempt auto proxy detection under Java " +
                      "version:"+javaVers);
View Full Code Here

     * @throws ProxyDetectionException if detection failed
     */
    private static ProxyHost detectProxySettingsJDK13(URL sampleURL)
        throws ProxyDetectionException
    {
        ProxyHost result = null;
        try {
            // Attempt to discover proxy info by asking internal plugin
            // code to locate proxy path to server sampleURL...
            Class pluginProxyHandler =
                Class.forName("sun.plugin.protocol.PluginProxyHandler");
            Method getDefaultProxyHandlerMethod =
                pluginProxyHandler.getDeclaredMethod("getDefaultProxyHandler",
                                                     null);
            Object proxyHandlerObj =
                getDefaultProxyHandlerMethod.invoke(null, null);
            if (proxyHandlerObj != null) {
                Class proxyHandlerClass = proxyHandlerObj.getClass();
                Method getProxyInfoMethod =
                    proxyHandlerClass.getDeclaredMethod("getProxyInfo",
                                                        new Class[]{URL.class});
                Object proxyInfoObject =
                    getProxyInfoMethod.invoke(proxyHandlerObj,
                                              new Object[] { sampleURL });
                if (proxyInfoObject != null) {
                    Class proxyInfoClass = proxyInfoObject.getClass();
                    Method getProxyMethod =
                        proxyInfoClass.getDeclaredMethod("getProxy", null);
                    boolean useProxy =
                        (getProxyMethod.invoke(proxyInfoObject, null) != null);
                    if (useProxy) {
                        String proxyIP =
                            (String)getProxyMethod.invoke(proxyInfoObject, null);
                        Method getProxyPortMethod =
                            proxyInfoClass.getDeclaredMethod("getPort", null);
                        Integer portInteger =
                            (Integer)getProxyPortMethod.invoke(proxyInfoObject, null);
                        int proxyPort = portInteger.intValue();
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("1.3.X: proxy=" + proxyIP+
                                      " port=" + proxyPort);
                        }
                        result = new ProxyHost(proxyIP, proxyPort);
                    } else {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("1.3.X reported NULL for " +
                                      "proxyInfo.getProxy (no proxy assumed)");
                        }
View Full Code Here

     *
     * @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(URL sampleURL) {
        ProxyHost result = null;
        try {
            // Look around for the 1.4.X 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.X 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.X Proxy info geProxy:"+proxyIP+
                              " get Port:"+proxyPort);
                }
                result = new ProxyHost(proxyIP, proxyPort);
            }
        } catch (Exception e) {
            LOG.warn("Sun Plugin 1.4.X proxy detection class not found, " +
                     "will try failover detection, e:"+e);
        }       
View Full Code Here

     *                                 PLUGIN_PROXY_CONFIG_PROP
     */
    private static ProxyHost getPluginProxyConfigSettings()
        throws ProxyDetectionException
    {
        ProxyHost result = null;
        try {
            Properties properties = System.getProperties();
            String proxyList =
                properties.getProperty("javaplugin.proxy.config.list");
            if (LOG.isDebugEnabled()) {
                LOG.debug("Plugin Proxy Config List Property:"+proxyList);
            }
            boolean useProxy = (proxyList != null);
            if (useProxy) {
                proxyList = proxyList.toUpperCase();
                //  Using HTTP proxy as proxy for HTTP proxy tunnelled SSL
                //  socket (should be listed FIRST)....
                //  1/14/03 1.3.1_06 appears to omit HTTP portion of
                //  reported proxy list... Mod to accomodate this...
                //  Expecting proxyList of "HTTP=XXX.XXX.XXX.XXX:Port" OR
                //  "XXX.XXX.XXX.XXX:Port" & assuming HTTP...
                String proxyIP="";
                if (proxyList.indexOf("HTTP=") > -1) {
                    proxyIP =
                        proxyList.substring(proxyList.indexOf("HTTP=")+5,
                                            proxyList.indexOf(":"));
                } else {
                    proxyIP = proxyList.substring(0, proxyList.indexOf(":"));
                }
                int endOfPort = proxyList.indexOf(",");
                if (endOfPort < 1) endOfPort = proxyList.length();
                String portString =
                    proxyList.substring(proxyList.indexOf(":")+1,endOfPort);
                int proxyPort = Integer.parseInt(portString);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("proxy " + proxyIP+" port " + proxyPort);
                }
                result = new ProxyHost(proxyIP, proxyPort);
            } else {
                LOG.debug("No configured plugin proxy list");
                result = NO_PROXY_HOST;
            }
        } catch (Exception e) {
View Full Code Here

     *
     * @param httpClient    The HttpClient that should have its host configurations proxy host set.
     * @param properties    The properties that should be set.
     */
    void setHttpProxyHost(final HttpClient httpClient, final Properties properties) {
        ProxyHost proxyHost = createProxyHost("http.proxyHost", "http.proxyPort", 80, properties);
        if (proxyHost != null) {
            httpClient.getHostConfiguration().setProxyHost(proxyHost);
        }
    }
View Full Code Here

     *
     * @param httpClient    The HttpClient that should have its host configurations proxy host set.
     * @param properties    The properties that should be set.
     */
    void setHttpsProxyHost(final HttpClient httpClient, final Properties properties) {
        ProxyHost proxyHost = createProxyHost("https.proxyHost", "https.proxyPort", 443, properties);
        if (proxyHost != null) {
            httpClient.getHostConfiguration().setProxyHost(proxyHost);
        }
    }
View Full Code Here

        }
    }
   
    private ProxyHost createProxyHost(final String hostPropertyName, final String portPropertyName, final int defaultPort, final Properties properties) {
        final String proxyHost = (String) properties.get(hostPropertyName);
        ProxyHost proxy = null;
        if (proxyHost != null) {
            final String proxyPortStr = (String) properties.get(portPropertyName);
            if (proxyPortStr == null) {
                proxy = new ProxyHost(proxyHost, defaultPort);
            }
            else {
                proxy = new ProxyHost(proxyHost, Integer.parseInt(proxyPortStr));
            }
            log.debug("ProxyHost " + proxy.toString());
        }
        return proxy;
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.ProxyHost

Copyright © 2018 www.massapicom. 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.