tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Reynir Þór Hübner <rey...@hugsmidjan.is>
Subject Re: HttpUrlConnection.getInputStream() returns empty
Date Tue, 27 Jul 2004 10:47:59 GMT
hi,
you could maybe try somthing like the following :

try
{
   String str_url = "https://www.domain.com";
   URL urlid = new URL(str_url);
   HttpsURLConnection conn = (HttpsURLConnection)urlid.openConnection();
   conn.setRequestMethod("GET");
   conn.setDoOutput(false);
   out.write("RESPONSECODE = " + conn.getResponseCode()+"\n<br>");
   BufferedReader in1 = new BufferedReader(new 
InputStreamReader(conn.getInputStream()));
   String line;
   while ((line = in1.readLine()) != null)
      out.write(line +"\n");
}
catch (Exception e)
{
   e.printStackTrace(System.out);
}

hope it helps
-reynir


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
> 

---------------------------------------------------------------------
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