Showing posts with label DheerajSoa. Show all posts
Showing posts with label DheerajSoa. Show all posts

Wednesday, December 27, 2017

BPEL - Dynamic XSLT file selection and multiple inputs to XSLT

Hey guys,


In this post, I am explaining the steps to Dynamically select the XSLT files in BPEL process and pass on the multiple parameters to XSLT file as input.

This will need below implementation at High level :
1. DVM Lookup for dynamic XSLT file selection
2. Use of  ora:processXSLT() function to process XSLT and assign result to variable.


Implementations Steps :

1. Create SOA project, with BPEL process
2. Add the services and reference as per requirement
3. In the BPEL process, use assign to lookup DVM for XSLT file name.
4. Use another assign to execute the ora:processXSLT() function and assign result to variable.

Things to keep in mind while implementing ora:processXSLT() :

XSLT is processed in BPEL using the method: ora:processXSLT categorized under BPEL XPath Extension Functions.
The input parameters (signature) for the method is as defined by Oracle:

Signature:

processXSLT('template','input','properties/parameter'?)

Arguments definition:

template - The XSLT template or XSLT file Name with location (If using files from MDS)

input - The input data to be transformed

properties - This is optional. Additional inputs or parameters as defined in XSLT files.


e.g. ora:processXSLT('Transform_data.xsl', $inputVariable.body, bpws:getVariableData('metaDataVar'))

However, in our case, we are looking to dynamically select the XSLT file from DVM lookup, so the example will be like this

ora:processXSLT($xsltLocVar, $inputVariable.body, bpws:getVariableData('metaDataVar'))

Here Variable xsltLocVar already has XSLT file name fetched from DVM lookup.


The properties/parameter translated into parameter constructs of the XSLT and can be referenced within the XSLT scope. The property needs to be defined in a specific structure as mentioned below -


The definition of the schema contains for the following details:

<?xml version="1.0" encoding="windows-1252"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:p="http://schemas.oracle.com/service/bpel/common" xmlns="http://schemas.oracle.com/service/bpel/common" targetNamespace="http://schemas.oracle.com/service/bpel/common" elementFormDefault="qualified">
<xsd:element name="parameters">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="item" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="value" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>




Consider this schema structure for any variable.
A variable will always have a name and a value. eg. a variable x = 100. In case the name of the variable is "x" and the value is "100".

So the parameter variable needs to be set for all the variables which needs to be passed to the XSLT.

Define the XSD in your BPEL project. Create a variable of type global in the BPEL project with name "metaDataVar" (the name can be anything)

Lets assume, in one variable "user" we have the username and in another variable "password" we have the password for an account stored. The final payload needs to be constructed which should have both the values.

In your BPEL, create a copy operation and provide an expression to the "name" element of the variable "params". May be use the expression builder to assign a value of "userName" to the element "name".

Similarly assign "passValue" to the element "name" of the "params" variable and the xpath expression to the value to instantiate the value of the params element.

Now, come down to the XSLT where these elements needs to be accessed. Use XSLT construct to define the param as depicted below:

<xsl:param name="userName"/>
<xsl:param name="passValue"/>

Now the values of the variables can be accessed using a simple expression "$userName" and "$passValue"

Friday, October 13, 2017

Get Set Properties in BPEL header / Passing Properties from 1 BPEL and receiving in another BPEL using header

Hi Guys,

I am writing this post, because one day, I wanted to pass few properties from my bpel, which I needed in 2nd bpel process. I coudn't find any blogs with full details. There were many with partial details about how to do it.


Use Case :
Properties of 1st bpel needs to be passed to 2nd bpel. These could be timestamp, any unique ID genrated in bpel 1, or File name or location in case of file/ftp adapter service etc.


Implementation :
There could be many ways, how you do this, however one of the simplest way to achieve this is using the properties. High level steps :
1. Add the properties while invoking the reference Paternelink
2. Fetch the properties from received payload.

Note : The Syntax is different for bpel 1.1 and bpel 2.0, Most blogs has this for bpel 1.1 in their posts. This post is based on bpel 2.0


STEP 1 :
Add properties in your Invoke.



Source code view--




STEP 2:
Add properties in your receive activity of 2nd bpel


 Source code view--




Thats all.


Testing, screens from the Flow trace.

1st bpel invoke --



2nd bpel receive --



It is not only INVOKE and RECEIVE activities where you can use , but others supported activities are listed below with their format:

