Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
Arc::Service_JavaWrapper Class Reference

#include <javawrapper.h>

Inheritance diagram for Arc::Service_JavaWrapper:
Inheritance graph
[legend]
Collaboration diagram for Arc::Service_JavaWrapper:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Service_JavaWrapper (Arc::Config *cfg)
virtual ~Service_JavaWrapper (void)
virtual Arc::MCC_Status process (Arc::Message &, Arc::Message &)
 Service request processing routine.
virtual void AddSecHandler (Config *cfg, ArcSec::SecHandler *sechandler, const std::string &label="")
 Add security components/handlers to this MCC.
virtual bool RegistrationCollector (XMLNode &doc)
 Service specific registartion collector, used for generate service registartions.
virtual std::string getID ()
 Service may implement own service identitifer gathering method.

Protected Member Functions

Arc::MCC_Status make_fault (Arc::Message &outmsg)
Arc::MCC_Status java_error (JNIEnv *jenv, const char *str)
bool ProcessSecHandlers (Message &message, const std::string &label="") const
 Executes security handlers of specified queue.

Protected Attributes

Glib::Module * libjvm
JavaVM * jvm
char * classPath
jclass serviceClass
jobject serviceObj
std::map< std::string,
std::list< ArcSec::SecHandler * > > 
sechandlers_
 Set of labeled authentication and authorization handlers.

Static Protected Attributes

static Arc::Logger logger
 Logger object used to print messages generated by this class.

Detailed Description

Definition at line 16 of file javawrapper.h.


Constructor & Destructor Documentation

Definition at line 26 of file javawrapper.cpp.

  : Service(cfg),
    libjvm(NULL),
    jvm(NULL),
    classPath(NULL) {
    std::string path = "-Djava.class.path=" + (std::string)((*cfg)["ClassPath"]);
    std::string class_name = (std::string)(*cfg)["ClassName"];
    logger.msg(Arc::VERBOSE, "config: %s, class name: %s", path, class_name);
    JNIEnv *jenv = NULL;
    JavaVMInitArgs jvm_args;
    JavaVMOption options[1];
    /* Initiliaze java engine */
    Glib::ModuleFlags flags = Glib::ModuleFlags(0);
    libjvm = new Glib::Module("libjvm.so", flags);
    if (!*libjvm) {
        logger.msg(Arc::ERROR,
                 "libjvm.so not loadable - check your LD_LIBRARY_PATH");
       return;
    }
    void* myJNI_GetDefaultJavaVMInitArgs;
    libjvm->get_symbol("JNI_GetDefaultJavaVMInitArgs",
                     myJNI_GetDefaultJavaVMInitArgs);
    void* myJNI_CreateJavaVM;
    libjvm->get_symbol("JNI_CreateJavaVM", myJNI_CreateJavaVM);
    if (myJNI_GetDefaultJavaVMInitArgs == NULL || myJNI_CreateJavaVM == NULL) {
        logger.msg(Arc::ERROR,
                 "libjvm.so does not contain the expected symbols");
       return;
    }
    ((jint(*)(void*))myJNI_GetDefaultJavaVMInitArgs)(&jvm_args);
    jvm_args.version = JNI_VERSION_1_2;
    jvm_args.nOptions = 1;
    classPath = strdup(path.c_str());
    options[0].optionString = classPath;
    options[0].extraInfo = NULL;
    // "-Djava.class.path=.:/home/szferi/arc1/src/services/echo_java/:/home/szferi/arc1/java/arc.jar";
    jvm_args.options = options;
    jvm_args.ignoreUnrecognized = JNI_FALSE;
    ((jint(*)(JavaVM**, void**, void*))myJNI_CreateJavaVM)(&jvm, (void **)&jenv,
                                                    &jvm_args);
    logger.msg(Arc::VERBOSE, "JVM started");
    
    /* Find and construct class */
    serviceClass = jenv->FindClass(class_name.c_str());
    if (serviceClass == NULL) {
        logger.msg(Arc::ERROR, "There is no service: %s in your java class search path", class_name);
        if (jenv->ExceptionOccurred()) {
            jenv->ExceptionDescribe();
        }
        return;
    }
    jmethodID constructorID = jenv->GetMethodID(serviceClass, "<init>", "()V");
    if (constructorID == NULL) {
        logger.msg(Arc::ERROR, "There is no constructor function");
        if (jenv->ExceptionOccurred()) {
            jenv->ExceptionDescribe();
        }
        return;
    }
    serviceObj = jenv->NewObject(serviceClass, constructorID);
    logger.msg(Arc::VERBOSE, "%s constructed", class_name);
}

Here is the call graph for this function:

Definition at line 89 of file javawrapper.cpp.

                                              {
    logger.msg(Arc::VERBOSE, "Destroy jvm"); 
    if (jvm)
        jvm->DestroyJavaVM();
    if (libjvm)
        delete libjvm;
    if (classPath)
        free(classPath);
}

