Labnn - REST Enabling CRUD: Scenario
Labnn - REST Enabling CRUD: Scenario
I have the following DB table Patient. I need to REST enable Create, Retrieve, Update and Delete functionality. For this I will use the SOA DB adapter to service enable the DB operations. I will then create a REST interface in OSB for these services.
DB Setup:
CREATE TABLE PATIENT ( PAT_ID NUMBER NOT NULL , PAT_NAME VARCHAR2(20) NOT NULL , PAT_SURNAME VARCHAR2(20) NOT NULL , PAT_AGE NUMBER(3) NOT NULL , PAT_SEX VARCHAR2(1) NOT NULL , PAT_NATIONALITY VARCHAR2(20) , PAT_COMMENTS VARCHAR2(255) , CONSTRAINT PATIENT_PK PRIMARY KEY ( PAT_ID ) ENABLE );
Insert into patient values (1, 'Name', 'Surname', 21, 'M', 'IE', ''); Insert into patient values (2, 'Name', 'Surname', 22, 'F', 'UK', '');
Now create a DB adapter service for INSERT Drag and drop the Database Adapter icon to the External References area.
Create a new DB connection nd point to the schema where you have created the PATIENT table
Accept defaults
The service has been created, a couple of files have been added to the project.
Create the eis for the database adapter Click on Deployments, the DBAdapter is already deployed. Click on Configuration Outbound connection Pools
Click Import
Click load another and load the following, one after the other o o o InsertPatientService_db.jca UpdatePatientService_db.jca DeletePatientService_db.jca
Click Next>>
Click Next>>
Click Last>>
Click Save
Now we want to branch on the HTTP method. This can be accessed as follows ./ctx:transport/ctx:request/http:http-method/text()
Edit the Stage o The first step is to assign the incoming parameters to OSB variables Note, there are 2 parameters patientID=1
Click on Expression
The patientID will be used as input to the SELECT service. The service expects the following structure
We will assign this structure to the OSB $body variable passing thru the incoming patientID. Add an Assign
I have amended the data to use the parameter passed in via the HTTP GET
</soap:Body>
Log $body
Save and Test Click on The Business Service Tester to see what the required input format
<ins:PatientCollection xmlns:ins="http://xmlns.oracle.com/pcbpel/adapter/db/top/InsertPatientService"> <!--Zero or more repetitions:--> <ins:Patient> <ins:patId>1000.00</ins:patId> <!--Optional:--> <ins:patName>string</ins:patName> <!--Optional:--> <ins:patSurname>string</ins:patSurname> <!--Optional:--> <ins:patAge>3</ins:patAge> <!--Optional:--> <ins:patSex>s</ins:patSex> <!--Optional:--> <ins:patNationality>string</ins:patNationality> <!--Optional:--> <ins:patComments>string</ins:patComments> </ins:Patient> </ins:PatientCollection>
o o
<upd:PatientCollection xmlns:upd="http://xmlns.oracle.com/pcbpel/adapter/db/top/UpdatePatientService"> <!--Zero or more repetitions:--> <upd:Patient> <upd:patId>5</upd:patId> <!--Optional:--> <upd:patName>string</upd:patName> <!--Optional:--> <upd:patSurname>string</upd:patSurname> <!--Optional:--> <upd:patAge>3</upd:patAge> <!--Optional:--> <upd:patSex>s</upd:patSex> <!--Optional:--> <upd:patNationality>string</upd:patNationality> <!--Optional:--> <upd:patComments>VERY HEALTHY - can be sent home</upd:patComments> </upd:Patient> </upd:PatientCollection>