How to implement rest services in BW 6

How to implement rest services in BW 6

Let’s take the a scenario and implement that scenario with TIBCO Business Works 6.x.

Restful services:

We have table called employee which has the following columns—> EMPID, First Name,

Last Name, Age, Gender, Salary, Commission.

We have to create a restful web service with get method such as we have to query the

database with restful resource input parameter.

So let’s implement this scenario using TIBCO AMX BW 6.x.

Creating a new project:

open TIBCO BW 6.x then select new project:

1

on selecting the new project you have to choose BusinessWorks application.

2

then click next

3

for creating a project you should have both BW application and BW application module so by default

create application module is selected if it is not then select create application module and move next.

4

Make sure all the boxes are checked and click finish.

then on the left hand side you will find application and application module which you created.

5

Creating a Schema:

First create schema In Business Works application module go to schema and select new and the XMl

schema file. Schema->New->XML Schema file.

6

Then you have to create a schema with desired name.

7

So in this scenario i have created the following schema.

8

Developing a restful services:

Then rename the process with proper name.

9

Then you can see the renamed businessworks process open on right hand side. but initially it was in

stateful mode.

10

As the rest services are stateless in properties go to advanced and change it to stateless mode.

11

now if you observe you can see an additional icon for rest services has been prompted on left hand

side in BW process interface bar after changed mode to stateless.

12

click on that icon which creates the rest service.

13

In the resource service you have to design the URl which is required for your web services,

So here i am giving /employee?EMPID={EMPID} After question mark we are giving EMPID={EMPID}

which indicates query parameter. select the operations which we use in this case we are using GET.

14

click next

then select the response xsd element and use the above schema which we created as a response xsd

element.

15

16

Now your rest service is build.

in this scenario we have to integrate with oracle DB so first we need to install oracle db drive.

Installing a Third party Driver:

Download drivers from official website we need to install ojdbc6.jar from following website.

http://www.oracle.com/technetwork/apps-tech/jdbc-112010-090769.html.

Copy the drivers to the TIBCO_HOME\bw\6.1\config\design\thirdparty directory.

TIBCO_HOME\bw\6.1\config\drivers\shells\jdbc.oracle.runtime\runtime\plugins\com.tibco.bw.jdbc.dat

asourcefactory.oracle\lib.

On a command line, navigate to TIBCO_HOME\bw\6.1\bin, run command.

Oracle: bwinstall oracle-driver.

Now your Oracle driver has been installed.

now we have to create JDBC connection resource.

In BusinessWorks application module go to resource–>new–>JDBC connection resource.

17

configure JDBC connection resource with proper credentials and database URL

18

and test the connection.

Now configure JDBC query as shown below.

19

in the statement we have to write query statement such as empid as a dynamic parameter as we are

getting it from rest service.

20

As we have declared in resource path while creating rest service we will get EMPID as a parameter.

21

as we are using JDBC query once we fetch we will get the output structure.

22

Now map this output structure to the existing schema structure in GETOUT.

23

Now test this service.

go to run and click on debug configarations.

24

Then again click on debug

25

Testing a Restful service:

Now our service starts debugging on you see that bw application is started then you have to enter

LRESTDOC command on console

26

then click enter then you will find your local url for testing your services.

27

Copy discover URL and paste it in a chrome browser.

28

click on get employee details.

29

now enter EMPID and click try it out.

.30

now you find your results.

Post Method:

Now we can post some data to database using post method.

Configure post method as shown below

31

Now we have to select input and output Schema click on browse and select the schema which we

created and click next and select the output schema same now click finish.

32

33

Now add JDBC update as we are using JDBC update for posting data.

34

Now write sql statement for inserting your data.

35

If transaction is successful then you have to see the data which you posted or inserted into database

so map this data in postout.

36

now the service is completed now test the service as shown below.

37

38

Now you can see your data as it is posted to database response code is 200.

PUT Method:

Now update the existing record in database:

for updating existing record we use put method.

Configure the put method as show below

39

We have to give input and output schema structure

40

Now add JDBC update and write statement:

41

Map the output schema so that you can get the data which you have updated.

42

Now test the service

43

Now try it we can see the output:

44

No Comments

Post A Comment