menu

Thursday, November 13, 2014

RESTful Services In SOA

Introduction:

      At this write I'll try to show you how to create and test a simple Rest service in Oracle SOA Suite environment, with a small validate data example.Using Restful approach we can use raw xml or even no xml data instead of using Soap messages in Soap based services.It is sometimes painful to deal with the overengineered Soap services.At that time the Restful based services come to rescue to develop faster web services and to decrease response time of the services.Of course this will bring some extra effort at some points, since Rest doesn't have some builtin capabilities of Soap.For example, although there is an attempt to define Restful services with wadl(web application description language), it is not yet well understood and widely used like wsdl(web services description language).However its more eaiser to develop Restful services in Oracle SOA Suite environment.
Let's start with creating the bpel process. There will be some differences on creating and testing the Restful service because of the reasons we mentioned above.

Create the Bpel Process:

     Create a Bpel process with "Define Service Later" template in a Soa project in the composite page.


RESTful Services In SOA
Figure 1

     Create a xsd file to use in our example.We'll use Xml data as input and output of the Restful service.

RESTful Services In SOA
Figure 2

In Figure 2, you can see we have two input variables to validate, one string and one date.Now, open the composite page and create a REST service in the exposed services part as in Figure 3.

RESTful Services In SOA
Figure 3

On the "Create Rest binding" page, rename the service, enter a resource path and click on the plus sign on the Operation bindings part.

RESTful Services In SOA
Figure 4

