hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ali Mohammed" <Ali.Moham...@amdocs.com>
Subject RE: Error with ProxyClient
Date Wed, 21 Dec 2005 02:14:01 GMT

Hi,



I'm able to make some progess and now I'm getting this other error.



Here's the error message:



Dec 20, 2005 6:08:08 PM
org.apache.commons.httpclient.auth.AuthChallengeProcessor
selectAuthScheme



INFO: ntlm authentication scheme selected



Connect failed: HTTP/1.0 404 Not Found



Here's my code:



public class ProxyTunnelDemo {

        ProxyClient proxyclient = new ProxyClient();




proxyclient.getHostConfiguration().setHost("http://www.yahoo.com");


proxyclient.getHostConfiguration().setProxy("genproxy.amdocs.com",
8080);

        proxyclient.getState().setProxyCredentials(

            new AuthScope("proxy_host", proxy_port, null, null),

            new NTCredentials("login_name", "password", "proxy_host",
"domain"));



        // create the socket

        ProxyClient.ConnectResponse response = proxyclient.connect();



        if (response.getSocket() != null) {

            Socket socket = response.getSocket();

            try {

                // go ahead and do an HTTP GET using the socket

                Writer out = new OutputStreamWriter(

                    socket.getOutputStream(), "ISO-8859-1");

                out.write("GET http://www.yahoo.com/ HTTP/1.1\r\n");

                out.write("Host: www.yahoo.com\r\n");

                out.write("Agent: whatever\r\n");

                out.write("\r\n");

                out.flush();

                BufferedReader in = new BufferedReader(

                    new InputStreamReader(socket.getInputStream(),
"ISO-8859-1"));

                String line = null;

                while ((line = in.readLine()) != null) {

                    System.out.println(line);

                }

            } finally {

                // be sure to close the socket when we're done

                socket.close();

            }

        } else {

            // the proxy connect was not successful, check connect
method for reasons why

            System.out.println("Connect failed: " +
response.getConnectMethod().getStatusLine());


//System.out.println(response.getConnectMethod().getResponseBodyAsString
());

        }

    }



Can anyone tell me what's going on here? I have been trying since 2 days
now and I'm stumped.



I found another piece of code on the net that dumps the content from the
url and that works fine with proxy. Here's the code for that program: I
don't understand why ProxyClient wouldn't work.



package webconnector;



import java.net.*;

import java.io.*;

import java.net.*;

import java.util.Properties;



public class CheckUrl {

  public static void main(String s[]) {

    new CheckUrl().dump("http://www.yahoo.com");

    System.out.println("**************");

    new CheckUrl().dump("http://www.paypal.com");

    System.out.println("**************");

   }



public void dump(String URLName){

  try {

    DataInputStream di = null;

    FileOutputStream fo = null;

    byte [] b = new byte[1];



    // PROXY --------- jdk1.3.1

    Properties systemSettings = System.getProperties();

    systemSettings.put("proxySet", "true");

    systemSettings.put("http.proxyHost","proxy_host") ;

    systemSettings.put("http.proxyPort", "proxy_port") ;



    URL u = new URL(URLName);

    HttpURLConnection con = (HttpURLConnection) u.openConnection();

    sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();

    String encodedUserPwd =

         encoder.encode("domain\\login_name:password".getBytes());

    con.setRequestProperty

         ("Proxy-Authorization", "Basic " + encodedUserPwd);

    // PROXY ----------



    di = new DataInputStream(con.getInputStream());

    while(-1 != di.read(b,0,1)) {

         System.out.print(new String(b));

         }

    }

  catch (Exception e) {

       e.printStackTrace();

       }

  }

 }





Thanks.

Ali.







________________________________

From: Ali Mohammed
Sent: Tuesday, December 20, 2005 2:11 PM
To: 'httpclient-user@jakarta.apache.org'
Subject: Error with ProxyClient



Hi,



I'm a beginner and I'm trying the sample code to connect to a webpage
using the ProxyTunnelDemo class from the examples and I always get an
error "Unknown Host Exception". Here's the error message.



C:\bea\j2sdk1.4.2_06\bin\javaw -classpath
"C:\JavaProjects\Http_Client\classes;C:\bea\weblogic81\server\lib\weblog
ic.jar;C:\JavaProjects\Http_Client\commons-httpclient-3.0-rc4\commons-ht
tpclient-3.0-rc4.jar;C:\JavaProjects\Http_Client\commons-codec-1.3\commo
ns-codec-1.3.jar;C:\JavaProjects\Http_Client\commons-logging-1.0.4\commo
ns-logging.jar;C:\JavaProjects\Http_Client\commons-logging-1.0.4\commons
-logging-api.jar;C:\JavaProjects\Http_Client\junit3.8.1\junit.jar;C:\bea
\j2sdk1.4.2_06\jre\javaws\javaws.jar;C:\bea\j2sdk1.4.2_06\jre\lib\charse
ts.jar;C:\bea\j2sdk1.4.2_06\jre\lib\ext\dnsns.jar;C:\bea\j2sdk1.4.2_06\j
re\lib\ext\ldapsec.jar;C:\bea\j2sdk1.4.2_06\jre\lib\ext\localedata.jar;C
:\bea\j2sdk1.4.2_06\jre\lib\ext\sunjce_provider.jar;C:\bea\j2sdk1.4.2_06
\jre\lib\im\indicim.jar;C:\bea\j2sdk1.4.2_06\jre\lib\im\thaiim.jar;C:\be
a\j2sdk1.4.2_06\jre\lib\jce.jar;C:\bea\j2sdk1.4.2_06\jre\lib\jsse.jar;C:
\bea\j2sdk1.4.2_06\jre\lib\plugin.jar;C:\bea\j2sdk1.4.2_06\jre\lib\rt.ja
r;C:\bea\j2sdk1.4.2_06\jre\lib\sunrsasign.jar;C:\bea\j2sdk1.4.2_06\lib\d
t.jar;C:\bea\j2sdk1.4.2_06\lib\htmlconverter.jar;C:\bea\j2sdk1.4.2_06\li
b\tools.jar"  ProxyTunnelDemo

java.io.IOException: Stream closed



            at
java.io.BufferedInputStream.ensureOpen(BufferedInputStream.java:120)



            at
java.io.BufferedInputStream.read(BufferedInputStream.java:270)



            at
org.apache.commons.httpclient.ContentLengthInputStream.read(ContentLengt
hInputStream.java:169)



            at
java.io.FilterInputStream.read(FilterInputStream.java:111)



            at
org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputSt
ream.java:107)



            at java.io.FilterInputStream.read(FilterInputStream.java:90)



            at
org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputSt
ream.java:126)Connect failed: HTTP/1.0 403 Forbidden







            at
org.apache.commons.httpclient.HttpMethodBase.getResponseBody(HttpMethodB
ase.java:684)



            at
org.apache.commons.httpclient.HttpMethodBase.getResponseBodyAsString(Htt
pMethodBase.java:735)



            at ProxyTunnelDemo.main(ProxyTunnelDemo.java:92)



Exception in thread "main"



Thanks,

Ali.



The information contained in this message is proprietary of Amdocs,
protected from disclosure, and may be privileged.
The information is intended to be conveyed only to the designated recipient(s)
of the message. If the reader of this message is not the intended recipient,
you are hereby notified that any dissemination, use, distribution or copying of
this communication is strictly prohibited and may be unlawful.
If you have received this communication in error, please notify us immediately
by replying to the message and deleting it from your computer.
Thank you.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message