SOA 12c - HelloWorld Rest Service

Here we go! 
Information that you need to know: 

What Are RESTful Web Services?

RESTful web services are built to work best on the Web. Representational State Transfer (REST) is an architectural style that specifies constraints, such as the uniform interface, that if applied to a web service induce desirable properties, such as performance, scalability, and modifiability, that enable services to work best on the Web. In the REST architectural style, data and functionality are considered resources and are accessed using Uniform Resource Identifiers (URIs), typically links on the Web. The resources are acted upon by using a set of simple, well-defined operations. The REST architectural style constrains an architecture to a client/server architecture and is designed to use a stateless communication protocol, typically HTTP. In the REST architecture style, clients and servers exchange representations of resources by using a standardized interface and protocol.

The following principles encourage RESTful applications to be simple, lightweight, and fast:

Resource identification through URI: A RESTful web service exposes a set of resources that identify the targets of the interaction with its clients. Resources are identified by URIs, which provide a global addressing space for resource and service discovery. See The @Path Annotation and URI Path Templates for more information.

Uniform interface: Resources are manipulated using a fixed set of four create, read, update, delete operations: PUT, GET, POST, and DELETE. PUT creates a new resource, which can be then deleted by using DELETE. GET retrieves the current state of a resource in some representation. POST transfers a new state onto a resource. See Responding to HTTP Methods and Requests for more information.

Self-descriptive messages: Resources are decoupled from their representation so that their content can be accessed in a variety of formats, such as HTML, XML, plain text, PDF, JPEG, JSON, and others. Metadata about the resource is available and used, for example, to control caching, detect transmission errors, negotiate the appropriate representation format, and perform authentication or access control. See Responding to HTTP Methods and Requests and Using Entity Providers to Map HTTP Response and Request Entity Bodies for more information.

Stateful interactions through hyperlinks: Every interaction with a resource is stateless; that is, request messages are self-contained. Stateful interactions are based on the concept of explicit state transfer. Several techniques exist to exchange state, such as URI rewriting, cookies, and hidden form fields. State can be embedded in response messages to point to valid future states of the interaction. See Using Entity Providers to Map HTTP Response and Request Entity Bodies and “Building URIs” in the JAX-RS Overview document for more information.

For more detailed information read the following URL: https://docs.oracle.com/javaee/6/tutorial/doc/gijqy.html

In this post, we will learn how create our first SOA Application type REST.

The next images are the SOA Project execution: 

We need to start the JDeveloper IDE.

Click on File menu, then click on New option, followed immediately by Application option.

For Example: 

Then on the New Gallery window, choose Applications option in General Category, then choose SOA Application item.

For Example:

On the Application window, set the next values, and click on next button. 

Application Name helloWorldRest
Directory C:\JDeveloper\mywork\helloWorldRest
Application Package Prefix

For example:

On the Project window, set the next values, and click on next button. 

Project Name  helloWorldRest
Directory C:\JDeveloper\mywork\helloWorldRest

For Example:

On the Configure SOA settings window, set the next values, and click on finish button.

Standard Composite  Empty Composite

For example:

After clicking on finish button, the JDeveloper IDE has the next appearance: 

Then the next step, we need to select the BPEL Process component, this component is located on the right side, on Components section, when you found this, select it and drag it to Components section on work area.

For Example: 

On the Create BPEL Process window, set the next values, and click on ok button.

BPEL Specification BPEL 2.0 Specification
Name HelloWorldRestBPELProcess
Namespace http://xmlns.oracle.com/helloWorldRest/helloWorldRest/HelloWorldRestBPELProcess
Directory C:\JDeveloper\mywork\helloWorldRest\helloWorldRest\SOA\BPEL
Template Type WebService
Template Synchronous BPEL Process
Service Name helloworldrestbpelprocess_client
Expose as a SOAP Service Unchecked
Transaction required
Input {http://xmlns.oracle.com/helloWorldRest/helloWorldRest/HelloWorldRestBPELProcess}process
Output {http://xmlns.oracle.com/helloWorldRest/helloWorldRest/HelloWorldRestBPELProcess}processResponse

For example:

Now we are going to do right click on the inbound arrow on the bpel and choose the option Expose as REST

For example:

Then on REST Binding Configuration window (Step 1), enter the RestService value, you can change the value if you like, click on next button.

For example:

Then on REST Binding Configuration window (Step 2), configure the Resources. In the Resource Path click on edit button and enter resource name SimpleRequest and click on ok button.

For example:

Then click on edit button on Operation Bindings.
Then on REST Operation Binding window, select POST as HTTP Verb and In the Request tab check JSON as payload.

For example:

In the Response tab check JSON as payload. Click on ok button.

For example:

Resources and Operation Bindings gets configured. Click finish button.

Now the BPEL component gets exposed as REST Service.

Now we are going to do double click on component: HelloWorldRestBPELProcess. Automatically the .bpel tab is displayed, this is the work area of the BPEL component.

For example:

We need to drag the Assign activity to work area between receiveInput and replyOutput components.

For example:

Now we need to double click on AssignReplyOut activity.
Then on Edit Assign window, we are going to assign the value of the input variable to the result variable, the purpose of this is to identify if our payload works well, since our input will be in json format, and at the end from the execution it will return a json format again.

JSON (Request) --> BPEL (XML) --> JSON(Response)

For example:

Now the next step is create a jar file to can deploy it on WebLogic Server, we need to select the helloWorldRest project and right click, then chose the helloWorldRest... option. 

On the Deployment Action window, set the next values, and click on next button.
Deployment Action  Generate SAR File

For example:


On the Deployment Configuration window, set the next values, and click on next button.
New Revision ID  1.0

For example:


On the Deployment Summary window, click on Finish button.
For example:

If all steps were successful, then you will view on yours JDeveloper IDE the correctly deployment.
For example:

Comments

Popular posts from this blog

SOA 12c - Fault Handling (Creating Fault Policies and Fault Bindings)

SOA 12c - DB Adapter (Poll for New or Changed Records in a Table)

SOA 12c - DB Adapter (Perform an Operation on a Table)