On the next page, enter the operation name, choose the Http Verb as POST (Since we'll use xml input) and for the request and response choose the process and processResponse elements of our xsd we just created above.See in Figure 5 and 6.

RESTful Services In SOA
Figure 5

RESTful Services In SOA
Figure 6

The final screen should look like the following, just press OK.

RESTful Services In SOA
Figure 7

Now, go to the composite page and link the REST service with the Bpel process, choosing the transaction as "required" like in Figure 8.

RESTful Services In SOA
Figure 8

Built the Details of Bpel Process:

     Go to the Bpel editor, and drag and drop a Reveice component.

RESTful Services In SOA
Figure 9

On the "Edit receive" page, check "Create Instance" and create an input variable by clicking the green plus sign.See in Figure 10.

RESTful Services In SOA
Figure 10

Similarly create the output variable like in Figure 11.

RESTful Services In SOA
Figure 11

You can now drag and drop a "Validate" activity after the receiveInput component and the final Figure will be like below.

RESTful Services In SOA
Figure 12

Open the "Edit validate" page by double clicking the validate activity and choose the input to validate.

RESTful Services In SOA
Figure 13

Our aim is to get a fault if there is an error while validating variables.So we'll use catchAll activity with the help of a scope activity that wraps the validate component.If there is an error in the variables validation we'll catch the Rest fault.See in Figure 14.

RESTful Services In SOA
Figure 14

Next, drag and drop two assign activities after validate and catchAll respectively to set true or false to the return value which is a boolean.See in Figure 15.

RESTful Services In SOA
Figure 15

RESTful Services In SOA
Figure 16


In Figure 16 we see the whole Bpel process completed.

Test the Restful Service:

     Testing a Restful service is different than testing a Soap based service.First deploy the project after starting the integrated weblogic server.

RESTful Services In SOA
Figure 17

Now, we have to go to the enterprise manager and obtain the wadl of our service.Go to the http://localhost:7101/em, click on the project under soa-infra->Default, then click on the image that two after the "Settings..." button.Copy the wadl address that you see in Figure 18 and 19.

RESTful Services In SOA
Figure 18

RESTful Services In SOA
Figure 19


We can now go to the Jdeveloper again, and choose Tools->HTTP Analyzer.

RESTful Services In SOA
Figure 20

Click on "Open Url" on the opened page and paste the wadl you just copied.

RESTful Services In SOA
Figure 21

You can see wadl of your service in Jdeveloper now like in Figure 22.Click on Test button.

RESTful Services In SOA
Figure 22

Enter a valid and non-valid date value in to the second parameter and see the result like in Figure 23 and 24.

RESTful Services In SOA
Figure 23

RESTful Services In SOA
Figure 24

Conclusion:

     Today, I explained the usage of Restful services in SOA Suite with a validate data example.You can sometimes choose to use the lightweight Restful approach.However, you need to develop some builtin capabilities by hand by this approach that are already implemented in Soap based approach until Restful approach become more popular and engineered as Soap based approach.

You can download the source code from here.

Using Subprocess In SOA

Introduction:

     Today I'll talk about a new feature of SOA Suite 12c environment, subprocesses. We'll see two type of subprocess which are "inline" and "standalone".The main purpose is to create reusable components that include more than one activities.Using subprocess we can develop less code for repeating operations incresing the reusability and maintainability.

Inline Subprocess:

     You can use inline subprocess if you want to reuse a group of activities in a single bpel process rather than using it in more than one process.It will be part of a main bpel process.You have to combine reusable activities in a scope to be able make them as subprocess.There will be only one subprocess in the memory.

Here is an example bpel process for inline subprocess.

The example is just for the explanation of the inline subprocess.We'll create a bpel process which take 2 string input parameters, write the first parameter to a file in a file names as "yyyyMMddHHmmssSSz" and then check if the second parameter's length is greater that 5, if so write that parameter to another file again in a file named as "yyyyMMddHHmmssSSz".Here we need 2 write process and so need 2 invoke for the same file write adapter.At this point inline subprocess comes to rescue and helps us to create a reusable subprocess to be able to call write process many times with only one implementation.

At the end of the example we should get the following composite.


Using Subprocess In SOA
Figure 1

Create a synchron bpel process with an xsd file with 2 string input variables.

Using Subprocess In SOA
Figure 2

Create a file adapter by right clicking in the external references and follow the wizard by entering the File server JNDI name as "eis/FileAdapter" as in Figure 3 and 4.

Using Subprocess In SOA
Figure 3

Using Subprocess In SOA
Figure 4

Then choose the "Write" operation and enter the file directory and the file name convention as in Figure 5 and 6.

Using Subprocess In SOA
Figure 5

Using Subprocess In SOA
Figure 6

Finally we choose the input xsd file as the input of our file write adapter just to be an example.

Using Subprocess In SOA
Figure 7

Now go to the bpel process editor and drag and drop a scope,an assing and an invoke activity after the ReceiveInput component, reference the file adapter from the invoke and place the assign and invoke in the scope activity since the activities should be in a scope activity to create an inline subprocess.See in Figure 8.

Using Subprocess In SOA
Figure 8

Below is the invoke activity edit page.

Using Subprocess In SOA
Figure 9

You can now right click the scope activity and choose "Convert to a Subprocess" as in Figure 9.

Using Subprocess In SOA
Figure 10

Give a name to your subprocess, you can also choose immediately replacing your scope with the call of created subprocess as shown in Figure 10.

Using Subprocess In SOA
Figure 11

You can see your subprocess by choosing the subprocess in the left top corner as shown in the Figure 11 with a red arrow.

Using Subprocess In SOA
Figure 12

You can change your subprocess call name in the edit page.

Using Subprocess In SOA
Figure 13

At this point we define the input of file adapter with the help of the assign activity.We either define a variable in the main process and assign that variable before calling the subprocess and assign that variable to the input of file adapter in the subprocess as shown in Figure 14 and 15 or define a variable in the subprocess and make a relation with the input variable of the main process and the variable created in the subprocess.Since an inline subprocess can see the main process's variables it's no matter here, however when we use the standalone subprocess we have to create a variable in the subprocess and make a relation with the main process variable as we'll see in the standalone subprocess part of this write.

Using Subprocess In SOA
Figure 14


Using Subprocess In SOA
Figure 15

In the bpel process editor place an If activity after the just created subprocess call and check if the second input parameter length is greater than 5.

Using Subprocess In SOA
Figure 16

You can see the inline subprocess in the  Components -> Subprocesses as shown with a red arrow in the Figure 17. Simply drag and drop it in the if activity to call the file process second time after defining an assign activity similar to the previous subprocess call.

Using Subprocess In SOA
Figure 17

The final bpel process should now look like as in Figure 18.

Using Subprocess In SOA
Figure 18

Let's now test our bpel process first with a second input with a length less than 5 and then greater than 5.We should see two files created in the later case.

Using Subprocess In SOA
Figure 19

Since the second input is "test" which has 4 length there will be one file created in the target directory as in Figure 20.

Using Subprocess In SOA
Figure 20

The content of the created file will be like in the following figure

Using Subprocess In SOA
Figure 21

If we run the process with a parameter like "test77" we'll end up with 2 files created as in Figure 22.

Using Subprocess In SOA
Figure 22

Standalone Subprocess:

     The second type of subprocess is standalone which can be reused accross multiple bpel processes.For the first release of Soa Suite 12c its only supported in the same composite.We may use "Create SOA Template" feature to create a template with the standalone subprocess and then reused in different composites. 

Here is an example bpel process for standalone subprocess.

The example is just for the explanation of the standalone subprocess.We'll create a bpel process that takes 1 string input variable and persist it to database using a standalone subprocess which will include a database adapter.We'll create a table named "TEST" that include only one column to hold the string input value.We'll call the subprocess to insert the value and then will check if the count of the "TEST" table is less than 5 using another database adapter with a pure sql to get the count of the rows.If its less than 5 we call the subprocess again to insert the table this time input value concatenated with "-" and the "COUNT" of the table.

At the end of the example we should get the below composite.

Using Subprocess In SOA
Figure 23

First let's create a synchron bpel process with one input variable like in Figure 24.

Using Subprocess In SOA
Figure 24

Then create a standalone  subprocess by right clicking the Components part of the composite page as shown in Figure 25.

Using Subprocess In SOA
Figure 25

Create a connection under Connections -> Database and create a table name "TEST" under SOAINFRA -> Tables as in following figure.

Using Subprocess In SOA
Figure 26

Before editing the standalone subprocess create a database adapter to persist the input to the database.Choose the connection you created and enter the prebuilt JNDI name as eis/DB/SOA.

Using Subprocess In SOA
Figure 27

Choose "Insert Only" option and left the "Attribute Filtering" as it is.See in Figure 28 and 29.

Using Subprocess In SOA
Figure 28

Using Subprocess In SOA
Figure 29

Now double click to the standalone subprocess and go to the bpel editor.Drag and drog an assing and an invoke activity referencing to the database adapter as in the following figure.

Using Subprocess In SOA
Figure 30

To be able to assign the input of database adapter in the subprocess, unlike inline subprocess you must define a variable in the standalone subprocess and link that variable to a variable in the main process.Drag and drop an assign activity after the ReceiveInput of the main process and define a variable named InputValue in the main process and assign it by the input of the schema as in Figure 31.

Using Subprocess In SOA
Figure 31

As you can see in Figure 32, standalone subprocess is now in in the components tab.

Using Subprocess In SOA
Figure 32


Now go to the subprocess create a variable named "InputVar" and then in the main process editor drag and drop the standalone subprocess after the assign activity and link the "InputValue" variable of the main process with the "InputVar" variable of the subprocess in the "Edit Call" page as in Figure 33.

Using Subprocess In SOA
Figure 33

You should then assign the InputVar to the input of database adapter in the subprocess as in the following figure.

Using Subprocess In SOA
Figure 34

Let's now define another database adapter to get the count of the table as in the Figures 35 and 36.We define  a pure sql to get the count.

Using Subprocess In SOA
Figure 35

Using Subprocess In SOA
Figure 36

We now use an If activity after calling the "count" database adapter and if the count is less than 5 we add another call to the standalone subprocess with an input value of the form "input-count".See in Figures 37 and 38.

Using Subprocess In SOA
Figure 37

Using Subprocess In SOA
Figure 38

Finally we should get the following bpel process with 2 subprocess calls.

Using Subprocess In SOA
Figure 39

Let's test the bpel process running it 3 times with the test, test2 and test3 values respectively.In the first two calls we should see two inserts.In the last call since the row count will be 5 the second subprocess call will not be executed.See in Figures 40, 41 and 42 for the results.You can use the Tools -> Database -> SQLWorksheet to see the records in the table.

Using Subprocess In SOA
Figure 40

Using Subprocess In SOA
Figure 41

Using Subprocess In SOA
Figure 42

Conclusion:

      We saw subprocesses which is a new feature of SOA Suite 12c.Subprocesses can be used to develope reusable applications and it can reduce the size of your application.You can either use inline or standalone subprocess according to your need.In the standalone subprocess you can reuse a group of activities across multiple bpel processes while inline can be used only in the same bpel process. In the first release of SOA Suite 12c the standalone subprocess can be used only in the same composite, so you should look for the latest releases.

You can download the source code from here.