Thursday, 28 September 2017

Concept of Namespace, Default and target namespace, use of prefix

Namespace in XSD

This blog explains the concept of namespace in XML schema with help of some java concepts. I personally found that relating the concept  of namespace to java packages makes it easier to grasp and remember.

1)  Namespace in XSD and Package in java
  
The concept of namespace in XSD is very similar to the use of package in java. Package in java is used to group related classes in a single unit, to avoid naming conflicts or ambiguity.
Similarly in XSD, Namespace is used to group all the elements in that XSD as a single unit to avoid any kind of ambiguity.

According to w3 standards, A namespace should start with a protocol.
Generally http is used

eg- http://Class.school.com

2)  TargetNamespace in XSD and package declaration  in java

Package declaration in java is simple as below

Package com.school.class;
Public class Student{
}

Here Class Student belongs to the package com.school.class

similar to package declaration in java, targetNamespace in XSD is used to group all entities in that XSD in a single namespace. Placing the targetNamespace attribute at the top of your XSD schema means that all entities defined in XSD are part of this namespace. In short It is a unique identifier. Here all the entities are part of http://Class.School.com namespace.

<schema targetNamespace="http://Class.School.com"
            xmlns="http://www.w3.org/2001/XMLSchema">
            <element name="Student">
                        <complexType>
                                    <sequence>
                                         <element name="RollNo" type="int"/>
                                         <element name="Name" type="string"/>
                                    </sequence>
                        </complexType>
            </element>

</schema>

3)  Import in java and namespace declaration in XSD

When a class belongs to a package, at the time of using that class we need to use fully qualified namespace.

e.g.   Com.school.class.Student

,This however increases the overhead of using fully qualified name for the class whenever it is used. That is when import is used.


import  java.lang.*;    
class Student{  
  public static void main(String args[]){  
     
   system.out.println("Hello”);
  
 }   
}      

Similarly in XSD xmlns is used. This can be explained as below

All the entities used in an xsd (element, sequence, complexType  etc) belong to a w3 namespace "http://www.w3.org/2001/XMLSchema-instance".
Hence while writing an xsd we need to import the namespace http://www.w3.org/2001/XMLSchema-instance into the XSDas below.

<schema targetNamespace="http://Class.school.com"
            xmlns="http://www.w3.org/2001/XMLSchema">

so here http://www.w3.org/2001/XMLSchema is similar to a built in package in java e.g. java.lang. Importing this namespace enables us to use the entities declared in the namespace in our xsd. We can similarly import more than one namespace in an XSD as per our requirement.

1)  Use of prefix in XSD

Importing namespace gives birth to another concept of prefix in XSD.

A namespace declared without a prefix is called default namespace, there can be one or no default namespace in an XSD. In the above example http://www.w3.org/2001/XMLSchema is the default namespace. However the same XSDcan be modified as below

Here xs is the prefix for namespace http://www.w3.org/2001/XMLSchema .So all the entities in this namespace should be used with that prefix.

<xs:schema targetNamespace="http://Class.school.com"
            xmlns:xs="http://www.w3.org/2001/XMLSchema">
            < xs:element name="Student">
                        < xs:complexType>
                                    < xs:sequence>
                                                < xs:element name="RollNo" type="int"/>
                                                < xs:element name="name" type="string"/>
                                    </ xs:sequence>
                        </ xs:complexType>
            </ xs:element>
 </ xs:schema>



 HAPPY LEARNING!!!!

Wednesday, 20 September 2017

query() and queryMore() operations in Salesforce

Here in this tutorial, I am going to discuss query() and queryMore() operations in salesforce and how to invoke the same in a BPEL.
In my previous tutorials I have already discussed interaction with salesforce API using enterprise wsdl. Please refer those if you are new to use cases where salesforce has to be invoked directly.

I came across a scenario where I needed to retrieve data from a salesforce object. Query operation is a very easy way to do the same. Just a select query on the object and that is all. Please note that * is not used in sql query here. Specify all necessary field names that you want.

The query result object contains up to 500 rows of data by default. If the query results exceed 500 rows, then the client application uses the queryMore() call and a server-side cursor to retrieve additional rows in 500-row chunks.Moreover if  you are querying for fields of type Base64, both query and query more returns a single record.


query()
Executes a query against the specified object and returns data that matches the specified criteria.
query() call is used to retrieve data from an object and below are the parameters

