Exemple #1
0
 def dispatch(self, protocol, message, inbackground = 1):
     """
     Receives the raw messages from the protocol implementations and passes them
     somewhere depending on the type.
     
     Message is passed to the L{messagewrapper.MessageWrapper.unwrapG4dsMessage} function for removing
     the g4ds-"header" and gain the actual information. Afterwards, in case of an encrypted message
     it is passed to the private function L{_handleDecryptionAndValidation} which will thereupon unwrap and decrypt
     the message. Then, the message is passed and it is identified, whether there is a service or a
     control message contained. Depending on this, the content is either passed to the 
     L{g4dsconfigurationcontroller.ControlMessageDispatcher.dispatch} or to the 
     L{serviceintegrator.ServiceIntegrator.dispatch}.
     
     @param protocol: Protocol as identified for the incoming message
     @type protocol: C{String}
     @param message: String representation of the XML message
     @type message: C{String}
     """
     if inbackground:
         import thread
         thread.start_new_thread(self.dispatch,(protocol, message, 0))
         return
     
     from errorhandling import G4dsException
     try:
         from g4dslogging import getDefaultLogger, COMMUNICATION_INCOMING_MSG, COMMUNICATION_INCOMING_MSG_DETAILS
         getDefaultLogger().newMessage(COMMUNICATION_INCOMING_MSG, 'New incoming message')
         firstmessage = message
         message, rootnode = getMessageWrapper().unwrapG4dsMessage(message)
         
         message, senderidDec, communityid = self._handleDecryptionAndValidation(message, protocol)
         
         message, mid, senderid, refid = getMessageWrapper().unwrapG4dsPlain(message)
         getDefaultLogger().newMessage(COMMUNICATION_INCOMING_MSG_DETAILS, '-- MSG ID %s | SENDER %s' %(mid, senderid))
         getDefaultLogger().newMessage(COMMUNICATION_INCOMING_MSG_DETAILS, '-- Size of msg (brutto | netto): %d | %d Bytes' %(len(firstmessage), len(message)))
         getMessageContextController().addMessage(mid)
         getMessageContextController().addValue(mid, 'refid', refid)
         getMessageContextController().addValue(mid, 'senderid', senderid)
         getMessageContextController().addValue(mid, 'communityid', communityid)
         
         root = xml.dom.ext.reader.Sax2.FromXml(message)
 
         childnode = root.childNodes[1]
         if childnode.nodeType == Node.ELEMENT_NODE:
             stio = StringIO()
             xml.dom.ext.PrettyPrint(childnode, stio)
             xmlSubTreeString = stio.getvalue()
             stio.close()
             
             if childnode.nodeName == xmlconfig.g4ds_control_node:
                 id, name, data = getMessageWrapper().unwrapControlMessage(xmlSubTreeString)
                 getControlMessageDispatcher().dispatch(childnode, id, name, data, mid)
                 
             if childnode.nodeName == xmlconfig.g4ds_service_node:
                 id, name, data = getMessageWrapper().unwrapServiceMessage(xmlSubTreeString)
                 getServiceIntegrator().dispatch(id, name, data, mid)
     except G4dsException, msg:
         from g4dslogging import getDefaultLogger, COMMUNICATION_INCOMING_ERROR
         getDefaultLogger().newMessage(COMMUNICATION_INCOMING_ERROR, msg)
Exemple #2
0
 def registerClient(self, serviceid, clientcallback):
     """
     A new client has connected through C/S facilities.
     
     Let's go and register it with the service integrator.
     """
     from serviceintegrator import getServiceIntegrator
     getServiceIntegrator().registerClient(serviceid, clientcallback)
Exemple #3
0
def testFullCommunication():
    from messagehandler import getGlobalOutgoingMessageHandler
    outgoing = getGlobalOutgoingMessageHandler()

    from serviceintegrator import getServiceIntegrator
    getServiceIntegrator().sendMessage("M854612", "S10001", "IOIDS", "<ioids>test it app</ioids>")
    import g4dsconfigurationcontroller
    g4dsconfigurationcontroller.getOutgoingControlMessagesHandler().sendMessage(
    "M854612", g4dsconfigurationcontroller.CONTROL_SUBSYSTEM_MEMBERS, 
        "Member managing", "<routing><gateway><add>bla</add></gateway></routing>")
    
    g4dsconfigurationcontroller.getOutgoingControlMessagesHandler().sendMessage(
    "M854612", g4dsconfigurationcontroller.CONTROL_ROUTER, 
        "Forward message", "<routing><gateway><add>bla</add></gateway></routing>")
    # just for testing purpose the old version, where we directly connect to the global outing message handler and we
    # have to define an endpoint. Actually, the service integrator should be used and only a member id should be 
    # provided. Endpoints are assembled automatically.
    #outgoing.sendServiceMessage("E393454", "S10002", "PLAIN TEST",  "plain old logging :)")      # "E770313"
    raw_input("waiting :)")
Exemple #4
0
 def newMessage(self, serviceid, destinationMember, destinationCommunity, message):
     """
     Sends a new message through the service integrator.
     """
     from serviceintegrator import getServiceIntegrator
     getServiceIntegrator().sendMessage(destinationMember, serviceid, 'test service', message, destinationCommunity)
Exemple #5
0
 def unregisterClient(self, serviceid):
     """
     Disconnects a client from a certain service.
     """
     from serviceintegrator import getServiceIntegrator
     getServiceIntegrator().unregisterClient(serviceid)