tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Honey George <honey_geo...@yahoo.com>
Subject Re: HttpUrlConnection.getInputStream() returns empty
Date Thu, 29 Jul 2004 10:15:40 GMT
Hi David,
  My environment is Tomcat 4.1.18 + Sun JDK 1.4. I do
not use JSP and in my case a servlet invokes a java
class.
Now I got solution to my problem. The issue was that
the InputStream.avaulable() was returning 0 even
through there is byates to read.
My old code for reading bytes from the stream was like
this..
InputStream is = ......
byte[] b = new byte[is.available()];
is.read(b);

I modified this to...

ArrayList lines = new ArrayList();
BufferedReader r = new BufferedReader
(new InputStreamReader(in));
String line = null;
while ( (line=r.readLine()) != null )
{
if (StringUtils.isNotEmpty(line))
{
lines.add(line.trim());
}
}

Now I am getting the contents from the stream.

>From the JSSE Ref Guide:

"Implementation Note: Due to the complexity of the SSL
and TLS protocols, it is difficult to predict whether
incoming bytes on a connection are handshake or
application data, and how that data might affect the
current connection state (even causing the process to
block). In the Sun JSSE implementation, the
available() method on the object obtained by
SSLSocket.getInputStream() returns a count of the
number of application data bytes successfully
decrypted from the SSL connection but not yet read by
the application."

Thanks,
  George

 --- David Goodenough <david.goodenough@btconnect.com>
wrote: 
> Could you list your operating environment.  I have
> (see my other note) a
> very similar problem, and I think that by working
> out which components
> are common to both of us we can narrow this down
> much quicker.
> 
> I am using 5.0.27 Tomcat (I also used 4.1 and got
> the same problem), I am
> using JSPs with JSTL and the IO taglib, I am running
> on Sun JVM 1.4.2_05
> (also tried 1.4.1) on a Linux system.  As you are
> not using JSPs etc that 
> just about leaves Tomcat itself, JVM and the
> operating system.
> 
> David
> 
> On Monday 26 July 2004 19:15, Honey George wrote:
> > Hi All,
> >    I am facing a problem with HttpUrlConnection in
> > Tomcat. I wanted to extract the contents of an
> https
> > enabled URL,
> > actually from the same site where my application
> is
> > running(Will not try to access external URLs). My
> > program will look
> > like this.
> >
> >
>
===========================================================================
> >======================================= import
> java.net.*;
> > import java.util.*;
> > import java.io.*;
> >
> > import javax.net.ssl.HostnameVerifier;
> > import javax.net.ssl.HttpsURLConnection;
> > import javax.net.ssl.SSLSession;
> > import javax.net.ssl.*;
> > .............
> >
> >
>
System.getProperty("java.protocol.handler.pkgs","javax.net.ssl");
> > java.security.Security.addProvider(new
> > com.sun.net.ssl.internal.ssl.Provider());
> > .................
> >         HostnameVerifier hv = new
> HostnameVerifier()
> >         {
> >             public boolean verify(String
> urlHostName,
> > SSLSession session)
> >             {
> >                 System.out.println("Warning: URL
> Host:
> > "+urlHostName+" vs. "+session.getPeerHost());
> >                 return true;
> >             }
> >         };
> >
> > HttpsURLConnection.setDefaultHostnameVerifier(hv);
> >
> >         // Create a trust manager that does not
> > validate certificate chains
> >         TrustManager[] trustAllCerts = new
> > TrustManager[]{
> >         new X509TrustManager() {
> >             public
> > java.security.cert.X509Certificate[]
> > getAcceptedIssuers() {
> >                 return null;
> >             }
> >             public void checkClientTrusted(
> >                
> java.security.cert.X509Certificate[]
> > certs, String authType) {
> >             }
> >             public void checkServerTrusted(
> >                
> java.security.cert.X509Certificate[]
> > certs, String authType) {
> >             }
> >         }
> >         };
> >
> >         // Install the all-trusting trust manager
> >         try
> >         {
> >             SSLContext sc =
> > SSLContext.getInstance("SSL");
> >             sc.init(null, trustAllCerts, new
> > java.security.SecureRandom());
> >
> >
>
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
> >         } catch (Exception e) {
> >
> >         }
> >
> > 	................................
> >
> >         HttpURLConnection httpCon =
> >             (HttpURLConnection) new
> >
>
java.net.URL("https://www.abc.com/test.txt").openConnection();
> >
> >
> httpCon.setRequestProperty(USER_AGENT_HEADER_FIELD,
> > "");
> >
> > httpCon.setRequestProperty(ACCEPT_HEADER_FIELD,
> > "text/plain");
> >         return httpCon;
> >
> > 	InputStream is = httpCon.getInputStream();
> >
>
===========================================================================
> >======================================= Here the
> problem is that the
> > InputStream does not
> > return any contents when executed from inside
> Tomcat.
> > But I am able to
> > extract the contents of the URL when I execute
> outside
> > tomcat in a command line program. The Connection
> > object returned
> > by "new
> java.net.URL("https://www.abc.com/test.txt")"
> > is
> sun.net.www.protocol.https.HttpsURLConnectionImpl.
> >
> > Can I get some help on this one?
> >
> > Thanks & Regards,
> >    George
> >
> >
> >
> >
> >
> >
> >
>
___________________________________________________________ALL-NEW
> Yahoo!
> > Messenger - all new features - even more fun! 
> > http://www.allnewmessenger.com
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> tomcat-user-help@jakarta.apache.org
>  


	
	
		
___________________________________________________________ALL-NEW Yahoo! Messenger - all
new features - even more fun!  http://uk.messenger.yahoo.com

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


Mime
View raw message