INPUT-
   1)  queryString a query expression that specifies the object to query, the fields to retrieve, and any conditions that determine whether a given object qualifies.

 Upon invocation, the API executes the query against the specified object, caches the results of the query on the API, and returns a query response object to the client application

OUTPUT-
  1)  done
type- Boolean
value-(true/false)
Description- Indicates whether additional rows need to be retrieved from the query results (false) using queryMore(), or not (true). Your client application can use this value as a loop condition while iterating through the query results.

  2)  queryLocator

Description- A specialized string, similar to ID. Used in queryMore() for retrieving subsequent sets of objects from the query results, if applicable. 

  3)  Records

Type- sObjects []
Description- Array of sObjects representing individual objects of the specified object and containing data defined in the field list specified in the queryString

  4)  Size
Type- int
Description-Total number of rows retrieved in the query.


queryMore()

Retrieves the next batch of objects from a query()

INPUT-
  1)  queryLocator

OUTPUT-
Is same as that of query() operation.


Steps.

1) Create a SOA project with a BPEL and a reference with salesforce enterprise wsdl.

2) Invoke login operation and assign username and password 
use session id, URL retrieved as response of login operation in subsequent operations as discussed in previous tutorials

3) Invoke query operation and create input and output variables. Input and Output of query operation looks like below




4) Assign sql query as input to query() operation


5) Create variables done,QueryLocator as string. Assign done and QueryLocator returned as response of query() operation to these variables.



6) Drop a While activity and enter the condition as done='false'.


7)  Inside the while loop drop Invoke activity for queryMore operation and create input and output variables. Input and Output of query operation looks like below.




8) Assign value from QueryLocator variable to the input of queryMore operation.


9) After invoke assign done and QueryLocator returned as response of query() operation to these variables. 




Deploy and test your composite.

HAPPY LEARNING!!!!

Tuesday, 19 September 2017

Interact directly with Salesforce API using the Enterprise WSDL in BPEL 2.0

In my previous tutorial, I discussed the way to interact directly with Salesforce API using the Enterprise WSDL. The BPEL in the tutorial was in 1.1 version.

When I try to implement the same in BPEL version 2.0, it does not work. BPEl fault ‘fromvalue is not a sref:service-ref element’ is thrown at runtime. 



This error is related to PartnerReference variable (of enpointReference type ) which is directly assigned to the partner link. Though rest of the steps and logic remains the same,changes are only required for PartnerReference variable. Below are few changes related to this variable when trying to implement the same in BPEL 2.0

     1)  Download the ws-bpel_serviceref.xsd  and add it to your project

2) Create a variable PartnerReference of element type service-ref , which is defined in the above xsd.



3) Using append xml fragment option the following xml snippet to the above variable  PartnerReference

 <wsa:EndpointReference xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing">
    <wsa:Address/>
</wsa:EndpointReference>

Make sure to declare xmlns:wsa=http://schemas.xmlsoap.org/ws/2003/03/addressing namespace in BPEL as well.

4) Now assign  the server url received as a response of login operation to, PartnerReference/ wsa:EndpointReference/ wsa:Address


5) Now assign PartnerReference variable to the partner link that is to be invoked.



HAPPY LEARNING!!!!

Thursday, 14 September 2017

Interact directly with Salesforce API using the Enterprise WSDL- No Salesforce adapter

As part of Oracle Fusion Middleware 11.1.1.7, Oracle introduced the Cloud Adapter for Salesforce.com integration.

However, for complex scenarios it might be better to interact directly with Salesforce API using the Enterprise WSDL. You will need to manage the sessions (login/logout) in your custom code, but it allows you more flexibility to create a generic approach and reuse it.
Before you call the service to query or change objects, you need to call the Login operation and handle the Session ID received back, that needs to be included in any subsequent requests

Here in this tutorial I am sharing a way to interact directly with Salesforce API using the Enterprise WSDL instead of salesforce adapter.

Prerequisites:

1)  Credentials to your Salesforce.com account
     Username (in the form of an e-mail address)
     Password + Security token.

2) Download Enterprise WSDL file form Salesforce.com

3)  Import Salesforce.com Certificate into Client/Server
The Salesforce.com Client certificate has to be downloaded from the Salesforce.com application user interface. This certificate has to be imported into the client server for successful handshaking with Salesforce.com
For more information on the prerequisites, please refer to the user guide for salesforce adapter.