BPEL 2.0 bpelx Extensions Syntax
The following example shows bpelx extensions syntax in BPEL 2.0:
<invoke ...>
  <bpelx:fromProperties>?
    <bpelx:fromProperty name="NCName" .../>+
  </bpelx:fromProperties>
  <bpelx:toProperties>?
    <bpelx:toProperty name="NCName" .../>+
  </bpelx:toProperties>
</invoke>

<receive ...>
  <bpelx:fromProperties>?
    <bpelx:fromProperty name="NCName" .../>+
  </bpelx:toProperties>
</receive>

<onEvent ...>
  <bpelx:fromProperties>?
    <bpelx:fromProperty name="NCName" .../>+
  </bpelx:fromProperties>
</onEvent>

<reply...>
  <bpelx:toProperties>?
    <bpelx:toProperty name="NCName" .../>+
  </bpelx:toProperties>
</reply>

<reply ...>
  <bpelx:toProperties>
    <bpelx:toProperty name="NCName" .../>
  </bpelx:toProperties>
</reply>
Note the following details:
  • The toProperty is a from-spec. This copies a value from the from-spec to the property of the given name.
  • The fromProperty is a to-spec. This copies a value from the property to the to-spec.



BPEL 1.1 bpelx Extensions Syntax

The following example shows bpelx extensions syntax in BPEL 1.1:
<invoke ...>
  <bpelx:inputProperty name="NCName" expression="string" variable="NCName"
 part="NCName" query="string"/>*
  <bpelx:outputProperty name="NCName" expression="string" variable="NCName"
 part="NCName" query="string"/>*
</invoke>

<receive ...>
  <bpelx:property name="NCName" expression="string" variable="NCName"
 part="NCName" query="string"/>*
</receive>

<onMessage...>
  <bpelx:property name="NCName" expression="string" variable="NCName"
 part="NCName" query="string"/>*
</onMessage>

<reply ...>
  <bpelx:property name="NCName" expression="string" variable="NCName"
 part="NCName" query="string"/>*
</reply>  


Refer Oracle Doc for more detail, available at -- http://docs.oracle.com/middleware/12213/soasuite/develop/GUID-33A38C1A-38A6-473B-9FEA-D3164AD7A118.htm#SOASE87180

Thursday, July 13, 2017

CSV to XML or Native to XML Transformation using MFL

Hi Guys,

Recently one of associate asked me about the MFL, so here I am writing this post on the usage of the MFL.
What I have experienced so far is, there are very few SOA experts who uses the Message Format Language or MFL.
There are others, who underestimates the MFL capability as compared to Oracle Technology adapters.

Lets get started..

Use case :
Reading a .csv file from file location, transforming to XML, and writing the XML file to another location.
Sample Input CSV Message -

CustomerID;Firstname;Lastname;Age
1212;Dheeraj;Mishra;25
3242;Ajay Kumar;Singh;43

Background -
The MFL can be used to transform a Native format to XML and vice versa. The biggest advantage MFL provides is, It can be done in OSB message flow. So you have option to log or audit both the formats as well as you can use it anywhere in Message flow as per your need.
Whereas Oracle technology adapters can only be used as a start point or end point of service.

Another advantage, MFL requires only one artifact (MFL transform file, .mfl file) for message transformation and no extra configuration is needed. Whereas Oracle Technology adapters will generate multiple artifacts like .wsdl file, .xsd file, .jca file etc.
Due to this Oracle Technology adapters can make the service complex when you have to cater for multiple formats conversion.

Implementation:

Step 1 - Create Proxy to read .csv file.









 Step 2 - Create a Pipeline (Not applicable in 11g)



Step 3 - Add pipeline in Message flow


Step 4 - Now create a MFL transform file. 



New MFL will look like below- 



Step 5 - Add GROUP by right click on message icon in MFL. This is needed only if your Message or File has repeated records.
There are few properties on this page.
tick OPTIONAL if file can have only one record.
tick UNLIMITED if file can have more than one record.
Enter DELIMITER, usually \n for next line. Sometimes, it could be anything else like ; or " or | etc.
Tick DELIMITER IS OPTIONAL if this is possible to be used as delimiter for the last field in a record. As in our example, Last field uses \n as delimiter



Step 6 - Now add fields names as child elements in order of occurrence under Group.
Mention there Delimiters. Here delimiter is ;



Notice Last field has '\n' as delimiter



Step 7 - Test you MFL in Jdevloper itself



Step 8 - Now go back to Message flow, Add MFL transform Action. Specify the properties as shown.
Here MFL output is assigned to VarXML variable




