Thursday, August 8, 2013

Work with Salesforce sObject for easy transform

How to work with Salesforce object for easy transform?


Salesforce WSDL are designed to maximize flexibility by using generic sObject abstract type to represent any objects. (complex types). But CRUD operations on generic arrays of objects that are not strongly-typed, which is undesirable from an OO perspective. Here I show how Fusion Middleware can identify the context of the generic objects & cast them to strongly-typed (concrete) objects.


Step 1: Add the Salesforce object, to the latest version of  the Salesforce enterprise wsdl, that we would like to expose and utilize in XSL transformation designer. The objects are created in your custom namespace (noted as YOURCOMPANY below). Be sure to name the element with the EXACT name of the type.



 <schema elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:YOURCOMPANY.enterprise.soap.sforce.com" xmlns:ens="urn:sobject.enterprise.soap.sforce.com"> <import namespace="urn:sobject.enterprise.soap.sforce.com"/> <element name="Opportunity" type="ens:Opportunity"></element> </schema>
           
       
    

Step 2: Within the scope that you will be working with such object, create a variable of element type of what you created in Step 1.


<variable name="opp" element="ns10:Opportunity"/>

in this case, xmlns:ns10="urn:YOURCOMPANY.enterprise.soap.sforce.com"



Step 3: TransformToObj.xsl can be reused in each composite to map the custom object back to SObject.



 
?>
               xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
               xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
               xmlns:mhdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.mediator.service.common.functions.MediatorExtnFunction"
               xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
               xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue"
               xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
               xmlns:wns="urn:YOURCOMPANY.enterprise.soap.sforce.com"
               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
               xmlns:med="http://schemas.oracle.com/mediator/xpath"
               xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"
               xmlns:bpm="http://xmlns.oracle.com/bpmn20/extensions"
               xmlns:xdk="http://schemas.oracle.com/bpel/extension/xpath/function/xdk"
               xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
               xmlns:fns="urn:fault.enterprise.soap.sforce.com"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema"
               xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
               xmlns:tns="urn:enterprise.soap.sforce.com"
               xmlns:ora="http://schemas.oracle.com/xpath/extension"
               xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator"
               xmlns:ens="urn:sobject.enterprise.soap.sforce.com"
               xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap"
               exclude-result-prefixes="xsi xsl wns fns xsd soap tns ens bpws xp20 mhdr bpel oraext dvm hwf med ids bpm xdk xref ora socket ldap">
<!--<xsl:output method="xml" indent="yes"/>--> <xsl:template match="/"> <tns:update> <tns:sObjects> <xsl:attribute name="xsi:type" namespace="http://www.w3.org/2001/XMLSchema-instance"> <xsl:value-of select="local-name(/child::node())"/> </xsl:attribute> <xsl:for-each select="/child::node()/child::*"> <xsl:copy-of select="."/> </xsl:for-each> </tns:sObjects> </tns:update> </xsl:template> </xsl:stylesheet>
 
 
   
     
       
         
       
       
         
       
     
   
 



Wednesday, August 7, 2013

PythonWebAppInterfaceSalesforceRESTAPI

This implementation is a simple Python Web application that authenticates the user to Force.com via Oauth 2.0, then creates, reads, updates, and deletes Force.com records via the new API. It interfaces  with the Force.com REST API.

Need to install:
  • Gunicorn Web Server – Django has default HTTP server, but Gunicorn is more production-ready embedded webserver.
  • Django Rest Framework – Provides endpoint for client to interface. Provides Web browseable API, out of the box Authentication policies including Oauth2.
  • Python-Requests library – Get content, add in caching
  • Python-Logging module
  • OpenSSH-server – authentication
  • Virtualenv - Create a new virtual env using virtualenv to make sure package configuration is keep nicely isolated from any other projects.
  • A Force.com account on EE with password never expired option
  • Configure Remote Access in Salesforce – Generates clientId, clientSecret to use in python request.

Salesforce Object Design and Restful API

  • Partner_Locator__c and Partner_Locator_Country__c has a master to detail relationship.
  • Expose Apex classes as REST Web Services via annotations @RestResource
  • Apex Rest supports two formats for representations of resources: JSON and XML


Web Service Authorization with Oauth

  • Oauth allows Partner Locator web app as the client operate on behalf of a user, without revealing that user’s credentials, such as username and password, to the client. The client first sends the user to an authorization server (login.salesforce.com), which authenticates the user, obtains the user’s authorization, and issues an access token which the client can use in interacting with a resource server (instance url returned in response).

