Integrating With Fusion Application Using Services (Ruby)

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 Ruby on Rails.

Prerequisites

There are various frameworks available, in these examples we will use Savon and basic "net/https" call. In order to build the application you will need to install and configure "Ruby on Rails" development environment. The reader is expected be familiar with the "Ruby on Rails" and as such the details on creating the development environment and basic development are not covered. On high level to create the development environment you would follow these steps:

Implementing Web Service Call

Details for creating the base application details are not provided, the high level steps are:

  • Create application (rails new WsTest1)
  • Create controller (rails generate controller WsCallSample WsCall)
  • Set the root (remove public/index.html and modify the root property in config/routes.rb to 'WsCallSample#WsCall')
  • Add Savon to the application (Add "gem 'savon'" to app/Gemfile)

Next we will create a HTML form (in the example application under views/ws_call_sample/WsCall.html.erb) that allows user to enter the payload to be passed to the service, button to invoke the processing for Savon, button to invoke the processing for "net/https" call and text to display the results:

<HTML>
<HEAD>
<title>WsCallSample#WsCall</title>
</HEAD>
<BODY >
 
<form name="envelope" method="POST">
  <input type="hidden" name="INPUT_PAYLOAD" >
  <input type="hidden" name="OUTPUT_PAYLOAD" >
   <%= submit_tag "Invoke Savon", :name => "invokeSavon" %>
  <%= submit_tag "Invoke HttpRequest", :name => "invokeHttpRequest" %>
  <br>
  <table style="width:100%; font-size: small;" align=center>
    <tr>
      <td  align="left"><b>Input Payload</b></td>
      <td  align="left"><b>Output Payload</b></td>
    </tr>
    <tr>
      <td align="center"><textarea name="inputpayload" wrap="off" style="width:100%;height:100%" rows=30 ><%= params["inputpayload"] %></textarea></td>
      <td align="center"><textarea name="outputpayload" wrap="off" style="width:100%;height:100%" rows=30  ><%= params["xmlbody"] %></textarea></td>
    </tr>
  </table>
  <br>
</form>
</BODY>
</HTML>

Next  we update the controller (in the example application under controllers/ws_call_sample_controller.rb) to handle the submissions from the form:

require 'rubygems'
require 'nokogiri'
require 'rexml/document'
require "net/https"
require 'uri'
 
class WsCallSampleController < ApplicationController
  def WsCall
    username ="username";
    password ="password";
    input=params["inputpayload"];
 
    if params['invokeSavon']
      # Process submission when the invokeSavon button was pressed
      url = "https://host:port/icCnSetupCreditRulesPublicService/CreditRuleService?wsdl";
      
      # Create new instance of the Savon client using basic authentication
      client = Savon.client(wsdl: url, basic_auth: [username, password], ssl_verify_mode: :none )
 
      # Call the service with the envelope provided as input
      response = client.call(:on_fault, xml: input)
      
      # Parse the response to XML
      doc = Nokogiri::XML(response.to_xml  ,&:noblanks)
      s = doc.to_xml( indent:2, indent_text:" " )
      
      # Populate reponse content to a variable to be displayed on the output area
      params["xmlbody"] = s
 
    elsif params['invokeHttpRequest']
      # Process submission when the invokeHttpRequest button was pressed
      uri = URI.parse("https://host:port/icCnSetupCreditRulesPublicService/CreditRuleService")
 
      # Create new instance of HTTP object
      http = Net::HTTP.new(uri.host, uri.port)
 
      # The request uses SSL, certificates are NOT verified
      http.use_ssl = true
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
      
      # Create new instance of HTTP POST request
      request = Net::HTTP::Post.new(uri.request_uri)
 
      # Configure the request content type to be xml and SOAP action
      request.basic_auth(username, password)
      request.add_field("SOAPAction", "http://xmlns.oracle.com/apps/incentiveCompensation/cn/creditSetup/creditRule/creditRuleService/findRule")
      request.add_field("Content-Type", "text/xml;charset=UTF-8")
      
      # Set the envelope content obtained from the input to the request
      request.body = input
      
      # Execute the request and obtain the response
      response = http.request(request)
      
      # Parse the response to XML
      doc = Nokogiri::XML(response.body ,&:noblanks)
      s = doc.to_xml( indent:2, indent_text:" " )
 
      # Populate reponse content to a variable to be displayed on the output area
      params["xmlbody"] = s
    else
      # For any other action than invokeSavon / invokeHttpRequest default the input SOAP enveloper
      params["inputpayload"] = ""+
        "<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\"> " + "\n"+
        "  <soap:Body> " + "\n"+
        "    <findRule xmlns=\"http://xmlns.oracle.com/apps/incentiveCompensation/cn/creditSetup/creditRule/creditRuleService/types/\"> " + "\n"+
        "      <findCriteria> " + "\n"+
        "        <fetchStart xmlns=\"http://xmlns.oracle.com/adf/svc/types/\">0</fetchStart> " + "\n"+
        "        <fetchSize xmlns=\"http://xmlns.oracle.com/adf/svc/types/\">-1</fetchSize> " + "\n"+
        "        <filter xmlns=\"http://xmlns.oracle.com/adf/svc/types/\"> " + "\n"+
        "          <group> " + "\n"+
        "            <upperCaseCompare>false</upperCaseCompare> " + "\n"+
        "            <item> " + "\n"+
        "              <upperCaseCompare>false</upperCaseCompare> " + "\n"+
        "                <attribute>RuleId</attribute> " + "\n"+
        "                <operator>=</operator> " + "\n"+
        "                <value>300000000851162</value> " + "\n"+
        "            </item> " + "\n"+
        "          </group> " + "\n"+
        "        </filter> " + "\n"+
        "        <excludeAttribute xmlns=\"http://xmlns.oracle.com/adf/svc/types/\">false</excludeAttribute> " + "\n"+
        "      </findCriteria> " + "\n"+
        "      <findControl> " + "\n"+
        "        <retrieveAllTranslations xmlns=\"http://xmlns.oracle.com/adf/svc/types/\">false</retrieveAllTranslations> " + "\n"+
        "      </findControl> " + "\n"+
        "    </findRule> " + "\n"+
        "  </soap:Body> " + "\n"+
        "</soap:Envelope> " ;
    end
  end
end

The processing takes the envelope provided in input and executes the use Savon and basic "net/https" call. The content of the response is displayed to the user in the output field. To test:

  • Change to the directory where the application was created
  • Start the server with "rails server"
  • In browser navigate to "http://localhost:3000"
  • Press a button to invoke Savon / net/https call to a service, result will be updated on the output field.

Summary

In this article we covered an example using Savon and basic "net/https" for “Ruby on Rails” 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
« April 2014
SunMonTueWedThuFriSat
  
1
2
4
5
6
8
11
12
13
15
16
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today