Reputation: 41
my httpclient project has encountered a strange problem .it run successful in other two Centos systems with java1.6. but it failed in another machine(centos and java1.6). the problem is:
java.lang.IllegalStateException: Failure initializing default SSL context [java] at org.apache.http.conn.ssl.SSLSocketFactory.createDefaultSSLContext(SSLSocketFactory.java:211) [java] at org.apache.http.conn.ssl.SSLSocketFactory.(SSLSocketFactory.java:333) [java] at org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory(SSLSocketFactory.java:165) [java] at org.apache.http.impl.conn.SchemeRegistryFactory.createDefault(SchemeRegistryFactory.java:45) [java] at org.apache.http.impl.client.AbstractHttpClient.createClientConnectionManager(AbstractHttpClient.java:294) [java] at org.apache.http.impl.client.AbstractHttpClient.getConnectionManager(AbstractHttpClient.java:445) [java] at simulativeLogin.WebClientDevWrapper.wrapClient(Unknown Source) [java] at simulativeLogin.GetAccessToken.getToken(Unknown Source) [java] at crawler.FriendshipCrawler.main(Unknown Source) [java] at java.lang.reflect.Method.invoke(libgcj.so.10) [java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ant-1.7.1.jar.so) [java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ant-1.7.1.jar.so) [java] at org.apache.tools.ant.taskdefs.Java.run(ant-1.7.1.jar.so) [java] at org.apache.tools.ant.taskdefs.Java.executeJava(ant-1.7.1.jar.so) [java] at org.apache.tools.ant.taskdefs.Java.executeJava(ant-1.7.1.jar.so) [java] at org.apache.tools.ant.taskdefs.Java.execute(ant-1.7.1.jar.so) [java] at org.apache.tools.ant.UnknownElement.execute(ant-1.7.1.jar.so) [java] at java.lang.reflect.Method.invoke(libgcj.so.10) [java] at org.apache.tools.ant.dispatch.DispatchUtils.execute(ant-1.7.1.jar.so) [java] at org.apache.tools.ant.Task.perform(ant-1.7.1.jar.so) [java] at org.apache.tools.ant.Target.execute(ant-1.7.1.jar.so) [java] at org.apache.tools.ant.Target.performTasks(ant-1.7.1.jar.so) [java] at org.apache.tools.ant.Project.executeSortedTargets(ant-1.7.1.jar.so) [java] at org.apache.tools.ant.Project.executeTarget(ant-1.7.1.jar.so) [java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(ant-1.7.1.jar.so) [java] at org.apache.tools.ant.Project.executeTargets(ant-1.7.1.jar.so) [java] at org.apache.tools.ant.Main.runBuild(ant-1.7.1.jar.so) [java] at org.apache.tools.ant.Main.startAnt(ant-1.7.1.jar.so) [java] at org.apache.tools.ant.launch.Launcher.run(ant-launcher-1.7.1.jar.so) [java] at org.apache.tools.ant.launch.Launcher.main(ant-launcher-1.7.1.jar.so) [java] Caused by: java.lang.IllegalStateException [java] at gnu.javax.net.ssl.provider.X509KeyManagerFactory.engineGetKeyManagers(libgcj.so.10) [java] at javax.net.ssl.KeyManagerFactory.getKeyManagers(libgcj.so.10) [java] at org.apache.http.conn.ssl.SSLSocketFactory.createSSLContext(SSLSocketFactory.java:187) [java] at org.apache.http.conn.ssl.SSLSocketFactory.createDefaultSSLContext(SSLSocketFactory.java:209)
Upvotes: 1
Views: 18638
Reputation: 77
The answer is in the comments. If you do type java -version
and see java version "1.5.0"
, you will need to make sure that you are using Java 6. It should say java version "1.6.0"
Upvotes: 0
Reputation: 656
It's not your fault. Use another JVM, that will solve your problem. I had the same problem. I'm running Apache HttpClient on Gumstix/linux/jamVM. I got the exactly the same exceptions. Here is a test program for X509. I ran it on my Mac mini, the result is "SunX509" as algorithm; but on jamVM, it is 'null'. Try it.
public class TestX509 {
public static void main(String[] args) {
String algorithm = Security
.getProperty("ssl.KeyManagerFactory.algorithm");
System.out.println("algorithm is " + algorithm);
}
}
See source of line 108 of gnu.javax.net.ssl.provider.X509KeyManagerFactory.java. This is where the exception comes from. (Because the 'current' is a key manager, which is null. You know that from the previous test.)
104: protected KeyManager[] engineGetKeyManagers()
105: {
106: if (current == null)
107: {
108: throw new IllegalStateException();
109: }
110: return new KeyManager[] { current };
111: }
112:
Since the library throws IllegalStateException, which is a RuntimeException, some one considered it as a bug of GCJ and reported it here http://code.google.com/p/selenium/issues/detail?id=2483.
Upvotes: 5
Reputation: 137637
I see that you're using GCJ as the implementation of Java (from the fact that the cause exception originates in the gnu.javax.net.ssl.provider.X509KeyManagerFactory
class, and the way that many stack levels are in libgcj.so.10
). Unfortunately, that's not a version of Java that's officially sanctioned; it has a number of issues in a few areas of its implementation and that can sometimes bite very hard. In particular, it seems that it has problems with X.509 key handling! (I didn't know that it did, but it clearly does.)
The simplest fix is to switch to using a different Java implementation. The Sun/Oracle Java implementation is definitely good (I use it extensively) and I've heard good things about the OpenJDK implementation too; as I understand it, OpenJDK is the Sun JDK with some parts removed (notably the bits that they licensed from elsewhere, which I believe to be a chunk of the codec and GUI code, but I don't know for sure). What you don't want to do is to spend your time working around bugs in an implementation of Java that nobody recommends using!
Upvotes: 2