Hi , i'm new in this mailing list, i've started recently to integrate tomcat in some of my applications ( i found a lot easyer to manage tomcat inside a big servlet than viceversa), as early adopted java developer i hope to help a bit in tomcat development when i become a bit more expert, at this moment my tomcat integration it's stuck with the AprLifecycleListener class, i've compiled, installed apr ,jni, ssl and so fort documentation is a bit tricky on that... expecially for path+external variables handlings and compiling configurations, i really hope to have time to build a guidelines for everything about that...
...anyway i'll go to explain my issue :

public class AprLifecycleListener

it's a class which load jni component and check for apr existance and versionm,

at first request it call  :

  private static void init()


then set a boolean private and unaccessible variable which avoid successive calls

   if (aprInitialized) {
            return;
        }


my problem is that this class seems to not recognize apr in my computer.. i don't know exactly when this is called, anyway if i overload this class and force to call the init() again within my overloaded class it works...



i don't have a ready to test class , it will take some time to produce, but if really needed i'll do..



anyway this is a test case i've done..

-------- this  (with my overloaded apr-Loader class ):

    public static void main(String[] args) throws InterruptedException {
VarsTrackingHttpServer varsTrackingHttpServer = new VarsTrackingHttpServer(); //System.out.println("ORIGINAL APR AVAILABLE? " + AprLifecycleListener.isAprAvailable()); System.out.println("OVERLOADED APR CLASS AVAILABLE?" + testAprLifecycleListener.isAprAvailable());

        varsTrackingHttpServer.start();
        Thread.sleep(1500000);
        varsTrackingHttpServer.stop();
        varsTrackingHttpServer.waitStopped(100);

    }
----------------- produce this :
init()__ STARTED
init()__ 1
---error, aprInitialized=true
Loaded APR based Apache Tomcat Native library 1.1.24.
APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
initializeWebServer()__start
OVERLOADED APR CLASS AVAILABLE?true
tomcat basedir = /tmp
SERVER TMPDIR = /tmp
APRAVAILABLE?::true
FastTomcat::STARTING()::Apache Tomcat/7.0.27
Jun 22, 2012 8:11:16 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-apr-8087"]


---------- but this (without the overloaded class called)
    public static void main(String[] args) throws InterruptedException {


VarsTrackingHttpServer varsTrackingHttpServer = new VarsTrackingHttpServer(); System.out.println("ORIGINAL APR AVAILABLE? " + AprLifecycleListener.isAprAvailable()); //System.out.println("OVERLOADED APR CLASS AVAILABLE?" + testAprLifecycleListener.isAprAvailable());

        varsTrackingHttpServer.start();
        Thread.sleep(1500000);
        varsTrackingHttpServer.stop();
        varsTrackingHttpServer.waitStopped(100);

    }

------ produce this :

initializeWebServer()__start
ORIGINAL APR AVAILABLE? false
tomcat basedir = /tmp
SERVER TMPDIR = /tmp
APRAVAILABLE?::false
FastTomcat::STARTING()::Apache Tomcat/7.0.27
Jun 22, 2012 8:10:32 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8087"]



--------------------- and if i call the standard class (it will fail to load apr even if i call twice, because the boolean "initialized" avoid successive calls) than i call my overloaded class ( it will load apr correctly) , than also the original class recognize apr as loaded! (HERE DOWN THE EXAMPLE..) so what's the trick? seems that the AprLifecycleListener class is being called in a moment when apr is not available and then there is no possibility to re-call it??


---------------- finally this :
    public static void main(String[] args) throws InterruptedException {

VarsTrackingHttpServer varsTrackingHttpServer = new VarsTrackingHttpServer(); System.out.println("ORIGINAL APR AVAILABLE? " + AprLifecycleListener.isAprAvailable()); System.out.println("OVERLOADED APR CLASS AVAILABLE?" + testAprLifecycleListener.isAprAvailable()); System.out.println("ORIGINAL APR AVAILABLE? " + AprLifecycleListener.isAprAvailable());

        varsTrackingHttpServer.start();
        Thread.sleep(1500000);
        varsTrackingHttpServer.stop();
        varsTrackingHttpServer.waitStopped(100);

    }

---------------- PRODUCE :
---error, aprInitialized=true
ORIGINAL APR AVAILABLE? false
init()__ STARTED
init()__ 1
Loaded APR based Apache Tomcat Native library 1.1.24.
APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
initializeWebServer()__start
OVERLOADED APR CLASS AVAILABLE?true
ORIGINAL APR AVAILABLE? true
tomcat basedir = /tmp
SERVER TMPDIR = /tmp
APRAVAILABLE?::true
FastTomcat::STARTING()::Apache Tomcat/7.0.27
Jun 22, 2012 8:08:51 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-apr-8087"]



