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:

Opening the Composite Sample Application

  1. Open Oracle JDeveloper 12c, click the Applications tab, and select e2e-1201-composites.

    Applications tab
  2. 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.

    Create Folder

    The Create Folder dialog box is displayed.

  3. In the Folder Name field, enter samples, and click OK.

    Create Folder

    The samples directory is created. You will store the sample request for the POST service in this directory.

  4. Expand SOA, and double-click ValidatePayment.

    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

  1. In the Components swimlane, right-click the left wired connection of validatePaymentProcess, and select Expose as REST.

    Expose As REST

    The Create REST binding wizard is displayed.

  2. 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
    REST binding
  3. In the Relative Path field, in the Create REST Resource dialog box, enter /validate, and click OK.

    REST resource
  4. In the Resources pane, on the Create a REST binding page, select the empty resource path / and click Delete.

    Delete resource path
  5. Click Yes if a warning message is displayed.

    Delete resource with operation

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

  1. In the Operation Bindings pane, click Add, and select Add operation binding.

    Add operation binding
  2. 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
    Browse schema URL for request
  3. In the Type Chooser dialog box, select PaymentInfo, and click OK.

    PaymentInfo
  4. On the Request tab, select all fields except CardNum, ExpireDate, and AuthorizationAmount, and click Delete.

    Delete parameters
  5. Click the Response tab, deselect XML, select JSON for Payload, and click browse for schema file.

    Browse schema URL for response
  6. In the Type Chooser dialog box, select PaymentStatus, and click OK.

    PaymentStatus
  7. Verify your work, and click OK.

    Confirm operation binding

Adding a POST Operation Binding to the REST Service

  1. In the Operation Bindings pane, click Add, and select Add operation binding.

    Add operation binding
  2. 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
    Browse schema URL for request
  3. In the Type Chooser dialog box, select PaymentInfo, and click OK.

    PaymentInfo
  4. On the Request tab, deselect XML, select JSON for Payload, and click Generate Sample Payload.

    Delete parameters
  5. 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
    Browse schema URL for response
  6. Click the Response tab, deselect No Payload, select JSON for Payload, and click browse for schema file.

    PaymentStatus
  7. In the Type Chooser dialog box, select PaymentStatus, and click OK.

    Confirm operation binding
  8. Verify your work and click OK.

    Confirm operation binding

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

  1. Verify that the ValidateRS proxy service displays the GET and POST operations, and save your work.

    Save ValidatePayment
  2. From the Components palette, drag and drop Mediator to the Components swimlane.

    Add a mediator
  3. 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
    Create mediator
  4. In the ValidatePayment diagram, wire the ValidateRS proxy service to the RouteData mediator.

    Wire mediator
  5. In the Components swimlane, right-click the RouteData mediator, and select Edit.

    Edit mediator

    The RouteData.mplan page opens.

Adding a Routing Rule to the Mediator for the GET Operation

  1. In the Validate_GET pane, on the RouteData.mplan page, click Create a new Routing Rule.

    Create routing rule
  2. In the Target Type dialog box, select Existing Service, and click OK.

    Existing service
  3. In the Target Services dialog box, expand BPEL Processes, validatePaymentProcess, Services, and validatepaymentprocess_client, select validate, and click OK.

    Validate service
  4. In the Validate_GET pane, on the RouteData.mplan page, click Select an existing mapper file or create a new one.

    Select mapper file

    The Request Transformation Map dialog box opens.

  5. Click Create Mapping.

    Create mapping
  6. On the Create Transformation Map page, accept the default values, and click OK.

    Transformations
  7. In the Request Transformation Map dialog box, click OK.

    Transformation map
  8. 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
    Map nodes
  9. On the RouteData.mplan page, scroll down to the Synchronous Reply pane, and click Select an existing mapper file or create a new one.

    Create mapper
  10. In the Reply Transformation Map dialog box, click Create Mapping.

    Create mapping
  11. On the Create Transformation Map page, accept the default values, and click OK.

    Transformations
  12. In the Reply Transformation Map dialog box, click OK.

    Transformation map
  13. 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:

    Map nodes


Adding a Routing Rule to the Mediator for the POST Operation

  1. On the RouteData.mplan page, scroll down to the Validate_POST pane, and click Create a new Routing Rule.

    Create routing rule
  2. In the Target Type dialog box, select Existing Service, and click OK.

    Existing service
  3. In the Target Services dialog box, expand BPEL Processes, validatePaymentProcess, Services, and validatepaymentprocess_client, select validate, and click OK.

    Validate service
  4. In the Validate_POST pane, on the RouteData.mplan page, click Select an existing mapper file or create a new one.

    Select mapper file
  5. In the Request Transformation Map dialog box, click Create Mapping.

    Create mapping
  6. On the Create Transformation Map page, accept the default values, and click OK.

    Transformations
  7. In the Request Transformation Map dialog box, click OK.

    Transformation map
  8. 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
    Map nodes
  9. On the RouteData.mplan page, scroll down to the Synchronous Reply pane, and click Select an existing mapper file or create a new one.

    Create mapper
  10. In the Reply Transformation Map dialog box, click Create Mapping.

    Create mapping
  11. On the Create Transformation Map page, accept the default values, and click OK.

    Transformations
  12. In the Reply Transformation Map dialog box, click OK.

    Transformation map
  13. 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:

    Map nodes


Deploying a Composite Application

In this section, you deploy a composite application to Integrated WebLogic Server.

  1. In the ValidatePayment diagram, compare your diagram with the following image and save your work before deploying the application.

    ValidatePayment composite
  2. On the Applications tab, right-click ValidatePayment, select Deploy, and then select ValidatePayment.

     Deploy ValidatePayment
  3. 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:

    Summary
  4. On the Deployment - Log tab, verify that the deployment was finished.

    Log

Testing a REST Service

  1. 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
    ValidateRS
  2. 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.

    ValidateRS
  3. 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
    Test Web Service

    Note: If you get any SSLHandshakeException errors when testing the web service, verify the URL starts with http, not https, and the port is 7101.

  4. Click the Response tab, and verify that the response displays the Denied status.

    Response
  5. 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
    Test Web Service

    Note: If you get any SSLHandshakeException errors when testing the web service, verify the URL starts with http, not https, and the port is 7101.

  6. Click the Response tab, and verify that the response displays the Authorized status.

    Response

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

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.