Create a BPEL process to invoke Salesforce
1    1) Create a SOA project with sync BPEL



 2)Another component that would be brought into the composite is a Web Service Adapter. Create it on the basis of enterprise WSDL. On the composite.xml, provide wiring between both the component.




3) Click on the BPEL to write the logic

4) In Salesforce the first operation that is invoked is the login operation. This process takes 2 inputs: ‘user name’ and ‘password’ via payload. The password is a combination of Salesforce password and the security token. Only when we are successfully able to invoke the login operation we would be able to invoke the other operations on Salesforce.

Drop an invoke activity and select Login operation from the drop down. Create input/output variables for the invocation.


5) Dropassign activity assigning values to username and password parameters, prior to the Invoke activity.



6) The output payload provides two important details using which we would precede with the subsequent operations. These are as follows:
Session ID: This ID needs to be sent as part of header information for all operations post login
ServerURL: This is the URL that needs to be called for all subsequent operations (query, update etc.) for this user.

The output of login operation provides Session ID that needs to be included in any subsequent requests to maintain the sessions.Create a SessionHeader variable of type Header.Map the session id retrieved from the login operation into this variable.



7) Configuration for Server URL: Create one PartnerReference variable in BPEL project of ‘EndpointReference’ type defined in ws addressing xsd http://schemas.xmlsoap.org/ws/20 03/03/addressing. Map the server URL received as a response of login operation to this variable, and then subsequently assign this variable PartnerReference directly to the partner link prior to invoking the second operation.



8) Drop an invoke activity and select the next operation you want to perform (create in this case).



9) In the invoke activity, select Header tab and select SessionHeader.




10) In order to assign input to CREATE operation, drop an XSLT activity to map input variable to Invoke_CreateTestObject. 




Salesforce WSDL exhibits polymorphic behavior. Records need to be substituted as actual Salesforce object as shown below






So this is how the BPEL looks like. Deploy and test the composite



HAPPY LEARNING!!!!

Friday, 8 September 2017

Error while testing service in EM ADF_FACES-60096: Server Exception during PPR, #8 java.io.IOException: Stream closed

I came across the below error when I tried to test deployed SOA service on EM. This problem started after a server restart.

ADF_FACES-60097: For more information, please see the server's error 
log for an entry beginning with ADF_FACES-60096 server Exception during PPR,#8

ISSUE -

Post logging into EM, when any of the SOA composite is attempted to be tested by clicking the TEST button, A popup with the above error can be seen. This issue can be user specific i.e. might occur for one of the user while other users might not face the same.
The details of the error are captured in admin log file.


AdminServer] [ERROR] [] [oracle.adfinternal.view.faces.config.rich.RegistrationConfigurator]
[tid: [ACTIVE].ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)']
[userId: weblogic] [ecid: bdd06acffce2e19a:26bccba1:15e577c16ae:-8000-00000000000002bf,0]
[APP: em] ADF_FACES-60096:Server Exception during PPR, #8[[
java.io.IOException: Stream closed
          at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:134)
          at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
          at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
          at oracle.xml.parser.v2.XMLReader.pushXMLReader(XMLReader.java:377)
          at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:315)
          at oracle.jsp.parse.XMLUtil.getDocument(XMLUtil.java:447)

Cause-

The reason is corrupt files for the specific user. Hence removing the corrupt files for particular user and restarting the server will help resolve the issue as files will be regenerated on server restart.


Solution -

    1)    Stop the server

    2)  Under domain home look for the username that is facing the issue.
In my case below are the directories from where I removed all the existing xml files. Take backup of all files before deleting.

$DOMAIN_HOME/sysman/mds/partition1/ai/sca/share/audit/mdssys/cust/user/weblogic
$DOMAIN_HOME/sysman/mds/partition1/as/wsmgt/mdssys/cust/user/weblogic
$DOMAIN_HOME/sysman/mds/partition1/oracle/sysman/mds/files/model/mdssys/cust/user/weblogic
$DOMAIN_HOME/sysman/mds/partition1/oracle/sysman/mds/files/model/template/splitters/mdssys/cust/user/weblogic


     3)  Restart the server


HAPPY LEARNING!!!!

Demystifying getActiveUnitofWork property of DB Adpater

Here in this I am going to discuss one of the interaction options available in Database adapter configuration, getActiveUnitofWork The p...