Coding and Configuration Specifics:


  • requests.post : Requests is an Apache2 Licensed HTTP library. Requests makes integration with web services seamless. There is no need to manually add query strings to URLs, or to form-encode POST data. Keep-alive and HTTP connection pooling are 100% automatic.
  • @api_view(['GET']) : Use Django Response class @api_view function for views that return Response objects to ensure that the view can perform content negotiation and select the appropriate renderer for the response, before it is returned from the view.
  • @cache_page(60) : caching the output of individual views. Django.views.decorators.cache defines a cache_page decorator that will automatically cache the view’s response.
  • rest_framework.renderers.JSONPRenderer : A list or tuple of parser classes, that determines the default set of renderers that may be used when returning a Response object. Django REST framework provides JSONP support to get around cross-domain browser access issue.
  • from django.conf.urls import patterns, url : URLConf is a simple mapping between URL patterns (simple regular expressions) to Python functions (views).


Tuesday, September 2, 2008

PeopleSoft Enterprise Portal Pagelet Consume CI-based WS wrapped in BPEL

We have PeopleSoft Enterprise Portal (EP), Campus Solution and other PS modules. We are exploring ways for PeopleSoft Enterprise Portal to serve up the information from other modules; also comparing the approaches for developers to use to enhance the user interface/presentation; enabling mashup with external information to serve in EP. The other considerations are to have a best solution that simplifies the future PeopleSoft migration and maintenance; allows for centralizing management/monitoring of business transactions. The current skill set of the available resources in house also dictates largely what the best approach to take for application development and customization is.

From PeopleTools 8.48 up, it becomes possible/easier for PeopleSoft to integrate with SOA framework. We have Oracle SOA suite in our toolbox we could take advantage of. Currently the approach 1 might be shaping up to be our leading contender for this type of pattern.

For an introduction to iScript, take a look at this link: http://jjmpsj.blogspot.com/2008/02/what-is-iscript.html?showComment=1210730760000. BPELUtil is a utility Application class specifically make PeopleSoft Web Service easier to consumed by BPEL.

Approach 1: EP pagelet form post -> iScript in EP -> BPELUtil -> target system CI-based WS wrapped in BPEL

With this approach, we have ability to mashup with external information in BPEL layer. We developed a generic snippet of iScript that takes form variables posed to it and makes a BPELUtil function call to a service endpoint passed in the parameters as well. This approach is suitable for both PeopleSoft and non-PeopleSoft data. For PeopleSoft CI-based Web Service, wrapping as partnerlink in BPEL could hide the complexity of PeopleSoft schema.

Approach 2: EP pagelet form post -> iScript in target system -> CI in target system

We have EP and other PeopleSoft modules in the same domain, this approach is feasible. With this approach, we will need to set up SSO between EP and the target system. The draw back of this approach is: Having iScript in target system adds another modification that needs to be migrated with production, in addition to having to be synchronized with EP. We are an institution with limited resources and in house PeopleSoft knowledge. Given that reason, we might want to avoid using iScript in the target systems entirely.

For documentation purpose, here is some useful hint on configuring SSO. You will need to setup the target system node in EP and the EP node in the target system; also specify the content and portal URL's for the node. In the EP pagelet PeopleCode, you could use the function GenerateScriptContentURL to retrieve the target system iScript URL. For the user that has data in target system, you may need to create the user in the EP; and you will need to set up permission list for the target system iScript.

Approach 3: EP pagelet form post -> HTTPBindingServlet (SOA suite) -> target system CI-based WS wrapped in BPEL

We discovered that this release of BPEL HTTPBindingService has limited functionality. It works well if input is one single string. It doesn't work for us since we need to work with input as complex type. Alternatively if we could put the entire input element as XML text in the input field, this approach is workable solution. This was also blogged about in this link: http://technology.amis.nl/blog/?p=2386.

In addition to the above approaches, we also explored a way to create an instance of a target system component interface from PeopleCode written in the EP database. This is not feasible because the meta-data required to create the component interface and the data required to populate the component interface doesn't exist in the EP database. We do not consider copying the target system registry to the EP application as this was not the recommended approach because of the maintainese issues.

Other approaches for PeopleSoft integration such as Application Messaging, File Interfaces, and Java Integration might or might not find a way in our environment. We will be continuously exploring.

Monday, August 4, 2008

Resolve Peoplesoft Process Scheduler Error

This problem has shown up again, although this time in different disguise. There are also extra steps involved to resolve the problem.