Here is the call graph for this function:


Member Function Documentation

void Arc::Service::AddSecHandler ( Config cfg,
ArcSec::SecHandler sechandler,
const std::string &  label = "" 
) [virtual, inherited]

Add security components/handlers to this MCC.

For more information please see description of MCC::AddSecHandler

Definition at line 14 of file Service.cpp.

                                                                                           {
    if(sechandler) {
        sechandlers_[label].push_back(sechandler); //need polishing to put the SecHandlerFactory->getinstance here
        XMLNode cn = (*cfg)["SecHandler"];
        Config cfg_(cn);
    }
}

Here is the caller graph for this function:

virtual std::string Arc::Service::getID ( ) [inline, virtual, inherited]

Service may implement own service identitifer gathering method.

This method return identifier of service which is used for registering it Information Services.

Reimplemented in ARex::ARexService.

Definition at line 69 of file Service.h.

{ return ""; };
Arc::MCC_Status Arc::Service_JavaWrapper::java_error ( JNIEnv *  jenv,
const char *  str 
) [protected]

Definition at line 111 of file javawrapper.cpp.

                                                                           {
    std::cerr << str << std::endl;
    if (jenv->ExceptionOccurred()) {
        jenv->ExceptionDescribe();
    }
    /* Cleanup */
    jvm->DetachCurrentThread();
    return Arc::MCC_Status(Arc::GENERIC_ERROR);
}

Here is the caller graph for this function:

Definition at line 99 of file javawrapper.cpp.