this is my very dumb class which overload apr..



import org.apache.catalina.core.AprLifecycleListener;
import org.apache.tomcat.jni.Library;
import org.apache.tomcat.util.ExceptionUtils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.jni.Library;
import org.apache.tomcat.jni.SSL;
import org.apache.tomcat.util.ExceptionUtils;
import org.apache.tomcat.util.res.StringManager;
import org.eclipse.jdt.internal.compiler.ast.SuperReference;

import java.lang.reflect.Method;
import java.util.logging.Logger;

public class testAprLifecycleListener extends AprLifecycleListener {


    private static final Logger log = Logger.getLogger("none");


    public static boolean isAprAvailable() {
//        terminateAPR();
      /*  return AprLifecycleListener.isAprAvailable();*/

        synchronized (lock) {
            init();
        }
        return aprAvailable;
    }

    private static void init()
    {
        int major = 0;
        int minor = 0;
        int patch = 0;
        int apver = 0;
int rqver = TCN_REQUIRED_MAJOR * 1000 + TCN_REQUIRED_MINOR * 100 + TCN_REQUIRED_PATCH; int rcver = TCN_REQUIRED_MAJOR * 1000 + TCN_REQUIRED_MINOR * 100 + TCN_RECOMMENDED_PV;

        System.out.println("init()__ STARTED ");
     /*  if (aprInitialized) {
            return;
        }*/
        aprInitialized = true;
        System.err.println("---error, aprInitialized="+aprInitialized);
        System.out.println("init()__ 1 ");
        try {
            String methodName = "initialize";
            Class<?> paramTypes[] = new Class[1];
            paramTypes[0] = String.class;
            Object paramValues[] = new Object[1];
            paramValues[0] = null;
Class<?> clazz = Class.forName("org.apache.tomcat.jni.Library");
            Method method = clazz.getMethod(methodName, paramTypes);
            method.invoke(null, paramValues);
            major = clazz.getField("TCN_MAJOR_VERSION").getInt(null);
            minor = clazz.getField("TCN_MINOR_VERSION").getInt(null);
            patch = clazz.getField("TCN_PATCH_VERSION").getInt(null);
            apver = major * 1000 + minor * 100 + patch;
        } catch (Throwable t) {
            t = ExceptionUtils.unwrapInvocationTargetException(t);
            ExceptionUtils.handleThrowable(t);
            System.err.println(sm.getString("aprListener.aprInit",
                    System.getProperty("java.library.path")));
            return;
        }
        if (apver < rqver) {
System.err.println(sm.getString("aprListener.tcnInvalid", major + "."
                    + minor + "." + patch,
                    TCN_REQUIRED_MAJOR + "." +
                            TCN_REQUIRED_MINOR + "." +
                            TCN_REQUIRED_PATCH));
            try {
                // Terminate the APR in case the version
                // is below required.
                terminateAPR();
            } catch (Throwable t) {
                t = ExceptionUtils.unwrapInvocationTargetException(t);
                ExceptionUtils.handleThrowable(t);
                System.err.println("---error, PROBLEM TERMINATING APR!");
            }
            return;
        }
        if (apver < rcver) {
System.err.println(sm.getString("aprListener.tcnVersion", major + "."
                    + minor + "." + patch,
                    TCN_REQUIRED_MAJOR + "." +
                            TCN_RECOMMENDED_MINOR + "." +
                            TCN_RECOMMENDED_PV));
        }

        System.err.println(sm.getString("aprListener.tcnValid", major + "."
                + minor + "." + patch));

        // Log APR flags
        System.err.println(sm.getString("aprListener.flags",
                Boolean.valueOf(Library.APR_HAVE_IPV6),
                Boolean.valueOf(Library.APR_HAS_SENDFILE),
                Boolean.valueOf(Library.APR_HAS_SO_ACCEPTFILTER),
                Boolean.valueOf(Library.APR_HAS_RANDOM)));
        aprAvailable = true;
    }


    private static void terminateAPR()
            throws ClassNotFoundException, NoSuchMethodException,
            IllegalAccessException, InvocationTargetException
    {
        String methodName = "terminate";
        Method method = Class.forName("org.apache.tomcat.jni.Library")
                .getMethod(methodName, (Class [])null);
        method.invoke(null, (Object []) null);
        aprAvailable = false;
        aprInitialized = false;
        sslInitialized = false; // Well we cleaned the pool in terminate.
        sslAvailable = false; // Well we cleaned the pool in terminate.
        fipsModeActive = false;
    }

}


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to