The Rubis spool daemonThe Rubis Server layoutThe service ports dispatcher

Contents

Index

The service ports dispatcher

The Rubis web service ports are dispatched with the help of the ZSI Python module. The following Python program is located in the cgi-bin directory of the Apache server on <enrst-schreoder.uni.lu> and can be accessed via the http://ernst-schroeder.uni.lu/cgi-bin/rubisServer-1.1-0.py URL.

The three Decision-Deck standard service ports, namely hello, submitProblem, and requestSolution, are implemented as Python functions returning a structured answer containing the required messages as mentioned in Section Client View.

#!/usr/bin/python
# rubisServer.py
# RB March 2008
###########################

## hello port implementation
1: def hello():
2:     return {"message":
3:     """
4:     *********************************************
5:     * This is the Ernst-Schroeder Apache Server *
6:     * of the University of Luxembourg.          *
7:     * Welcome to the Rubis Web services.        *
8:     * RB March 2008, version 1.1-0              *
9:     *********************************************
10:    """}

## submitProblem port implementation
11: def submitProblem(**kw):
12:     import random, string, codecs
13:     try: # try saving of submitted problem file
14: 	    chars = string.letters+string.digits
15:         ticket = ''.join([random.choice(chars) for i in range(16)])
16:         fileName = '/var/rubisServerData/JobSpooler/problem-'+ticket+'.xml'
17:         fileOUT = codecs.open(fileName,'w',encoding='utf-8')
18:         fileOUT.write(unicode(kw['problemFile']))
19:         fileOUT.close()
20:         msg = 'The problem submission was successful !\n'
21:         return {"message": msg, "ticket": ticket}
22:     except:
23:         return {"message": "The problem submisson was unsuccessful", 
                "ticket":None}

## requestSolution port impementation
24: def requestSolution(**kw):
25:     ticket = kw['ticket']
26:     answer = {}   
27:     try: # check availability of solution file
28:         fileName = '/var/rubisServerData/Solutions/solution-'\
29:                     +str(ticket)+'.xml'
30:         fileIN = open(fileName,'r')
31:         answer['solution'] = fileIN.read()
32:         fileIN.close()
33:         msg = "The solution request was successful.\n"
34:     except:
35:         msg =  "Solution not available !!"
36:     answer['ticket'] = ticket
37:     answer['message'] = msg
39:     return answer

## CGI Python script
40: if __name__ == '__main__':
41:     import os, sys
42:     from ZSI import dispatch
43:     dispatch.AsCGI(rpc=True)

Lines 1-10 implement the hello server response.

Lines 11-23 implement the submitProblem port operation. In Line 15 first a 16 character long server ticket is generated and the XML encoded submitted problem file is written to the Problems directory with name problem-<ticket>.xml (see Figure 2). The answer containing a message and the actual response ticket is returned as port response.

Lines 24-39 implement the requestSolution port operation. If the solution is available in the Solutions directory, it is returned as port response, otherwise a message "Solution not available!!" is returned.

Lines 40-43 implement the corresponding SOAP rpc literal service as a CGI Python script using the Python ZSI module.


Raymond Bisdorff, June 2, 2008


The Rubis spool daemonThe Rubis Server layoutThe service ports dispatcherContentsIndex