Re: HttpUrlConnection.getInputStream() returns empty
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 [EMAIL PROTECTED] 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
Re: SSL Certificate Errors
I do not know what caused this problem..but you can solve this by explicitely trusting all the certificates. And this will work if client side certs are not used. You can find information on how to do this in the following URL. http://javaalmanac.com/egs/javax.net.ssl/TrustAll.html Thanks, George --- Craig, William S. [EMAIL PROTECTED] wrote: Hi, I'm experiencing the following errors while running Tomcat 4.1.27 on Win2K. I have a U.S. Government certificate in X.509 format trusted on Tomcat. I'm trying to communicate on SSL, but it appears that my certificate isn't trusted. I followed the instructions - any ideas on why my certificate isn't being trusted (if that's my problem) Thanks!! cacerts file: pa-ng-app, Jun 16, 2004 trustedCertEntry, Certificate fingerprint (MD5): DD:3D:8F.etc Errors: Exception Message: java.security.cert.CertificateException: Could not find trusted certificate javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: Could not find trusted certificate at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275) at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275) at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275) at com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(DashoA6275) at sun.net.www.protocol.https.HttpsClient.afterConnect(DashoA6275) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(DashoA 6275) at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(DashoA6275) at com.plumtree.content.client.http.diagnostic.DiagnosticTestsUtil.connectAndCh eckResponseCode(DiagnosticTestsUtil.java:127) at com.plumtree.content.client.http.diagnostic.DiagnosticTests.testConnectionWi thPortal(DiagnosticTests.java:644) 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:324) at com.plumtree.content.client.http.diagnostic.DiagnosticTests.executeTestMetho d(DiagnosticTests.java:202) at com.plumtree.content.client.http.diagnostic.DiagnosticTests.executeDiagnosti cTests(DiagnosticTests.java:178) at com.plumtree.content.client.http.diagnostic.DiagnosticTests.getDiagnosticTes tResults(DiagnosticTests.java:150) at org.apache.jsp.index_0002dinclude_0002ddiagnostics_jsp._jspService(index_000 2dinclude_0002ddiagnostics_jsp.java:53) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137) at ...etcetc. ___ALL-NEW Yahoo! Messenger - all new features - even more fun! http://www.allnewmessenger.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: HttpUrlConnection.getInputStream() returns empty
Hi reynir, I have made the changes as per you suggestion and I am getting the response code as 200. But still the inputstream returns empty, is.available() returns 0 bytes. thanks, - george --- Reynir_Þór_Hübner [EMAIL PROTECTED] wrote: 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()+\nbr); 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 ___ALL-NEW Yahoo! Messenger - all new features - even more fun! http://www.allnewmessenger.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
HttpUrlConnection.getInputStream() returns empty
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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Apache-Tomcat combination, Best Practices
Hi, First of all I assume I am posting to the correct mailing list, ignore this otherwise. I am trying to configure Apache Server Tomcat for running my JSPs static pages. Can anybody give me the best way of doing this. Where should I place my static HTML files where should I place my JSP pages. Also how do I redirect all the JSP requests to the Tomcat. I basically want all my static pages to be processed by Apache server the JSP pages by tomcat. I am Using Apache2,tomcat-4.1.18 mod_jk2 connector. George __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]