• Entries (RSS)
  • Comments (RSS)

javax.net.ssl.SSLHandshakeException: certificate expired

Posted by | Posted in Java, WebSphere | Posted on 24-06-2009

Tagged Under : ,

javax.net.ssl.SSLHandshakeException: certificate expired

javax.net.ssl.SSLHandshakeException: certificate expired. We get this exception when we try to invoke a web service from WebSphere Application Server 5.1. (In fact you will get this exception if your java version is 1.4.2_02 and earlier.) The complete stack trace of the exception is

WebServicesFault
 faultCode: Server.generalException
 faultString: javax.net.ssl.SSLHandshakeException: certificate expired
 faultActor: null
 faultDetail:
 
javax.net.ssl.SSLHandshakeException: certificate expired
        at com.ibm.ws.webservices.engine.WebServicesFault.makeFault(WebServicesFault.java:158)
        at com.ibm.ws.webservices.engine.transport.http.HTTP11Sender.invoke(HTTP11Sender.java:330)
        at com.ibm.ws.webservices.engine.transport.http.HTTPSender.invoke(HTTPSender.java:87)
        at com.ibm.ws.webservices.engine.PivotHandlerWrapper.invoke(PivotHandlerWrapper.java:212)

We get this exception because our trust store contains an expired Class 2 and Class 3 certificates. The Class 3 root certificate is used for authenticating web sites, signed code, SSL, OFX, and Administrator certificates. Class 2 root certificates are used for authenticating users and individuals.

The solution to this problem is to update the Class 2 and Class 3 certificates in our trust store. To do this either download the latest certificates from http://www.verisign.com/support/roots.html or extract the Class 2 and Class 3 certificates from a newer version of Java.

To import the latest certificates follow the below steps. The default password for sun cacerts is changeit

1. Delete the existing certificates by issing the following commands.
%JAVA_HOME%/bin/keytool -delete -alias verisignclass2ca -keystore %JAVA_HOME%/jre/lib/security/cacerts
%JAVA_HOME%/bin/keytool -delete -alias verisignclass3ca -keystore %JAVA_HOME%/jre/lib/security/cacerts

2. Import the new certificates by issuing the following command
%JAVA_HOME%/bin/keytool -import -v -keystore %JAVA_HOME%/jre/lib/security/cacerts -alias verisignclass2ca -file /home/Albin/certs/verisignclass2ca.arm

%JAVA_HOME%/bin/keytool -import -v -keystore %JAVA_HOME%/jre/lib/security/cacerts -alias verisignclass3ca -file /home/Albin/certs/verisignclass3ca.arm

Here verisignclass2ca.arm and verisignclass3ca.arm are the two new Class 2 and Class 3 certificates we imported. The above commands assume that your trust store is pointing to %JAVA_HOME%/jre/lib/security/cacerts, if it points to a different file, change the location.

For those who are facing difficulties in extracting the new certificates, download it from here. verisignclass2ca and verisignclass3ca. This is the certificates I have used when I encountered this issue.

Share

Cannot find the tag library descriptor for “http://java.sun.com/jsp/jstl/core”

Posted by | Posted in JSP | Posted on 09-12-2008

Tagged Under : , ,

Cannot find the tag library descriptor for “http://java.sun.com/jsp/jstl/core”

‘Cannot find the tag library descriptor for “http://java.sun.com/jsp/jstl/core”‘ is an error message that you might have seen while executing your JSTL code. So if you are getting this error message, the first thing you need to do is to make sure that you have all the JSTL jar files are in your class path. If you have the JSTL libraries in your class path and still you are getting the same error, you will have an older version of JSTL in your class path. Now to fix this issue change the declaration to

<[email protected] uri="http://java.sun.com/jstl/core" prefix="c" %>
Share

Recursively delete a directory

Posted by | Posted in Java | Posted on 02-11-2008

Tagged Under :

Recursively delete a directory

Here is a very simple code for recursively delete directories using java.

	/**
	 * Recursively deletes a directory and all its
	 * sub directories.
	 */
	public static void deleteDir(File dir){
		// If it is a directory get the child
		if(dir.isDirectory()) {
			// List all the contents of the directory
			File fileList[] = dir.listFiles();
 
			// Loop through the list of files/directories
			for(int index = 0; index < fileList.length; index++) {
				// Get the current file object.
				File file = fileList[index];
 
				// Call deleteDir function once again for deleting all the directory contents or
				// sub directories if any present.
				deleteDir(file);
			}
		}
 
		// Delete the current directory or file.
	        dir.delete();
	}

