Skip navigation.

Angelo Santagata

Syndicate content
Fusion Middleware / Cloud Integration Architect - If its middleware, or PaaS for SaaS, then I'm interested!
Updated: 14 hours 56 min ago

Streamline Oracle Development with Cloud Services

Thu, 2015-07-02 04:24
Streamline Java Development with Cloud Services
On-Demand Webinar Replay
Learn to deliver java applications to market faster. Reduce hardware and software costs for new development and testing environments. Improve DevOps efficiency. Build, test and run enterprise-grade applications in the Cloud and on premise.

Listen to this webinar replay with development expert James Governor, co-founder of RedMonk, and Daniel Pahng, President and CEO of mFrontiers, LLC, an ISV with hands-on experience developing enterprise mobility and Internet of Things (IOT) solutions, as they present this webcast on developing applications in the cloud. Listen today! For more information: July 2015                                                                                          Oracle Corporation - All rights reserved

Calling Fusion SOAP Services from Ruby

Wed, 2015-07-01 07:55
Just completed some integration work with a partner of ours using the Ruby language. Given that a lot of startups like Ruby I thought it would be useful to cut-n-paste the sample code here. This example creates a simple (minimal) opportunity using the SOAP API in Sales Cloud. That said the code would be almost identical if you were querying HCM Data, The approach we took here was to prototype the SOAP call using SOAPUI and then cut-n-paste the SOAP payload into the data variable. In a real industrialized solution I'd create the payloads in template form.

  def create_opportunity
  # Change yourhostname.com to your Fusion SOAP Endpoint Hostname     uri = URI.parse("https://yourhostname.com/opptyMgmtOpportunities/OpportunityService")
    http = Net::HTTP.new(uri.host, uri.port)     http.use_ssl = true     path = uri.request_uri     http.read_timeout = 5     http.open_timeout = 5

  # Change authorization header to contain Base64encoded string of username/password     headers = {     'Content-Type' => 'text/xml',     'soapAction' => 'http://xmlns.oracle.com/apps/sales/opptyMgmt/opportunities/opportunityService/createOpportunity',     'authorization' => 'Basic bBase64EncodedCredentialHere='     }
       # Data Contains the payload     data = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://xmlns.oracle.com/apps/sales/opptyMgmt/opportunities/opportunityService/types/" xmlns:opp="http://xmlns.oracle.com/apps/sales/opptyMgmt/opportunities/opportunityService/" xmlns:rev="http://xmlns.oracle.com/apps/sales/opptyMgmt/revenues/revenueService/" xmlns:not="http://xmlns.oracle.com/apps/crmCommon/notes/noteService" xmlns:not1="http://xmlns.oracle.com/apps/crmCommon/notes/flex/noteDff/" xmlns:rev1="http://xmlns.oracle.com/oracle/apps/sales/opptyMgmt/revenues/revenueService/" xmlns:act="http://xmlns.oracle.com/apps/crmCommon/activities/activitiesService/">     <soapenv:Header/>     <soapenv:Body>     <typ:createOpportunity>     <typ:opportunity>     <opp:Name>Joel Test New1</opp:Name>     </typ:opportunity>     </typ:createOpportunity>     </soapenv:Body>     </soapenv:Envelope>'
    resp, data = http.post(path, data, headers)   end
!TIP!
A quick test in a SOAP testing tool like JDevelopers Http Analyzer or SOAPUI is a MUST before executing this!

URL Encoding and other from Groovy

Wed, 2015-06-03 07:44

There are times when you want to execute some code within Groovy which Oracle Sales Cloud's groovy doesn’t like. A very common example is URLEncode and Base64Encoding, however there are many others..


Native Groovy supports both base64 encoding/decoding and URL Encoding/Decoding


e.g.



String encoded = s.bytes.encodeBase64.toString()



Alas the groovy interpreter within Sales Cloud doesn’t support either the base64 encoding/decoding classes or the URLEncoding classes. Thankfully there is a an easy workaround, Sales Cloud does support the ability to call a SOAP Service from Sales Cloud and given that many SalesCloud installations will have a Java Cloud SX instance available to them its quite easy to create a Java SOAP Service, deploy it to JCSSX and then call this from Sales Cloud to do the stuff that Sales Cloud’s groovy wont allow you to do.



https://4.bp.blogspot.com/-W_PVvNpvJ_Y/VW7a8Ow9DpI/AAAAAAAAMq8/FOvtRAKulGM/s400/base64image.jpg


Steps to recreate this

  1. Create a new Project within your favourite IDE (I use JDeveloper11g for Sales Cloud Development, Netbeans for other stuff)

  2. Ensure your project has support for JAX-WS WebServices, within JDeveloper  create a JEE project.

  3. Within your project create a new Java class, I’ve called PTSEncoder

  4. Now cut and paste the following code into this class, obviously rename the Class name if you havent used the same name as I have

package oracle.pts.encoder;

import java.io.IOException;

import java.io.UnsupportedEncodingException;

import java.net.URLDecoder;

import java.net.URLEncoder;

import javax.jws.WebMethod;

import javax.jws.WebService;

import javax.xml.bind.DatatypeConverter;

@WebService

public class PTSEncoder {

   public PTSEncoder() {

       super();

   }


   /**

    *

    * @param s - String to be translated

    * @return

    */

@WebMethod(operationName = "encode")