Step 9 - Add replace action to put XML in Body content



Step 10  - Create Business Service to write XMl file.






Step 11 - Add Route, Browse Business Service






Thats it guys. You have completed the Service.
Now go on deploy it to server, and Test the Service

Here's the Sample output file

<?xml version="1.0" encoding="UTF-8"?>
<CSVToXML>
  <Customer>
    <customerId>CustomerID</customerId>
    <firstName>Firstname</firstName>
    <lastName>Lastname</lastName>
    <age>Age</age>
  </Customer>
  <Customer>
    <customerId>1212</customerId>
    <firstName>Dheeraj</firstName>
    <lastName>Mishra</lastName>
    <age>25</age>
  </Customer>
  <Customer>
    <customerId>3242</customerId>
    <firstName>Ajay Kumar</firstName>
    <lastName>Singh</lastName>
    <age>43</age>
  </Customer>
</CSVToXML>



Download the sample osb jar file from below link
https://drive.google.com/open?id=0BxHj0h0tnxxObDkzT2FCNUN6aEE





Tuesday, March 07, 2017

REST / RESTful Web Service Interview Questions - Part 1

What REST stands for?
REST stands for REpresentational State Transfer.

What is REST?
REST is web standards based architecture and uses HTTP Protocol for data communication. It revolves around resource where every component is a resource and a resource is accessed by a common interface using HTTP standard methods. REST was first introduced by Roy Fielding in 2000.
In REST architecture, a REST Server simply provides access to resources and REST client accesses and presents the resources. Here each resource is identified by URIs/ global IDs. REST uses various representations to represent a resource like text, JSON and XML. Now a days JSON is the most popular format being used in web services.

Name some of the commonly used HTTP methods used in REST based architecture?
Following well known HTTP methods are commonly used in REST based architecture −
GET − Provides a read only access to a resource.
PUT − Used to create a new resource.
DELETE − Ued to remove a resource.
POST − Used to update a existing resource or create a new resource.
OPTIONS − Used to get the supported operations on a resource.




What is web service?
A web service is a collection of open protocols and standards used for exchanging data between applications or systems. Software applications written in various programming languages and running on various platforms can use web services to exchange data over computer networks like the Internet in a manner similar to inter-process communication on a single computer.

What are RESTful webservices?
Web services based on REST Architecture are known as RESTful web services. These web services use HTTP methods to implement the concept of REST architecture. A RESTful web service usually defines a URI, Uniform Resource Identifier a service, provides resource representation such as JSON and set of HTTP Methods.

What is a Resource in REST?
REST architecture treats every content as a resource. These resources can be text files, html pages, images, videos or dynamic business data. REST Server simply provides access to resources and REST client accesses and modifies the resources. Here each resource is identified by URIs/ global IDs.

How to represent a resource in REST?
REST uses various representations to represent a resource where text, JSON, XML. XML and JSON are the most popular representations of resources.

What are the best practices to design a resource representation?
Following are important points to be considered while designing a representation format of a resource in a RESTful web services −
Understandability − Both Server and Client should be able to understand and utilize the representation format of the resource.
Completeness − Format should be able to represent a resource completely. For example, a resource can contain another resource. Format should be able to represent simple as well as complex structures of resources.
Linkablity − A resource can have a linkage to another resource, a format should be able to handles such situations.

Which protocol is used by RESTful webservices?
RESTful web services make use of HTTP protocol as a medium of communication between client and server.

What is messaging in RESTful webservices?
A client sends a message in form of a HTTP Request and server responds in form of a HTTP Response. This technique is termed as Messaging. These messages contain message data and metadata i.e. information about message itself.


What is addressing in RESTful webservices?
Addressing refers to locating a resource or multiple resources lying on the server. It is analogous to locate a postal address of a person.

What is URI?
URI stands for Uniform Resource Identifier. Each resource in REST architecture is identified by its URI.

What is purpose of a URI in REST based webservices?
Purpose of an URI is to locate a resource(s) on the server hosting the web service.

What is format of a URI in REST architecture?
A URI is of following format −
<protocol>://<server-address:port>/<service-name>/<ResourceType>/<ResourceID>

What is the purpose of HTTP Verb in REST based webservices?
VERB identifies the operation to be performed on the resource.

