1 #!/usr/bin/env jython
2 #
3 # Listing 2
4 #
5 # Place this file in the module $MULE_HOME/lib/usr/article instead of
6 # in a .jar if you want to donkey punch it.
7
8
9 import org.mule as mule
10
11 import article.businessmodule as businessmodule
12 from businessmodule import BusinessObject
13
14 # Enable dynamic updates to the script:
15 reload(businessmodule)
16
17
18 class SampleMuleComponent(object):
19
20 # *** Public members ***
21
22 # Get a local reference - useful for testing outside of a Mule container:
23 def __init__(self, payload, log = None, eventContext = None, muleContext = None):
24 self.payload = payload
25 self.muleContext = muleContext
26 self.eventContext = eventContext
27 self.log = log
28 self.response = ''
29
30 def serviceRequest(self):
31 if self.eventContext is not None:
32 self.payload = self.eventContext.getMessage().getPayloadAsString()
33 method = self.eventContext.getMessage().getProperty('http.method')
34
35 self.log.info('processing method = '+method)
36
37 nStatus = 200 # OK
38 if method == 'GET':
39 self.response = BusinessObject().today()
40 else:
41 nStatus = 400 # Bad request
42 self.response = 'Invalid HTTP method called!'
43
44 responseMessage = mule.DefaultMuleMessage(self.response)
45 responseMessage.setIntProperty('http.status', nStatus)
46
47 return responseMessage
48