Life of a java disciple




J2EE Blogs:

J2ME Blogs:

.NET Blogs:

Important Links:

International Users:


















This page is powered by Blogger. Isn't yours?
Sunday, December 19, 2004
 

JSSE: How to ignore CertificateException: Couldn't find trusted certificate"?


While testing SecureSocket code, sometimes you would need code to ingore certificate validation.
JSSE provides a simple way to do this by writing your own TrustManager. The below sample code lets you write simple clients ignore certificate validation:

01 
02 
03 import java.io.InputStream;
04 import java.io.OutputStream;
05 
06 import javax.net.ssl.SSLContext;
07 import javax.net.ssl.SSLSocket;
08 import javax.net.ssl.SSLSocketFactory;
09 import javax.net.ssl.TrustManager;
10 import javax.net.ssl.X509TrustManager;
11 
12 /*
13  * This example demostrates how to use a SSLSocket as client to
14  * send and recieve Data while ignoring the certificate validation.
15  */
16 
17 public class SSLClient {
18 
19     public static void main(String[] argsthrows Exception {
20 
21         // Create a trust manager that does not validate certificate chains like the default TrustManager
22         TrustManager[] trustAllCerts = new TrustManager[]{
23             new X509TrustManager() {
24 
25                 public java.security.cert.X509Certificate[] getAcceptedIssuers() {
26                     return null;
27                 }
28 
29                 public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
30                     //No need to implement.
31                 }
32 
33                 public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
34                     //No need to implement.
35                 }
36             }
37         };
38 
39         // Let us create the factory where we can set some parameters for the connection
40         SSLContext sc = SSLContext.getInstance("SSL");
41         sc.init(null, trustAllCerts, new java.security.SecureRandom());
42 
43         SSLSocketFactory factory =sc.getSocketFactory();
44         SSLSocket socket =(SSLSocket)factory.createSocket(args[0], Integer.parseInt(args[1]));
45         socket.startHandshake();
46 
47 
48         OutputStream out = socket.getOutputStream();
49         InputStream in = socket.getInputStream();
50 
51         //Do- Fun stuff with I/O classes.
52     }
53 }


(3) comments
 

Mustang: 2 new methods in String class.


Two new helper methods are added to String class. The changes are described in bug#6189137.

1. boolean isEmpty() { return length() == 0; }
2. boolean contains(String s) { return indexOf(s) >= 0; }

A Simple test code to test the new features:

01 public class StringTest {
02     public static void main(String args[]) {
03 
04         String str = new String();
05         System.out.println(str.isEmpty());
06 
07         str = "Testing contains()";
08         System.out.println(str.contains("contains"));
09         System.out.println(str.isEmpty());
10     }
11 }


Result of executing the Test Code:
true
true
false

(1) comments
Thursday, December 16, 2004
 

BEA: Diablo (weblogic9 Beta) available for download


BEA made Diablo (Weblogic9 Beta) available for download as promised today.
Download it here.
Documentation is here.
What's new in 9.0 is here.

The changes to me looked like this release should have been 8.2 instead of 9. There are lot of little goodies but nothing that really make me want to move to 9 from 8.1. The most exciting change is support for JDK5.0

(8) comments
Tuesday, December 14, 2004
 

Google: Is this really possible?


Google did amazing JavaScript again with google suggest. I always hated Javascript and have to agree what google is doing is really amazing because its really cool and flaw less work with JavaScript and XMLHTTP.

Here is a link to the compresses javascript used by google (Don't you wonder why so few sites really compress js?).

(6) comments