python component in mule

13
Python Component In Mule The Python language has many similarities to Perl, C, and Java. However, there are some definite differences between the languages

Upload: ramakrishna-kapa

Post on 07-Jan-2017

131 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Python component in mule

Python Component In MuleThe Python language has many similarities to Perl, C, and Java. However, there are some definite differences between the languages

Page 2: Python component in mule

Python also allows the developer to configure interceptors and alter the values or references of particular properties in a script. Interceptors are configured to provide additional services to a message as it flows through a component. For example, a developer can configure an interceptor to execute scheduling or logging of a particular event while a message is being processed. The Python component also includes a custom interceptor which allows you to configure settings for Spring elements.

The Python script is generally executed at runtime (client-side request); the custom logic embedded in the script can be used to trigger an application to execute a database transaction, or modify your web-page interface.

Page 3: Python component in mule

Accessing Values in StringsPython does not support a character type;

these are treated as strings of length one, thus also considered a substring.

To access substrings, use the square brackets for slicing along with the index or indices to obtain your substring. For example −

#!/usr/bin/python var1 = 'Hello World!' var2 = "Python Programming" print "var1[0]: ", var1[0] print "var2[1:5]: ", var2[1:5]

Page 4: Python component in mule

Here is a set of small scripts, which demonstrate some features of Python programming.

# this is the first comment #! python # integer variables SPAM = 1 #! python print "Hello, Python" #! Python # string variable STRING = "# This is not a comment." print

STRING

Page 5: Python component in mule

#! Python # integer arith a=4 print a b=12+5 print b c=b%a print c

Page 6: Python component in mule

#! python

# input and operator if

x = int(raw_input("Please enter an integer: "))

if x < 0: x = 0 print 'Negative changed to zero' elif x == 0: print 'Zero' elif x == 1: print 'Single' else: print 'More'

Page 7: Python component in mule

! python

# range function

print range(10)

print range(5, 10)

print range(0, 10, 3)

a = ['Mary', 'had', 'a', 'little', 'lamb'] for i in range(len(a)): print i, a[i]

Page 8: Python component in mule

Create a New Project

Page 9: Python component in mule

Enter project name as demo_python click on finish

Page 10: Python component in mule

Drag components as shown in the below and configure Http

Page 11: Python component in mule

Drag python component and configure as below

Page 12: Python component in mule

Paste in script#! python

print "Hello, Python"

Page 13: Python component in mule

Run as Mule ApplicationHit the URL on browser:http://localhost:8081/python

Hello, Python is the output