Integrating With Fusion Application Using Services (Python: urllib2)

Fusion Applications provides Web services that allow external systems to integrate with Fusion Applications. There are two types of services: ADF services and composite services. ADF services are created for a logical business object and provide functionality to access and manipulate these objects. The composite services are mostly process oriented and provide an orchestration of multiple steps.

Information about the web services provided by Fusion Applications is hosted in Oracle Enterprise Repository (OER). The information provided by OER can be used to understand the functionality provided by the service and how the service can be called.

This series of articles describes how one can invoke SOAP web services provided by Fusion Applications using various technologies. In this article we will cover how to invoke a Fusion Application web service using urllib2 for Python.

Prerequisites

The reader is expected be familiar with the Python and as such the details on creating the development environment and basic development are not covered.

Implementing Web Service Call

Python is a widely used programming language; it is used e.g. by Oracle JDeveloper when creating domains. There are various libraries that can be used to make http requests, for demonstration purposes we use urllib2:

import urllib2, base64
username='username'
password='password'
 
# Construct xml payload, which is used to invoke the service. In the example case it is a "hard coded" string.
envelope = """<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                 <soap:Body>
                   <findRule xmlns="http://xmlns.oracle.com/apps/incentiveCompensation/cn/creditSetup/creditRule/creditRuleService/types/">
                     <findCriteria>
                       <fetchStart xmlns="http://xmlns.oracle.com/adf/svc/types/">0</fetchStart>
                       <fetchSize xmlns="http://xmlns.oracle.com/adf/svc/types/">-1</fetchSize>
                       <filter xmlns="http://xmlns.oracle.com/adf/svc/types/">
                         <group>
                           <upperCaseCompare>false</upperCaseCompare>
                           <item>
                             <upperCaseCompare>false</upperCaseCompare>
                             <attribute>RuleId</attribute>
                             <operator>=</operator>
                             <value>300000000851162</value>
                           </item>
                         </group>
                       </filter>
                       <excludeAttribute xmlns="http://xmlns.oracle.com/adf/svc/types/">false</excludeAttribute>
                     </findCriteria>
                     <findControl>
                       <retrieveAllTranslations xmlns="http://xmlns.oracle.com/adf/svc/types/">false</retrieveAllTranslations>
                     </findControl>
                   </findRule>
                 </soap:Body>
               </soap:Envelope>"""
# Construct the base 64 encoded string used as the credentials for the service call
creadentials = base64.encodestring('%s:%s' % (username, password))[:-1]
authorization =  "Basic %s" % creadentials
# Create and register opener, proxy needed when behind firewall
opener = urllib2.build_opener(urllib2.HTTPHandler(), urllib2.HTTPSHandler(), urllib2.ProxyHandler({'https': 'proxyhost:proxyport'}))
urllib2.install_opener(opener)
# Create request for the service call
request = urllib2.Request("https://host:port/icCnSetupCreditRulesPublicService/CreditRuleService")
# Configure the request content type to be xml
request.add_header("Content-Type", 'text/xml;charset=UTF-8')
# Configure the request authentication in header with base 64 encoded a user name and a password
request.add_header("Authorization", authorization)
# Set the SOAP action to be invoked; while the call works without this the value is expected to be set based on standards
request.add_header("SOAPAction", 'http://xmlns.oracle.com/apps/incentiveCompensation/cn/creditSetup/creditRule/creditRuleService/findRule') 
# Write the xml payload to the request.
request.add_data(envelope)
# Execute the request
handle = urllib2.urlopen(request)
# Get the response and process it, in this example we simply print out the response
content = handle.read()
print content

The above code does the following:
  1. Construct xml payload, which is used to invoke the service. In the example case it is a "hard coded" string
  2. Construct the base 64 encoded string used as the credentials for the service call
  3. Create and register opener, proxy needed when behind firewall
  4. Create request to be used to call the service
  5. Configure the request content type to be xml
  6. Configure the request header with the authentication information
  7. Set the SOAP action to be invoked; while the call works without this the value is expected to be set based on standards
  8. Write the xml payload to the request and execute the request
  9. Get the response and process it, in this example we simply print out the response

Summary

In this article we covered an example using urllib2 for Python to integrate with Fusion Applications using web services. In future articles other technologies for invoking Fusion Applications web services will be covered.

References

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Follow us on twitter Fusion Applications Extensibility, Customizations and Integration forum Fusion Applications Dev Relations YouTube Channel
This blog offers news, tips and information for developers building extensions, customizations and integrations for Oracle Fusion Applications.

Search

Categories
Archives
« August 2015
SunMonTueWedThuFriSat
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
     
Today