Oracle SOA Suite 12c: REST-Enabling SOA
Overview
Purpose
This tutorial shows you how to REST-enable an existing Simple Object Access Protocol (SOAP) service from an existing application by using Oracle SOA Suite 12c.
Time to Complete
Approximately 1 hour
Introduction
Most existing web applications are connected through web services, which are commonly known as SOAP services. More and more users are relying on mobile devices for communication, and they’re looking for lighter ways to access enterprise information on the go. REST services are the answer for the mobile device platform, because they get rapid responses and fast access to data.
Oracle SOA Suite 12c provides a complete set of service infrastructure components for designing, deploying, and managing composite applications. Oracle SOA Suite 12c enables services to be created, managed, and orchestrated into composite applications and business processes.
In this tutorial you, integrate REST operations as service-binding components and reference-binding components in SOA composite applications. You REST-enable a service by using an application that validates credit cards. The application validates the requested authorization amount for the credit card number, and it returns the response in XML or JavaScript Object Notation (JSON) format, the common data formats for mobile devices.
Hardware and Software Requirements
A Windows, Mac OS X, or Linux machine that meets the system requirements for Oracle SOA Suite 12c.
Note: This tutorial was created with Windows 7. If you use another operating system, the paths may be different.
Prerequisites
Before starting this tutorial, you should have:
- Installed Oracle SOA Suite 12c. See Installing Oracle SOA Suite Quick Start for Developers.
- Imported the Oracle SOA Suite sample applications into your JDeveloper IDE. See Running a Sample Application.
- Started Oracle WebLogic Server.
- Obtained valid credentials for Oracle Enterprise Manager.
Opening the Composite Sample Application
-
Open Oracle JDeveloper 12c, click the Applications tab, and select e2e-1201-composites.
-
Expand ValidatePayment, right-click SOA, click New, and then select Folder. If Folder isn’t displayed in the list, then select From Gallery to find it.
-
In the Folder Name field, enter
samples,
and click OK. -
Expand SOA, and double-click ValidatePayment.
By default the application contains a SOAP proxy service that checks for a credit card's preset authorized amount. The SOAP adapter is wired to a Business Process Execution Language (BPEL) process that pulls the data through a database adapter and calculates the payment status.
Exposing a REST Service by Using the GET and POST HTTP Methods
In this section, you expose a REST service and then add operation bindings to the REST service to support GET and POST HTTP methods.
Exposing the Service as REST
-
In the Components swimlane, right-click the left wired connection of validatePaymentProcess, and select Expose as REST.
-
On the Create a REST binding page, enter the following values for the REST service, and then click Add a resource in the Resources pane:
- Name:
ValidateRS
- Description:
Validate payment through a restful service
- Name:
-
In the Relative Path field, in the Create REST Resource dialog box, enter
/validate,
and click OK. -
In the Resources pane, on the Create a REST binding page, select the empty resource path / and click Delete.
-
Click Yes if a warning message is displayed.
Don't close the Create REST binding wizard. Next you add a REST binding to support the GET and POST HTTP methods.
Adding a GET Operation Binding to the REST Service
-
In the Operation Bindings pane, click Add, and select Add operation binding.
-
Enter or select the following values, and then click browse for schema file:
- Operation:
Validate_GET
- Resource: /validate
- HTTP Verb: GET
- Description:
Validate payment using the GET http method
- Operation:
-
In the Type Chooser dialog box, select PaymentInfo, and click OK.
-
On the Request tab, select all fields except CardNum, ExpireDate, and AuthorizationAmount, and click Delete.
-
Click the Response tab, deselect XML, select JSON for Payload, and click browse for schema file.
-
In the Type Chooser dialog box, select PaymentStatus, and click OK.
-
Verify your work, and click OK.
Adding a POST Operation Binding to the REST Service
-
In the Operation Bindings pane, click Add, and select Add operation binding.
-
Enter or select the following values, and then click browse for schema file:
- Operation:
Validate_POST
- Resource: /validate
- HTTP Verb: POST
- Description:
Validate payment using the POST http method
- Operation:
-
In the Type Chooser dialog box, select PaymentInfo, and click OK.
-
On the Request tab, deselect XML, select JSON for Payload, and click Generate Sample Payload.
-
In the Sample pane, remove all fields except CardNum, ExpireDate, and AuthorizationAmount, enter or select the following values, and then click OK:
- Sample Type: JSON
- CardNum:
1234123412341234
- ExpireDate:
0316
- AuthorizationAmount:
1230.73
- Save to:
CanonicalOrder_PaymentInfo.json
- Directory:
<your_local_path>\e2e-1201-composites\ValidatePayment\SOA\samples
-
Click the Response tab, deselect No Payload, select JSON for Payload, and click browse for schema file.
-
In the Type Chooser dialog box, select PaymentStatus, and click OK.
-
Verify your work and click OK.
Adding a Mediator with Routing Rules
In this section, you add and wire a mediator to the REST proxy service and the BPEL process. You also add routing rules to the mediator to support the GET and POST operations.
Adding and Wiring a Mediator to the REST Proxy Service
-
Verify that the ValidateRS proxy service displays the GET and POST operations, and save your work.
-
From the Components palette, drag and drop Mediator to the Components swimlane.
-
In the Create Mediator dialog box, enter or select the following values, and then click OK:
- Name:
RouteData
- Directory:
<your_local_path>
\e2e-1201-composites\ValidatePayment\SOA\Mediators - Template: Define Interface Later
- Name:
-
In the ValidatePayment diagram, wire the ValidateRS proxy service to the RouteData mediator.
-
In the Components swimlane, right-click the RouteData mediator, and select Edit.
Adding a Routing Rule to the Mediator for the GET Operation
-
In the Validate_GET pane, on the RouteData.mplan page, click Create a new Routing Rule.
-
In the Target Type dialog box, select Existing Service, and click OK.
-
In the Target Services dialog box, expand BPEL Processes, validatePaymentProcess, Services, and validatepaymentprocess_client, select validate, and click OK.
-
In the Validate_GET pane, on the RouteData.mplan page, click Select an existing mapper file or create a new one.
-
Click Create Mapping.
-
On the Create Transformation Map page, accept the default values, and click OK.
-
In the Request Transformation Map dialog box, click OK.
-
On the PaymentInfo_To_PaymentInfo1.xsl page, expand ns0:PaymentInfo in the <sources> and xsl:stylesheet panes, map the leaf nodes manually as follows, and then save and close the page:
- ns0:CardNum to ns0:CardNum
- ns0:ExpireDate to ns0:ExpireDate
- ns0:AuthorizationAmount to ns0:AuthorizationAmount
-
On the RouteData.mplan page, scroll down to the Synchronous Reply pane, and click Select an existing mapper file or create a new one.
-
In the Reply Transformation Map dialog box, click Create Mapping.
-
On the Create Transformation Map page, accept the default values, and click OK.
-
In the Reply Transformation Map dialog box, click OK.
-
On the PaymentStatus_To_PaymentStatus1.xsl page, expand ns0:PaymentStatus in both sides in the <sources> and xsl:stylesheet panes, map the ns0:Status leaf nodes manually, and then save and close the page:
Adding a Routing Rule to the Mediator for the POST Operation
-
On the RouteData.mplan page, scroll down to the Validate_POST pane, and click Create a new Routing Rule.
-
In the Target Type dialog box, select Existing Service, and click OK.
-
In the Target Services dialog box, expand BPEL Processes, validatePaymentProcess, Services, and validatepaymentprocess_client, select validate, and click OK.
-
In the Validate_POST pane, on the RouteData.mplan page, click Select an existing mapper file or create a new one.
-
In the Request Transformation Map dialog box, click Create Mapping.
-
On the Create Transformation Map page, accept the default values, and click OK.
-
In the Request Transformation Map dialog box, click OK.
-
On the PaymentInfo_To_PaymentInfo2.xsl page, expand ns0:PaymentInfo in the <sources> and xsl:stylesheet panes, map the leaf nodes manually as follows, and then save and close the page:
- ns0:CardNum to ns0:CardNum
- ns0:ExpireDate to ns0:ExpireDate
- ns0:AuthorizationAmount to ns0:AuthorizationAmount
-
On the RouteData.mplan page, scroll down to the Synchronous Reply pane, and click Select an existing mapper file or create a new one.
-
In the Reply Transformation Map dialog box, click Create Mapping.
-
On the Create Transformation Map page, accept the default values, and click OK.
-
In the Reply Transformation Map dialog box, click OK.
-
On the PaymentStatus_To_PaymentStatus2.xsl page, expand ns0:PaymentStatus in both sides in the <sources> and xsl:stylesheet panes, map the ns0:Status leaf nodes manually, and then save and close the page:
Deploying a Composite Application
In this section, you deploy a composite application to Integrated WebLogic Server.
-
In the ValidatePayment diagram, compare your diagram with the following image and save your work before deploying the application.
-
On the Applications tab, right-click ValidatePayment, select Deploy, and then select ValidatePayment.
-
On the Deploy ValidatePayment page, enter, select, or verify the following values on the specified pages, click Next on each page, and then click Finish on the Summary page after you review your selections:
- Deployment Action page: Select Deploy to Application Server.
- Deploy Configuration page: Enter or
verify
1.0
for the New revision ID field, and select Overwrite any existing composites with the same revision ID. - Select Server page: Select IntegratedWebLogicServer.
- SOA Servers page: Verify that the default server is running and selected.
The Summary page should look like the following:
-
On the Deployment - Log tab, verify that the deployment was finished.
Testing a REST Service
-
In your Internet Explorer, Firefox, or Chrome browser, open Oracle Enterprise Manager. In the Login dialog box, enter the following values and then click Login:
- URL:
http://localhost:7101/em
- Username:
Your Oracle Enterprise Manager username
- Password:
Your Oracle Enterprise Manager password
- URL:
-
In the Target Navigation pane, expand SOA, soa-infra(DefaultServer), and default, and select ValidatePayment[1.0]. In the right pane, click Test and select ValidateRS.
-
On the Test Web Service page, enter or select the following values, and then click Test Web Service:
- Method: POST(null)
- Representation Media Type for Request: application/json
- Representation Media Type for Response: application/json
- Input Arguments: Raw View
- Raw View content:
Your previous sample request content ../samples/CanonicalOrder_PaymentInfo.json
-
Click the Response tab, and verify that the response displays the Denied status.
-
Click the Request tab, enter or select the following values, and then click Test Web Service:
- Method: GET(null)
- Representation Media Type for Request: No Media Type
- Representation Media Type for Response: application/json
- Input Arguments: Tree View
- AuthorizationAmount:
896.39
- ExpireDate:
0316
- CardNum:
1234123412341234
-
Click the Response tab, and verify that the response displays the Authorized status.
Summary
With Oracle SOA Suite 12c, you can expose REST services to support integration of data with mobile devices.
You enable the REST exposure by using a REST adapter wired to a mediator. The mediator translates and maps the input and output between the REST adapter and the BPEL process.
To support the GET and POST HTTP methods, you added operations to the REST service. The same service is available through the GET and POST requests.
In this tutorial, you learned to:
- Expose a REST service by using the GET and POST HTTP methods in Oracle SOA Suite 12c
- Wire a REST adapter to a BPEL process through a mediator
- Deploy a composite application to Oracle WebLogic Server
- Test a REST service by using Oracle Enterprise Manager
Resources
- Installing Oracle SOA Suite Quick Start for Developers
- SOA Suite sample applications
- Running a Sample Application
- REST-enabling SOA video
- To learn more about Oracle SOA Suite 12c, refer to additional OBEs in the Oracle Learning Library.
Credits
- Lead Curriculum Developer: Armando Hernandez
- Other Contributors: Ronald Pinkerton, Mary Peek
To navigate this Oracle by Example tutorial, note the following:
- Topic List:
- Click a topic to navigate to that section.
- Expand All Topics:
- Click the button to show or hide the details for the sections. By default, all topics are collapsed.
- Hide All Images:
- Click the button to show or hide the screenshots. By default, all images are displayed.
- Print:
- Click the button to print the content. The content that is currently displayed or hidden is printed.
To navigate to a particular section in this tutorial, select the topic from the list.