What are the best practices to create a standard URI for a web service?
Following are important points to be considered while designing a URI −
Use Plural Noun − Use plural noun to define resources. For example, we've used users to identify users as a resource.
Avoid using spaces − Use underscore(_) or hyphen(-) when using a long resource name, for example, use authorized_users instead of authorized%20users.
Use lowercase letters − Although URI is case-insensitive, it is good practice to keep url in lower case letters only.
Maintain Backward Compatibility − As Web Service is a public service, a URI once made public should always be available. In case, URI gets updated, redirect the older URI to new URI using HTTP Status code, 300.
Use HTTP Verb − Always use HTTP Verb like GET, PUT, and DELETE to do the operations on the resource. It is not good to use operations names in URI.



What is statelessness in RESTful Webservices?
As per REST architecture, a RESTful web service should not keep a client state on server. This restriction is called statelessness. It is responsibility of the client to pass its context to server and then server can store this context to process client's further request. For example, session maintained by server is identified by session identifier passed by the client.

What are the advantages of statelessness in RESTful Webservices?
Following are the benefits of statelessness in RESTful web services −
·         Web services can treat each method request independently.
·         Web services need not to maintain client's previous interactions. It simplifies application design.
·         As HTTP is itself a statelessness protocol, RESTful Web services work seamlessly with HTTP protocol.

What are the disadvantages of statelessness in RESTful Webservices?
Following is the disadvantage of statelessness in RESTful web services −
·         Web services need to get extra information in each request and then interpret to get the client's state in case client interactions are to be taken care of.

What do you mean by idempotent operation?

Idempotent operations means their result will always same no matter how many times these operations are invoked.


Refer to Part 2 of the interview questions set at below URL

http://osb-dheeraj.blogspot.in/2017/03/rest-restful-web-service-interview.html




REST / RESTful Web Service Interview Questions - Part 2


Which type of Webservices methods are to be idempotent?
PUT and DELETE operations are idempotent.

Which type of Webservices methods are to be read only?
GET operations are read only and are safe.

What is the difference between PUT and POST operations?
PUT and POST operation are nearly same with the difference lying only in the result where PUT operation is idempotent and POST operation can cause different result.

What should be the purpose of OPTIONS method of RESTful web services?
It should list down the supported operations in a web service and should be read only.

What should be the purpose of HEAD method of RESTful web services?
It should return only HTTP Header, no Body and should be read only.

What is caching?
Caching refers to storing server response in client itself so that a client needs not to make server request for same resource again and again. A server response should have information about how a caching is to be done so that a client caches response for a period of time or never caches the server response.

Which header of HTTP response, provides the date and time of the resource when it was created?
Date header provides the date and time of the resource when it was created.

Which header of HTTP response, provides the date and time of the resource when it was last modified?
Last Modified header provides the date and time of the resource when it was last modified.

Which header of HTTP response provides control over caching?
Cache-Control is the primary header to control caching.

Which header of HTTP response sets expiration date and time of caching?
Expires header sets expiration date and time of caching.

Which directive of Cache Control Header of HTTP response indicates that resource is cachable by any component ?
Public directive indicates that resource is cachable by any component.

Which directive of Cache Control Header of HTTP response indicates that resource is cachable by only client and server, no intermediary can cache the resource?
Private directive indicates that resource is cachable by only client and server, no intermediary can cache the resource.

Which directive of Cache Control Header of HTTP response indicates that resource is not cachable ?
no-cache/no-store directive indicates that resource is not cachable.

Which directive of Cache Control Header of HTTP response can set the time limit of caching ?
max-age directive indicates that the caching is valid up to max-age in seconds. After this, client has to make another request.

Which directive of Cache Control Header of HTTP response provides indication to server to revalidate resource if max-age has passed ?
must-revalidate directive provides indication to server to revalidate resource if max-age has passed.

What are the best practices for caching ?
Always keep static contents like images, css, JavaScript cacheable, with expiration date of 2 to 3 days. Never keep expiry date too high.
Dynamic contents should be cached for few hours only.

What are the best practices to be followed while designing a secure RESTful web service ?
As RESTful web services work with HTTP URLs Paths so it is very important to safeguard a RESTful web service in the same manner as a website is be secured. Following are the best practices to be followed while designing a RESTful web service −
Validation − Validate all inputs on the server. Protect your server against SQL or NoSQL injection attacks.
Session based authentication − Use session based authentication to authenticate a user whenever a request is made to a Web Service method.
No sensitive data in URL − Never use username, password or session token in URL , these values should be passed to Web Service via POST method.
Restriction on Method execution − Allow restricted use of methods like GET, POST, DELETE. GET method should not be able to delete data.
Validate Malformed XML/JSON − Check for well formed input passed to a web service method.
Throw generic Error Messages − A web service method should use HTTP error messages like 403 to show access forbidden etc.