To delete a directory using this method pass the directory name as a File object to deleteDir method. This code is very useful if the directory name is too long. Windows has a restriction in how long a Filename can be. So if you file path is too long, you wouldn’t be able to delete a directory.

Share

Sorting an ArrayList of objects.

Posted by | Posted in Java | Posted on 16-10-2008

Tagged Under :

Sorting an ArrayList of objects.

How do we sort an ArrayList of objects? The easiest way to sort an ArrayList of Objects is to use the Collections.sort() method. But how does the sort method know based on which field you need to sort? The solution is to implement the Comparator interface and override the compare method. For e.g.: if I have a class named person with the following structure.

class Person {
    private String firstName;
    private String lastName;
 
    public Person(){
    }
    public Person(String firstName, String lastName){
        this.firstName = firstName;
        this.lastName = lastName;
    }
 
    /**
     * @return Returns the firstName.
     */
    public String getFirstName() {
        return firstName;
    }
    /**
     * @param firstName The firstName to set.
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    /**
     * @return Returns the lastName.
     */
    public String getLastName() {
        return lastName;
    }
    /**
     * @param lastName The lastName to set.
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
 
    public String toString(){
        return "## Firstname : "+this.firstName+", Lastname : "+this.lastName;
    }
}

I have created some objects of Person class and they are added to an ArrayList. Now I need to sort the ArrayList based on Person’s firstName. The complete code listing for sorting the ArrayList is given below.

	Person p = new Person("Bruce", "Willis");
        Person p1  = new Person("Tom", "Hanks");
        Person p2 = new Person("Nicolas","Cage");
        Person p3 = new Person("John","Travolta");
 
        ArrayList list = new ArrayList();
        list.add(p);
        list.add(p1);
        list.add(p2);
        list.add(p3);
 
        Collections.sort(list, new Comparator(){
 
            public int compare(Object o1, Object o2) {
                Person p1 = (Person) o1;
                Person p2 = (Person) o2;
               return p1.getFirstName().compareToIgnoreCase(p2.getFirstName());
            }
 
        });
 
        System.out.println(list);

Here inside my Collections.sort method I am implementing the Comparator interface and overriding the compare method.

Share

JoSQL (SQL for Java Objects)

Posted by | Posted in Java | Posted on 30-06-2008

Tagged Under : ,

Recently I made a post on Language Integrated Query (LINQ) in C#. Since I like that feature very much I did a search for finding some similar libraries for Java. There is one project in sourceforge called JoSQL (http://josql.sourceforge.net/index.html) for querying collections using SQL syntax in Java. I would call JoSQL as LINQ alternative for Java. This JoSQL (SQL for Java Objects) is a small and powerful library which helps us to query Java collections. I just completed a small program for sorting a collection of object. Yes there are some Out of the Box sorting functions available in Collections. But still I used JoSQL for my sorting purpose.

Here is my first JoSQL program.

		// Create a list first
		ArrayList list = new ArrayList();
 
		// Add something to our collection
		list.add("1");
		list.add("3");
		list.add("5");
		list.add("4");
		list.add("2");
 
		// Just print it.
		System.out.println(list);
 
		// Create the query object.
		Query qry = new Query();
 
		// Our Java Object SQL for getting all the elements that are greater than
		// 2 and sorted based on the value
		qry.parse("SELECT * FROM java.lang.String WHERE toString > 2 ORDER BY toString ");
 
		// Get the query results.
		List results = qry.execute(list).getResults();
 
		// Now display the query results
		for(int index=0; index < results.size(); index++){
			System.out.println(results.get(index));
		}

I will give a small explanation for the above program. First I am creating an ArrayList and populating the collection with some values. Next I am querying on that collection. The query I used is “SELECT * FROM java.lang.String WHERE toString > 2 ORDER BY toString “. Here just like a normal SQL our JoSQL query also started with a SELECT, then the columns we want(In my case I want all the columns so I used *). Then I have mentioned java.lang.String as my FROM. This is because my Collection contains String objects. Then the WHERE clause. The WHERE clause condition in our case is ‘toString > 2’. Here toString is a method inside java.lang.String class. I wanted some column to apply my condition, so I thought I will use the toString method as my column name. Instead of toString method we can use any method we want. Then the ORDER BY clause. There also I used the toString methods as I did not find any other column to sort :-)

Share