{
    Arc::PayloadSOAP* outpayload = new Arc::PayloadSOAP(Arc::NS(),true);
    Arc::SOAPFault* fault = outpayload->Fault();
    if(fault) {
        fault->Code(Arc::SOAPFault::Sender);
        fault->Reason("Failed processing request");
    };
    outmsg.Payload(outpayload);
    return Arc::MCC_Status();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Service request processing routine.

Implements Arc::MCCInterface.

Definition at line 121 of file javawrapper.cpp.

{
    JNIEnv *jenv = NULL;
    
    /* Attach to the current java engine thread */
    jvm->AttachCurrentThread((void **)&jenv, NULL);
    /* Get the process function of service */
    jmethodID processID = jenv->GetMethodID(serviceClass, "process", "(Lnordugrid/arc/SOAPMessage;Lnordugrid/arc/SOAPMessage;)Lnordugrid/arc/MCC_Status;");
    if (processID == NULL) {
        return java_error(jenv, "Cannot find process method of java class");
    }
    /* convert inmsg and outmsg to java objects */
    Arc::SOAPMessage *inmsg_ptr = NULL;
    Arc::SOAPMessage *outmsg_ptr = NULL;
    try {
        inmsg_ptr = new Arc::SOAPMessage(inmsg);
        outmsg_ptr = new Arc::SOAPMessage(outmsg);
    } catch(std::exception& e) { };
    if(!inmsg_ptr) {
        logger.msg(Arc::ERROR, "input is not SOAP");
        return make_fault(outmsg);
    };
    if(!outmsg_ptr) {
        logger.msg(Arc::ERROR, "output is not SOAP");
        return make_fault(outmsg);
    };

    jclass JSOAPMessageClass = jenv->FindClass("nordugrid/arc/SOAPMessage");
    if (JSOAPMessageClass == NULL) {
        return java_error(jenv, "Cannot find SOAPMessage object");
    }
    /* Get the constructor of java object */
    jmethodID constructorID = jenv->GetMethodID(JSOAPMessageClass, "<init>", "(I)V");
    if (constructorID == NULL) {
        return java_error(jenv, "Cannot find constructor function of message");
    }
    /* Convert C++ object to Java objects */
    jobject jinmsg = jenv->NewObject(JSOAPMessageClass, constructorID, (jlong)((long int)inmsg_ptr));
    if (jinmsg == NULL) {
        return java_error(jenv, "Cannot convert input message to java object");
    }
    jobject joutmsg = jenv->NewObject(JSOAPMessageClass, constructorID, (jlong)((long int)outmsg_ptr));
    if (jinmsg == NULL) {
        return java_error(jenv, "Cannot convert output message to java object");
    }
    /* Create arguments for java process function */
    jvalue args[2];
    args[0].l = jinmsg;
    args[1].l = joutmsg;
    /* Call the process method of Java object */
    jobject jmcc_status = jenv->CallObjectMethodA(serviceObj, processID, args);
    if (jmcc_status == NULL) {
        return java_error(jenv, "Error in call process function of java object");
    }
    /* Get SWIG specific getCPtr function of Message class */
    jmethodID msg_getCPtrID = jenv->GetStaticMethodID(JSOAPMessageClass, "getCPtr", "(Lnordugrid/arc/SOAPMessage;)J");
    if (msg_getCPtrID == NULL) {
        return java_error(jenv, "Cannot find getCPtr method of java Message class");
    }
    /* Get Java MCC_Status class */
    jclass JMCC_StatusClass = jenv->FindClass("nordugrid/arc/MCC_Status");
    if (JMCC_StatusClass == NULL) {
        logger.msg(Arc::ERROR, "Cannot find MCC_Status object");
        /* Cleanup */
        jvm->DetachCurrentThread();
        return Arc::MCC_Status(Arc::GENERIC_ERROR);
    }
    /* Get SWIG specific getCPtr function of MCC_Status class */
    jmethodID mcc_status_getCPtrID = jenv->GetStaticMethodID(JMCC_StatusClass, "getCPtr", "(Lnordugrid/arc/MCC_Status;)J");
    if (mcc_status_getCPtrID == NULL) {
        return java_error(jenv, "Cannot find getCPtr method of java MCC_Status class");
    }
    
    /* Convert Java status object to C++ class */
    jlong mcc_status_addr = jenv->CallStaticLongMethod(JMCC_StatusClass, mcc_status_getCPtrID, jmcc_status);
    if (!mcc_status_addr) {
        logger.msg(ERROR, "Java object returned NULL status");
        return MCC_Status(GENERIC_ERROR);
    }
    Arc::MCC_Status status(*((Arc::MCC_Status *)(long)mcc_status_addr));
    /* Convert Java output message object to C++ class */
    jlong outmsg_addr = jenv->CallStaticLongMethod(JSOAPMessageClass, msg_getCPtrID, joutmsg);
     
    Arc::SOAPMessage *outmsg_ptr2 = (Arc::SOAPMessage *)(long)outmsg_addr;
    /* std::string xml;
    outmsg_ptr2->Payload()->GetXML(xml);   
    std::cout << xml << std::endl; */
    Arc::PayloadSOAP *pl = new Arc::PayloadSOAP(*(outmsg_ptr2->Payload()));
    outmsg.Payload((MessagePayload *)pl);
    // XXX: how to handle error?
    /* Detach from the Java engine */
    jvm->DetachCurrentThread();
    return status;
}

Here is the call graph for this function:

bool Arc::Service::ProcessSecHandlers ( Message message,
const std::string &  label = "" 
) const [protected, inherited]

Executes security handlers of specified queue.

For more information please see description of MCC::ProcessSecHandlers

Definition at line 22 of file Service.cpp.

                                                                              {
    std::map<std::string,std::list<ArcSec::SecHandler*> >::const_iterator q = sechandlers_.find(label);
    if(q == sechandlers_.end()) {
        logger.msg(DEBUG, "No security processing/check requested for '%s'", label);
        return true;
    }

    std::list<ArcSec::SecHandler*>::const_iterator h = q->second.begin();
    for(;h!=q->second.end();++h) {
        const ArcSec::SecHandler* handler = *h;
        if(handler) if(!(handler->Handle(&message))) {
            logger.msg(DEBUG, "Security processing/check for '%s' failed", label);
            return false;
        }
    }
    logger.msg(DEBUG, "Security processing/check for '%s' passed", label);
    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool Arc::Service::RegistrationCollector ( XMLNode doc) [virtual, inherited]

Service specific registartion collector, used for generate service registartions.

In implemented service this method should generate GLUE2 document with part of service description which service wishes to advertise to Information Services.

Reimplemented in ARex::ARexService, ISIS::ISIService, GridScheduler::GridSchedulerService, Echo::Service_Echo, ArcSec::Charon, Paul::PaulService, ArcSec::Service_Delegation, SPService::Service_SP, ArcSec::Service_SLCS, Hopi::Hopi, and Arc::Service_PythonWrapper.

Definition at line 41 of file Service.cpp.

{
    logger.msg(WARNING, "Empty registration collector");
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 20 of file javawrapper.h.

JavaVM* Arc::Service_JavaWrapper::jvm [protected]

Definition at line 19 of file javawrapper.h.

Glib::Module* Arc::Service_JavaWrapper::libjvm [protected]

Definition at line 18 of file javawrapper.h.

Logger object used to print messages generated by this class.

Reimplemented from Arc::Service.

Definition at line 26 of file javawrapper.h.

std::map<std::string,std::list<ArcSec::SecHandler*> > Arc::Service::sechandlers_ [protected, inherited]

Set of labeled authentication and authorization handlers.

MCC calls sequence of handlers at specific point depending on associated identifier. in most aces those are "in" and "out" for incoming and outgoing messages correspondingly.

Definition at line 40 of file Service.h.

Definition at line 21 of file javawrapper.h.

Definition at line 22 of file javawrapper.h.


The documentation for this class was generated from the following files: