Friday Sep 27, 2013

REST Enabling Oracle Fusion Sales Cloud using Java

Oracle Fusion Sales Could (Rel7) currently has a WebServices/SOAP interface however many clients & partners are interested in accessing Oracle Fusion Sales Cloud using REST & JSON. The main difference between a SOAP service and a REST service is the “way” you get access to the data and methods you use. Whilst SOAP is very powerful, very complete and also can be quite complex perhaps over-complex. REST in comparison is rather simple and uses the http verbs (GET,POST,PUT etc) to define the operation and can be as powerful as you desire.

There are many documents on the web which discuss REST vs SOAP but in summary :              

SOAP

Originally defined as Simple Object Access Protocol.

A protocol specification for exchanging structured information in the implementation of Web Services in computer networks.

An envelope, which defines what is in the message and how to process it
A set of encoding rules for expressing instances of application-defined datatypes
And a convention for representing procedure calls and responses.

Relies on eXtensible Markup Language (XML) as its message format, and usually relies on other Application Layer protocols (most notably Remote Procedure Call (RPC) and HTTP) for message negotiation and transmission.

This XML based protocol consists of three parts:

REST

RESTful web service (also called a RESTful web API) is a simple web service implemented using HTTP and the principles of REST. Such a web service can be thought about as a collection of resources. The definition of such a web service can be thought of as comprising three aspects:

The base URI for the web service, such as http://example.com/resources/

The MIME type of the data supported by the web service. This is often JSON, XML or YAML but can be any other valid MIME type.

The set of operations supported by the web service using HTTP methods (e.g., POST, GET, PUT or DELETE).

References

· http://en.wikipedia.org/wiki/Representational_State_Transfer#RESTful_web_services

· http://en.wikipedia.org/wiki/SOAP

Why would you want to use REST instead of SOAP?

There are many reasons why one would/could want to use REST instead of SOAP, one reasons is that SOAP is considered too heavy-weight for mobile applications, where payload size is critical, and also instead of XML, JSON is the preferred  message format.

The JSON message format is also very appropriate when interfacing with systems that use JavaScript (such as browsers or node.js) and hence adds weight to the desire to use REST instead of SOAP for accessing Oracle Fusion Sales Cloud.

So getting to the matter at hand and getting RESTful

So enough of why REST , how does one do it for Oracle Sales Cloud (aka CRM). Thankfully this is rather straightforward, at Oracle OpenWorld 2013 you would have seen Thomas Kurian demonstrate our new Oracle SOA Suite and how it can transform a SOAP service into a REST service whilst this is excellent and incredibly productive some clients dont want to install SOA Suite soley for this purpose. Thankfully its possible to do the same using pure Java and deploy it to a cloud infrastructure, like the newly release Oracle Java Cloud Service. It is however worth noting that using SOA Suite is preferable because it accelerates the deployment tremendously and would ultimately be more "agile". 

So what are the basic steps to REST enable a Fusion Sales Cloud Service?  

  1. Download and install the Jersey REST libraries, we'll use these for the creation of the RESTful service
  2. Generate the SOAP Client Side Proxie(s) for Oracle Sales Cloud. In this example we're using static proxies however for a more industrialized approach Id recommend going down the dynamic proxy route, more flexible and less likely to break at runtime, however at a development cost.
  3. Create "wrapper" JAXB Objects so that you can return XML data. This is needed because the baseline SOAP clients dont have @RootElement  (s) defined.
  4. Create the RESTful project and expose the services you require.
  5. Deploy to your runtime Java contain, like the Oracle Java Cloud Service
  6. Consume by your favourite client, like a mobile phone etc 

For the purpose of the tutorial (in the document), I've documented step by step how you can build the above, query Oracle Fusion Sales Cloud, manage security  (for development & production) and how to deploy the code to the Oracle Java Cloud. Obviously take note that this document is more of a tutorial than anything else when building your own custom REST Adaptor you would tailor it specifically to what services your client (mobile phone, javascript widget etc) requires.


Happy reading

Material

Note

This document and source code is sample code and assumes no support from Oracle Corporation or myself. 

Wednesday Sep 25, 2013

Sample Payload : Batch insert/update

Question came up in a call today, is it possible to do batch webservice updates using the Oracle Sales Cloud webservice interface??

The answer is YES, but not all webservices support this. The operation is called "process<ObjectName>",and you need to check in the ADFService list of operations, in FusionOER , that the service supports the process<xxx> syntax.

For example LocationService and  OpportunityService support the process operation but the SalesPartyService does not.

Also you will find there are typically two operations, process<object> and processCS<object> the difference being that the first one you supply it with a list of objects and one operation (ie update all locations), whereas in processCS you can provide a unique operation for each and every object.

From FusionOER for the opportunity service



Operation Description  Parameters  Return value
processOpportunity Performs a Create, Update, Delete, or Merge operation on a list of Opportunity rows. The specified operation is applied to all objects in the given list. String changeOperation ,
java.util.List Opportunities,
processControl oracle.jbo.common.service.types.ProcessControl

 A list of opportunities that are successfully processed
processCSOpportunity  Performs a Create, Update, or Delete operation on a list of Opportunity rows. Different operations may be applied to different objects, depending on what is specified in the ChangeSummary object.

oracle.jbo.common.service.types.ProcesssData processData,
processControl oracle.jbo.common.service.types.ProcessControl

 A list of opportunities that are successfully processed

And a sample payload looks like

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://xmlns.oracle.com/apps/cdm/foundation/parties/locationService/applicationModule/types/" xmlns:loc="http://xmlns.oracle.com/apps/cdm/foundation/parties/locationService/" xmlns:par="http://xmlns.oracle.com/apps/cdm/foundation/parties/partyService/" xmlns:sour="http://xmlns.oracle.com/apps/cdm/foundation/parties/flex/sourceSystemRef/" xmlns:loc1="http://xmlns.oracle.com/apps/cdm/foundation/parties/flex/location/" xmlns:typ1="http://xmlns.oracle.com/adf/svc/types/">
   <soapenv:Header/>
   <soapenv:Body>
      <typ:processLocation>
         <typ:changeOperation>Merge</typ:changeOperation>
         <typ:location>
            <loc:CreatedByModule>AMS</loc:CreatedByModule>
            <loc:Address1>510 Quercia Marcozzi</loc:Address1>
            <loc:Address2>Building 300</loc:Address2>
            <loc:City>Caserta</loc:City>
            <loc:Country>IT</loc:Country>
            <loc:State>CE</loc:State>
            <loc:PostalCode>90102</loc:PostalCode>
         </typ:location>
         <typ:location>
            <loc:CreatedByModule>AMS</loc:CreatedByModule>
            <loc:Address1>510 Quazi Marcozzi 2</loc:Address1>
            <loc:Address2>Building 500</loc:Address2>
            <loc:City>Caserta2</loc:City>
            <loc:Country>IT</loc:Country>
            <loc:State>CE</loc:State>
            <loc:PostalCode>90104</loc:PostalCode>
         </typ:location>
         <typ:processControl>
            <typ1:partialFailureAllowed>true</typ1:partialFailureAllowed>
         </typ:processControl>
      </typ:processLocation>
   </soapenv:Body>
</soapenv:Envelope>

About

Architect & Technology Evangelist - If its middleware I'm interested

Search

Archives
« September 2013 »
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
26
28
29
30
     
       
Today