What is the purpose of HTTP Status Code ?
HTTP Status code are standard codes and refers to predefined status of task done at server. For example, HTTP Status 404 states that requested resource is not present on server.

What is JAX-RS ?
JAX-RS stands for JAVA API for RESTful Web Services. JAX-RS is a JAVA based programming language API and specification to provide support for created RESTful Webservices. Its 2.0 version was released in 24 May 2013. JAX-RS makes heavy use of annotations available from Java SE 5 to simplify development of JAVA based web services creation and deployment. It also provides supports for creating clients for RESTful web services.

What are the core components of a HTTP Request?
A HTTP Request has five major parts −
Verb − Indicate HTTP methods such as GET, POST, DELETE, PUT etc.
URI − Uniform Resource Identifier (URI) to identify the resource on server.
HTTP Version − Indicate HTTP version, for example HTTP v1.1 .
Request Header − Contains metadata for the HTTP Request message as key-value pairs. For example, client ( or browser) type, format supported by client, format of message body, cache settings etc.
Request Body − Message content or Resource representation.




What are the core components of a HTTP response?
A HTTP Response has four major parts −
Status/Response Code − Indicate Server status for the requested resource. For example 404 means resource not found and 200 means response is ok.
HTTP Version − Indicate HTTP version, for example HTTP v1.1 .
Response Header − Contains metadata for the HTTP Response message as key-value pairs. For example, content length, content type, response date, server type etc.
Response Body − Response message content or Resource representation.



Friday, February 24, 2017

Human Task Implementation In Oracle SOA Suite - Part 2


This post is in continuation of my Part 1 of Human task implementation. You can read part 1 at below url :




So there are mainly 2 ways we can deploy Human task related artifacts to Application server.

1. Directly Deploying from Jdevloper.
2. Exporting project from Jdevloper, and Using EM console & Weblogic Console to deploy to Application server.


First, we will go with Directly Deploying from Jdevloper.

Now deploy the project along with the UI application created from Human task definition.
While deploying we will wizard as below where we need to specify the UI application info. Select the check boxes as below.

This is the only difference which we will be getting when compared with deploying SOA project without Human task








Second Approach, Exporting project from Jdevloper, and Using EM console & Weblogic Console to deploy to Application server.


1. Deploy your Human Task FORM UI as EAR file to local directory. PFA screens below. 
Please Note - Deploying it by Right Click on Project name will not create a EAR file, It will create a WAR file, which will give error while deploying.






2. Deploy your Human Task FORM UI as EAR file ( Generated in STEP 1) to Weblogic Console. PFA screens below.

Login to Weblogic console, Go to Deployments, Take Lock & Edit, Click on Install


Click on Upload your file in 12c servers (You need manually upload your file to server loaction in 11g Servers.)



Choose location, select UI EAR file



Once Uploaded, You will see this screen, Click on NEXT



Leave everything Default, Click on Next,



Select SOA manage Server



Leave everything Default, Click on Next


Leave everything Default, Click on FINISH


Activate The chnages,




Now, you need to Start the UI application deployed in previous step.
Go to Deployments, Select Control Tab



Select your UI Appliaction



Select Start--> Sevicing all request




Select YES to start.





3. Deploy your SOA Composite Project to JAR file on local directory. PFA screens below.





Do not select anything here, keep everything unselected,






4. Deploy your SOA Composite JAR file from local directory to EM Console. PFA screens below

Login to EM Console, Go to SOA-INFRA, Deploy composite


Select your Composite JAR file



Click Next


Review your Deployment,Click Next



Click on Deploy




Unit Testing

Go to deployed application and test it by giving the below details.





Click on the “Launch Flow Trace” to see the execution of the process.

You can notice that process is still running. This is because we have human activity as part of the process where human have take a action on the order


So Now logon to the worklist application using the below url


Login as user given in the Human task definition. Once you are logged in you can notice there list of request pending for logged-in user


Click on the request item. The details of the item will be displayed. Based on the outcome specified in the human task definition, it will creates the button for the human to take an action


Click “Reject” or “Approve”. Here will select “Approve”. Once human performs an action the item will be displayed from the list


Now go back to your process instance. You can notice that the process would be completed the execution


Here we are using browser as client to we can’t view the response data. But we can view what data the process has returned by clicking the process

You can notice that “Approve” case from the switch activity was executed because user has “Approved” the order request.

Based on the outcome we are returning “Approve” as the order status to the client as callback response