1 17 18 package org.apache.catalina.core; 19 20 21 import java.lang.reflect.Method ; 22 import org.apache.catalina.Lifecycle; 23 import org.apache.catalina.LifecycleEvent; 24 import org.apache.catalina.LifecycleListener; 25 import org.apache.catalina.util.StringManager; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 import java.lang.reflect.InvocationTargetException ; 30 31 32 33 42 43 public class AprLifecycleListener 44 implements LifecycleListener { 45 46 private static Log log = LogFactory.getLog(AprLifecycleListener.class); 47 48 51 protected StringManager sm = 52 StringManager.getManager(Constants.Package); 53 54 55 57 58 protected static final int REQUIRED_MAJOR = 1; 59 protected static final int REQUIRED_MINOR = 1; 60 protected static final int REQUIRED_PATCH = 3; 61 protected static final int RECOMMENDED_PV = 7; 62 63 64 protected static String SSLEngine = "on"; protected static boolean sslInitialized = false; 67 68 70 75 public void lifecycleEvent(LifecycleEvent event) { 76 77 if (Lifecycle.INIT_EVENT.equals(event.getType())) { 78 int major = 0; 79 int minor = 0; 80 int patch = 0; 81 try { 82 String methodName = "initialize"; 83 Class paramTypes[] = new Class [1]; 84 paramTypes[0] = String .class; 85 Object paramValues[] = new Object [1]; 86 paramValues[0] = null; 87 Class clazz = Class.forName("org.apache.tomcat.jni.Library"); 88 Method method = clazz.getMethod(methodName, paramTypes); 89 method.invoke(null, paramValues); 90 major = clazz.getField("TCN_MAJOR_VERSION").getInt(null); 91 minor = clazz.getField("TCN_MINOR_VERSION").getInt(null); 92 patch = clazz.getField("TCN_PATCH_VERSION").getInt(null); 93 } catch (Throwable t) { 94 if (!log.isDebugEnabled()) { 95 log.info(sm.getString("aprListener.aprInit", 96 System.getProperty("java.library.path"))); 97 } else { 98 log.debug(sm.getString("aprListener.aprInit", 99 System.getProperty("java.library.path")), t); 100 } 101 return; 102 } 103 if ((major != REQUIRED_MAJOR) || (minor != REQUIRED_MINOR) 104 || (patch < REQUIRED_PATCH)) { 105 log.error(sm.getString("aprListener.tcnInvalid", major + "." 106 + minor + "." + patch, REQUIRED_MAJOR + "." 107 + REQUIRED_MINOR + "." + REQUIRED_PATCH)); 108 } 109 if (patch < RECOMMENDED_PV) { 110 if (!log.isDebugEnabled()) { 111 log.info(sm.getString("aprListener.tcnVersion", major + "." 112 + minor + "." + patch, REQUIRED_MAJOR + "." 113 + REQUIRED_MINOR + "." + RECOMMENDED_PV)); 114 } else { 115 log.debug(sm.getString("aprListener.tcnVersion", major + "." 116 + minor + "." + patch, REQUIRED_MAJOR + "." 117 + REQUIRED_MINOR + "." + RECOMMENDED_PV)); 118 } 119 } 120 try { 121 initializeSSL(); 122 }catch ( Throwable t ) { 123 log.error(sm.getString("aprListener.sslInit",t.getMessage()),t); 124 } 125 } else if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType())) { 126 try { 127 String methodName = "terminate"; 128 Method method = Class.forName("org.apache.tomcat.jni.Library") 129 .getMethod(methodName, (Class [])null); 130 method.invoke(null, (Object []) null); 131 } catch (Throwable t) { 132 if (!log.isDebugEnabled()) { 133 log.info(sm.getString("aprListener.aprDestroy")); 134 } else { 135 log.debug(sm.getString("aprListener.aprDestroy"), t); 136 } 137 } 138 } 139 140 } 141 142 public static synchronized void initializeSSL() 143 throws ClassNotFoundException ,NoSuchMethodException , 144 IllegalAccessException ,InvocationTargetException { 145 146 if ("off".equalsIgnoreCase(SSLEngine) ) return; 147 if ( sslInitialized ) return; String methodName = "initialize"; 149 Class paramTypes[] = new Class [1]; 150 paramTypes[0] = String .class; 151 Object paramValues[] = new Object [1]; 152 paramValues[0] = "on".equalsIgnoreCase(SSLEngine)?null:SSLEngine; 153 Class clazz = Class.forName("org.apache.tomcat.jni.SSL"); 154 Method method = clazz.getMethod(methodName, paramTypes); 155 method.invoke(null, paramValues); 156 sslInitialized = true; 157 158 } 159 160 161 } 162 | Popular Tags |