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