   public String utf8encode(String s) {

       String result = "";

       try {


           result = URLEncoder.encode(s, "UTF-8");

           System.out.println("Encoded URL " + result);


       } catch (UnsupportedEncodingException e) {

           System.err.println(e);

       }

       return result;

   }


   /**

    *

    * @param s - String to be translated

    * @param enc - The name of a supported character encoding

    * @return

    */

   @WebMethod(operationName = "encodeWithEncType")

   public String ptsEncodeWithEncType(String s, String enc) {

       String result = "";

       try {

           if (enc == null || enc.length() <= 0) {

               enc = "UTF-8";

           }

           result = URLEncoder.encode(s, enc);

           System.out.println("Encoded URL " + result);


       } catch (UnsupportedEncodingException e) {

           System.err.println(e);


       }

       return result;

   }


   /**

    *

    * @param s - String to be translated

    * @return

    */

   @WebMethod(operationName = "decode")

   public String ptsDecode(String s) {

       String result = "";

       try {


           result = URLDecoder.decode(s, "UTF-8");

           System.out.println("Decoded URL " + result);


       } catch (UnsupportedEncodingException e) {

           System.err.println(e);

       }

       return result;

   }


   /**

    *

    * @param s - String to be translated

    * @param enc - The name of a supported character encoding

    * @return

    */

   @WebMethod(operationName = "decodeWithEncType")

   public String ptsDecodeWithEncType(String s, String enc) {

       String result = "";

       try {

           if (enc == null || enc.length() <= 0) {

               enc = "UTF-8";

           }

           result = URLDecoder.decode(s, enc);

           System.out.println("Decoded URL " + result);


           // String decodedUrl = URLDecoder.decode(encodedUrl, "UTF-8");

           //System.out.println("Dncoded URL " + decodedUrl);


       } catch (UnsupportedEncodingException e) {

           System.err.println(e);


       }

       return result;

   }


   /**

    * @param s

    * @return

    * @throws IOException

    */

@WebMethod(operationName = "encodebase64")

   public String ptsEncodeBase64(String s) throws IOException {        

       return DatatypeConverter.printBase64Binary(s.getBytes());

   }


   /**

    * @param s

    * @return

    * @throws IOException

    */

   @WebMethod(operationName = "decodebase64")

   public String ptsDecodeBase64(String s) throws IOException {    

       String result = new String(DatatypeConverter.parseBase64Binary(s));

       return result;

   }

// Simple tester

@WebMethod(exclude = true)

   public static void main(String[] args) {

       PTSEncoder pTSEncode = new PTSEncoder();

       pTSEncode.utf8encode("Angelo Woz here");

       pTSEncode.ptsEncodeWithEncType("Angelo Woz Here", "UTF-8");

       pTSEncode.utf8encode("------------");

       pTSEncode.ptsDecode("Jo was here");

       pTSEncode.ptsDecodeWithEncType("Jo Was here", "UTF-8");


       try {

           System.out.println("Encode Angelo = "+pTSEncode.ptsEncodeBase64("Encode Angelo"));

       } catch (IOException e) {

           e.printStackTrace();

       }

   }

}


For interest I created this class by first creating the methods and then using J Developers wizard to convert a class+methods into a SOAP WebService. This class uses Java annotations which tell at JEE server that most (not all) of these methods are WebService calls. This is done using server side injection at deployment time.

  1. If within JDeveloper you created your project as a web/jee project you can simply deploy it as is to your JCSSX, or local WLS Application Server

    1. Right Mouse Click on the Project, deploy to your deployment profile

    2. Deploy to Application Server

    3. Choose your application server and deploy

    4. Check the deployment

You can now test the SOAP Service using a SOAP testing tool like Http Analyzer or SOAP UI. The WSDL of the service would be the contextRoot+WebService Name. For JDeveloper this can be found if you right-click on the Webservice Class,Java WebServices Editor and look at the generation options



So in my instance the WSDL will be available at


https://<JCSSXServer>.java.us2.oraclecloudapps.com/PTSEncoder/PTSEncoderService?wsdl



  1. You can put this into SOAPUI or Http Analyzer and test away

  2. Now last you can register it in Sales Cloud as a web service and use it from Groovy

    1. Activate a Sandbox,  that way you can undo changes if oyu want

    2. Navigate to Application Composer

    3. Navigate to the application you will be using the SOAP WebService from (Common,Sales etc)

    4. Select WebServices

    5. Enter a name for the WebService, this name becomes the groovy package name

    6. Security None (for testing only)

    7. Then finally use the SoapService from any groovy script you desire, remember the Palette helps you find different services registered on you system



Sample Groovy Code

def base64result = adf.webServices.PTSBase64.encodebase64("Angelo Woz Here")


Final footnote

This example shows how to execute a base64 encoding externally using Java Cloud ServiceSaaS eXtensions (JCSSX), the example could easily have used Java Cloud Service, or some other Cloud service. More importantly you can code extensions using Java Cloud Service and call them from SalesCloud. Given that most JCSSX instances are going to be co-located within the same datacentre this makes the operation quick, efficient and very flexible!

Lastly, the service I deployed didn’t contain any security because it’s a stateless service and ok for anyone to call, that said in a production environment I would still add a medicum of security to the service just to make sure someone doesn’t try and abuse it.

Angelo
Enjoy!