#include #include // we want to use the CNI #include #include // we want to use some java classes #include #include #include #include #include #include #include /* * This function is registered as a handler for HTTP methods and will * therefore be invoked for all GET requests (and others). Regardless * of the request type, this function simply sends a message to * STDERR (which httpd redirects to logs/error_log). A real module * would do *alot* more at this point. */ static int anonymize_request(request_rec *r) { using namespace java::lang; try { JvCreateJavaVM(NULL); JvAttachCurrentThread(NULL, NULL); String *message = JvNewStringLatin1("Hello from C++"); JvInitClass(&System::class$); System::out->println(message); System::err->println(JvNewStringLatin1("Hello from CNI")); //////////////////////////Add for test////////////////// String *className = JvNewStringLatin1("single.Sigclass"); JvInitClass(&Class::class$); Class *cl = Class::forName(className); String *methodName = JvNewStringLatin1("main"); Class *stringArrayClass=JvNewObjectArray(0,(new String())->getClass(),NULL)->getClass(); typedef JArray ClassArray; ClassArray *parameterTypes = (ClassArray *)JvNewObjectArray(1, (new Class())->getClass(),stringArrayClass); JArray* m=cl->getMethods(); reflect::Method **tl =(reflect::Method **)elements(m); typedef JArray StringArray; // char** argv = {"news", "got"}; StringArray *stringArray = (StringArray *)JvNewObjectArray(0,(new String())->getClass(),NULL); jobjectArray parameters = JvNewObjectArray(1,stringArrayClass,stringArray); tl[0]->invoke(NULL,parameters); JvDetachCurrentThread(); } catch (Throwable *t) { System::err->println(JvNewStringLatin1("Unhandled Java exception:")); t->printStackTrace(); } // Send a message to stderr (apache redirects this to the error log) fprintf(stderr,"apache1.3_mod_permis: A request was made, Hello from CNI 2. \n"); // We need to flush the stream so that the message appears right away. // Performing an fflush() in a production system is not good for // performance - don't do this for real. fflush(stderr); // Return DECLINED so that the Apache core will keep looking for // other modules to handle this request. This effectively makes // this module completely transparent. return DECLINED; } module MODULE_VAR_EXPORT mod_permis = { STANDARD_MODULE_STUFF, NULL, /* initializer */ NULL, /* dir config creater */ NULL, /* dir merger --- default is to override */ NULL, /* server config */ NULL, /* merge server configs */ NULL, /* command table */ NULL, /* handlers */ NULL, /* filename translation */ NULL, /* check_user_id */ NULL, /* check auth */ NULL, /* check access */ NULL, /* type_checker */ anonymize_request, /* fixups */ NULL, /* logger */ NULL, /* header parser */ NULL, /* child_init */ NULL, /* child_exit */ NULL /* post read-request */ };