Problem: cs90disc only has PSUNX server configured (check under PeopleTools - Process Scheduler - Process Monitor menu, then Server List page). But in the Server Definition tab for PSNT under PeopleTools - Process Scheduler - Servers menu, the various process types are defined to run on this server. It might have been default setting. The important thing to remember is if PSNT is not configured; don't define any process types to run on PSNT.

If there are already existing service operations in the "New" state before you have chance to correct the PSNT settings, you need to cancel the service operation. In the Process Monitor page, you will notice the corresponding process is in "Queued" state, you will need to also change the Run Status to "Cancelled". Otherwise the Application Engine program PRCSYSPURGE will end up in "Error" state since it can't purge the PSPRCSRQST table because it detects some process are in "Initial" state but is not processing.

With the above works, it might still not solve the problem. What I had to do to finally succeed is to Purge Cache of App Server. You will need to go to PSADMIN to do that.

To speed up the testing of batch job, you could go to PeopleTools - Process Scheduler - System Settings menu, System Purge Options page, change the "Next Purge Date/Time" to be some thing close. Then go to PSADMIN to stop/start Process Scheduler.

Thursday, July 3, 2008

PeopleSoft outbound Sales Order to ESB

After just taking the Peoplesoft Integration Broker class, I was eager to get my first hand experience connecting Peoplesoft and ESB together. I found this great instruction on peoplesoft best practice site to get started. (ESB: Publishing PeopleSoft Outbound Sales Order to Enterprise Service Bus found on http://www.oracle.com/technology/tech/fmw4apps/peoplesoft/index.html)

This is a good case study to go through to demonstrate how to wire the Peoplesoft delivered application messages to external system.

Configuring Gateways and activating the Integration Broker Domains are the tasks that only need to be done once. Since I started working with a CRM discovery environment that does not have the Gateway set up before, that was the first thing I did.

CRM9.0 with PeopleTools 8.48 delivers some application messages and the integration points out of the box.

For the published application message CRM_SALES_ORDER, there is already a service and service operation defined with the same name. I just have to make sure the service/service operations are active. CRM_SALES_ORDER message/service use SALES_ORDER_LOAD queue which also already exists.

For the PeopleSoft Integration, we need to configure point to point routing. That includes configuring Node and Routing.

A Node representing ESB system needs to be defined in Peoplesoft. Since we are sending SOAP message out from Peoplesoft, the HTTPTARGET connector is selected.

A Routing is created by specifying sender node as PSFT_CR (default local node) and receiver node as SOADISC (the node ESB runs on). For the HTTPTARGET connector properties, we need to make sure it's SOAPACTION is set to "execute" and METHOD is set to POST. This is because SOAP binding only defines SOAP within HTTP POST requests. In the PRIMARYURL field, enter the same SOAP Endpoint URI that will be created later in ESB.

While configuring the Peoplesoft Integration Broker, I learned a few things.

Process Monitor is a good place to see if all processes fire correctly. In my case, The Process Scheduler was only configured for PSUNX and not for PSNT. I had to manually change all the associated Application Engine Process to run on PSUNX. There was not an obvious way finding out what Application Engine Process was associated with "Add Order" business flow, I had to just experiment. Each time a queued AE process in the process monitor points out some problem. The default scheduler get kick off seems to be PSNT which is the reason why the process didn't get run. Since queued process prevents progressing to next AE program, it took some time before I figure out all the AE process that needs to be configured to go to PSUNX. I suspect there is better way doing this.

By now, we are complete with the PeopleSoft side of configuration. There is still some step to go through in PeopleSoft but the purpose of it is to extracting out the message schema to facilitate creating of ESB project. For this Outbound Async one way wiring PeopleSoft application message to external system, we don't need to create a PeopleSoft Web Service. But we still go through the step to create Web Service next just to take advantage of the "Provide Web Service" function to get the XSD schema of the CRM_SALES_ORDER.

The "Provide Web Service" function generates a WSDL with inline XSD schema for any Service/Service Operation with an "Any to Local" inbound Routing. The steps we need to go through are:

1. Generate an Any-to-Local inbound routing for CRM_SALES_ORDER

2. Generate the WSDL

3. From the wsdl file, copy the part between “xsd:schema...” and “/xsd:schema”

Now we can move onto creating ESB process:

This part of the instruction is clear enough, but there is one thing worth pointing out. When we configure Peoplesoft routing, we supplied the SOAP Endpoint URI that will be created in ESB. What is being entered there has to match exactly what will get generated in ESB. It was not obvious at the first that what you put in when creating ESB System/Group become part of the SOAP URI. The mistake you will make if follow the instruction is that it had you put in "http://your_ip_address:port/event/PeopleSoft/Inbound/ReceivePSFTOrder_RS" in PeopleSoft Connector property setting. Later in the instruction on creating ESB System/Group, it asks you to enter "Peoplesoft" as name. After registering your ESB process, you will notice the SOAP Endpoint URI generated as :http://localhost:port/event/Peoplesoft/Inbound/ReceivePSFTOrder_RS". Notices the one URI spell “PeopleSoft” while the other "Peoplesoft". You could be ended up sitting there wondering why my ESB service is not invoked!

Wednesday, June 4, 2008

BPEL Console Security

We would like to partition BPEL domain by groups for multiple departments and/or interests. With the Oracle SOA suite 10.1.3.1.0 install, we have come to realize that the BPEL console security is very coarse grained - you can get in and do everything or you can't get in at all.

What this means is for example:
Group A owns domain D1 and have management access to D1,
Group B owns domain D2 and have management access to D2,
There is need for Group A to have read access to domain D2, but not being able to modify it. We are out of luck!

The other drawback is that If we want to tie in LDAP or OID as authentication model, it is a custom step.

Oracle do have plans for 11 release to support, I am not sure when we will have version 11 installed and tested.
  • Finer-grained control (read vs modify)
  • Tie in to SSO, LDAP, etc

Here is the exercise I went through setting up BPEL domain:

1. Login as oc4jadmin, create the domain D1.

2. As oc4jadmin, from JDeveloper, publish applications to D1. (When creating application server connections in the Connection Navigator, only oc4jadmin user account can be used. All other accounts including bpeladmin, default, do not have the RMI permissions. That means user foobar won’t be able to set up server connection without oc4jadmin account.)

3. Configure to use a XML based provider

4. Create a group/role "BPMD1DomainAdmin"
JAZN:> addrole jazn.com BPMD1DomainAdmin

5. Create a user "foobar" and grant the role "BPMD1DomainAdmin"
to the user.
JAZN:> adduser jazn.com foobar pwd
JAZN:> grantrole BPMD1DomainAdmin jazn.com foobar

6. Assign the domain admin permission to the "BPMD1DomainAdmin"
role by running:
cd C:\product\10.1.3.1\OracleAS_1\config
java -Xbootclasspath/a:/c:/product/10.1.3.1/OracleAS_1/bpel/lib/orabpel-boot.jar -jar c:/product/10.1.3.1/OracleAS_1/j2ee/home/jazn.jar -grantperm jazn.com -role BPMD1DomainAdmin com.collaxa.security.DomainPermission D1 all

7. Restart SOA suite. Now the user foorbar could login to BPEL console, and only see his domain.

Wednesday, May 28, 2008

Oracle AS ESB File FTP Adapter Part 2

Continued from Part 1:

With not much log message to go on when configuring ESB SFTP adapter, I decided to try BPEL SFTP adapter to see if that yields more hints. The strategy seems to help pinpoint the problem.

Here is the BPEL SFTP error msg in log:


JCA: Uncaught exception
oracle.classloader.util.AnnotatedNoClassDefFoundError in
JCA-work-instance:FTP Adapter-4 - cause:

Missing class: com.maverick.ssh.SshTransport

Dependent class: oracle.tip.adapter.ftp.SshImpl.SshImplFactory
Loader: FtpAdapter:0.0.0
Code-Source:
/C:/oracle/product/10.1.3.1/OracleAS_1/j2ee/home/connectors/FtpAdapter/FtpAdapter/ftpAdapter.jar
Configuration: <code-source> in
C:\oracle\product\10.1.3.1\OracleAS_1\j2ee\home\connectors\FtpAdapter\FtpAdapter

The missing class is not available from any code-source or loader in
the system.

The forums.oracle.com has one entry that mentioned that for Oracle AS B2B package, there is a patch # 6353697 available for getting SFTP to work. It makes one think that it is what I needed too but I got to find the confirmation and the right patch. After setting up access to Oracle Metalink, I came across an entry that points to the patch (# 5852001) I need. Since my SOA window install has different path setup, I have to correct the referred path in the patch before applying it. I am glad the final outcome is a success!

There are more things to try for the File/FTP adapter.

1. Test the Synchronous Read File operation, which reads the current contents of a file.

2. Test different options for when to write to new file. The factors are: Number of Messages, Elapsed Time, and File Size.

3. With FTP adapter, there are different methods for obtaining the modification time of files on the remote FTP server. I am able to use File System command “quote mdtm filename”, I need to experiment with Directory Listing and File Name Substring. For now, there is no time zone issue, since the time zone of the FTP server is same as the SOA instance.

4. We could use Public Key option to connect to SSH server.