users@glassfish.java.net

Re: custom X509TrustManager

From: <glassfish_at_javadesktop.org>
Date: Wed, 09 Jul 2008 00:01:25 PDT

Just curious, did you ever this log :

 ctx.log("EMELifeCycleListener: init()");

Can you modify the code instead to look like this :

public class EMELifeCycleListener implements LifecycleListener {

public void handleEvent(LifecycleEvent event) throws ServerLifecycleException {
LifecycleEventContext ctx = event.getLifecycleEventContext();
if (LifecycleEvent.INIT_EVENT == event.getEventType()) {
ctx.log("EMELifeCycleListener: INIT_EVENT");
/*Do simple init of my TrustManager no matter which state we are in*/
init(ctx);
return;
}
if (LifecycleEvent.STARTUP_EVENT == event.getEventType()) {
ctx.log("EMELifeCycleListener: STARTUP_EVENT");
return;
}
if (LifecycleEvent.SHUTDOWN_EVENT == event.getEventType()) {
ctx.log("EMELifeCycleListener: SHUTDOWN_EVENT");
return;
}
if (LifecycleEvent.TERMINATION_EVENT == event.getEventType()) {
ctx.log("EMELifeCycleListener: TERMINATE_EVENT");
return;
}

}

private static void init(LifecycleEventContext ctx) {
ctx.log("EMELifeCycleListener: init()");
try {
SSLContext context = SSLContext.getInstance("SSL");
TrustManager[] trustManagerArray = {new EMEX509TrustManager()};
context.init(null, trustManagerArray, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
} catch (KeyManagementException ex) {
ctx.log("EMELifeCycleListener got KeyManagementException" + ex.getMessage());
} catch (NoSuchAlgorithmException ex) {
ctx.log("EMELifeCycleListener got NoSuchAlgorithmException" + ex.getMessage());
}
}

And if that does not work, try putting your init call under STARTUP_EVENT
if (LifecycleEvent.STARTUP_EVENT == event.getEventType()) {
ctx.log("EMELifeCycleListener: STARTUP_EVENT");
/*Do simple init of my TrustManager no matter which state we are in*/
init(ctx);
return;
}
[Message sent by forum member 'kumarjayanti' (kumarjayanti)]

http://forums.java.net/jive/thread.jspa?messageID=285278