Python component in mule

Post on 07-Jan-2017

131 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

Transcript

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

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.

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]

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

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

#! 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'

! 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]

Create a New Project

Enter project name as demo_python click on finish

Drag components as shown in the below and configure Http

Drag python component and configure as below

Paste in script#! python

print "Hello, Python"

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

Hello, Python is the output

top related