hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From DreamEfforts <arvind...@yahoo.com>
Subject Proxy authentication details fetching
Date Mon, 10 Sep 2007 17:39:51 GMT

Hi Everyone,

I’m using Java plug-in API (plugin.jar which is present in JAVA_HOME/jre/lib
folder) for fetching the proxy server details like host and port of the
proxy server and Apache HttpClient API for fetching the proxy is
authenticated or not.
 
I used the below code for detecting the proxy authentication details and
this code is working fine and showing me the desired results.
private void detectAuthentication() {
    try {      
	  System.setProperty("http.proxySet", "true");
	  System.setProperty("http.proxyHost", hostName);
      System.setProperty("http.proxyPort", "" + port);

      ProxyClient proxyClient = null;
      ConnectMethod connectionMethod = null;

      try {
        setProxyProperties();
        proxyClient = new ProxyClient();
       
proxyClient.getParams().setConnectionManagerClass(SimpleHttpConnectionManager.class);

        HostConfiguration hostConfiguration =
            proxyClient.getHostConfiguration();
        hostConfiguration.setHost(UtilConstants.HTTP_PROXY_DETECT_URL);
        hostConfiguration.setProxy(hostName, 80);

        System.out.println("before connect");
        ProxyClient.ConnectResponse response = proxyClient.connect();

        System.out.println("after connect");

        connectionMethod = response.getConnectMethod();
        isProxyAuthenticated = connectionMethod.getDoAuthentication();
        System.out.println("isProxyAuthenticated : " +
isProxyAuthenticated);

        AuthState authState = connectionMethod.getProxyAuthState();
        isAuthAttempted = authState.isAuthAttempted();
        System.out.println("isAuthAttempted : " + isAuthAttempted);

        isAuthRequested = authState.isAuthRequested();
        System.out.println("isAuthRequested : " + isAuthRequested);

        schemaName = authState.getAuthScheme().getSchemeName();
        System.out.println("schemaName : " + schemaName);
      }
      catch (Exception e) {
        System.out.println("" + e.getMessage());
        isProxyAuthenticated = false;
      }
      finally {
        if (proxyClient != null) {
          proxyClient = null;
        }

        if (connectionMethod != null) {
          connectionMethod = null;
        }
      }
    }
    catch (Exception e) {
      isProxyAuthenticated = false;
    }
  }

When using the same code in a bean class then it’s not working and it’s
throwing the exception. I could understand that apache proxy client is
trying to connect to the Socks server, but socks server details are not
present in the system properties. 

2007/09/05 11:32:24:041 EDT [DEBUG] HttpConnection - Open connection to
192.158.10.151:80
2007/09/05 11:37:24:553 EDT [DEBUG] HttpMethodDirector - Closing the
connection.
2007/09/05 11:37:24:553 EDT [INFO] HttpMethodDirector - I/O exception
(java.net.SocketException) caught when processing request: Malformed reply
from SOCKS server
2007/09/05 11:37:24:553 EDT [DEBUG] HttpMethodDirector - Malformed reply
from SOCKS server <java.net.SocketException: Malformed reply from SOCKS
server>java.net.SocketException: Malformed reply from SOCKS server
	at java.net.SocksSocketImpl.readSocksReply(SocksSocketImpl.java:87)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:429)
	at java.net.Socket.connect(Socket.java:519)
	at java.net.Socket.connect(Socket.java:469)
	at java.net.Socket.<init>(Socket.java:366)
	at java.net.Socket.<init>(Socket.java:239)
	at
org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
	at
org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:122)
	at
org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
	at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
	at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
	at org.apache.commons.httpclient.ProxyClient.connect(ProxyClient.java:206)
	at utilities.beans.ProxyBean.doAuthentication(ProxyBean.java:180)
	at utilities.beans.ProxyBean.process(ProxyBean.java:33)
	at utilities.test.ProxyTest.<init>(ProxyTest.java:12)
	at utilities.test.ProxyTest.main(ProxyTest.java:36)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at AppMain.main(AppMain.java:90)


Can any one help me how to fix this issue.

Thanks


-- 
View this message in context: http://www.nabble.com/Proxy-authentication-details-fetching-tf4417021.html#a12598523
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Mime
View raw message