OSB 12c - Create REST Business Service

Here we go!
Information that you need to know:

Introduction to Business Services

Business services are Service Bus definitions of the enterprise services with which you want to exchange messages. They define enterprise web services to which Service Bus is a client. Those external web services are implemented in and hosted by external systems, so Service Bus must know what to invoke, how to invoke it, and what to expect as a result. Business services model those interfaces so that Service Bus can invoke the external services.

You define business services using WSDL (Web Services Definition Language) or Web Application Definition Language (WADL), just as you would define a proxy service. A business service configuration includes its interface, transport settings, and security settings. If the business service is based on a WSDL document, the configuration also includes a WSDL port or a WSDL binding.

You can base business services on existing WSDL and WADL documents, including those imported from a UDDI registry, SOA Oracle Metadata Services (MDS) Repository, an application server, or the file system. Service Bus also supports business services that use the REST binding (see Creating REST Services with Oracle Service Bus ). These services are based on WADL documents and can only be created using the Service Bus Overview Editor in JDeveloper.

For more detailed information read the following URL: https://docs.oracle.com/middleware/12211/osb/develop/GUID-B932E48E-8DDA-4C3D-B600-CBE2C510CED6.htm#OSBDV2168

How to Create a Business Service

A business service communicates with the external systems with which you share data. You can create a business service by dragging either an adapter or a transport from the Components window to the External Services lane. Adapters and transports are under Technology, Applications, and Advanced in the Components window.

Creating a Business Service with an Adapter
When you use a JCA adapter to create a business service, Service Bus generates a concrete WSDL file along with the business service. The WSDL file generated for the JCA adapter is abstract. The concrete WSDL file has the text "concrete" appended to the file name.

For more detailed information read the following URL: https://docs.oracle.com/middleware/12211/osb/develop/GUID-B932E48E-8DDA-4C3D-B600-CBE2C510CED6.htm#OSBDV2166

Business Service Role in Message Processing

Business services are the interfaces that connect with service producers. The business service interface is defined in terms of Web Services Description Language (WSDL) or Web Application Definition Language (WADL) and the type of transport it uses.

For more detailed information read the following URL: https://docs.oracle.com/middleware/12211/osb/develop/GUID-2CFA406F-66DF-44F1-894B-CFD7EC66CEB1.htm#OSBDV87901

In this post, we will learn how create OSB Project with REST Business Service component.

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 Service Bus Application item.

For example:

On the Application window, set the next values, and click on finish button.
Application Name  TrainingOSB
Directory  C:\JDeveloper\mywork\Training\TrainingOSB
Application Package Prefix 

For example:

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

For example:

Then on the New Gallery window, choose Projects option in General Category, then choose Service Bus Project item.

For example:

On the Project window, set the next values, and click on next button.
Project Name  RESTBusinessService
Directory  C:\JDeveloper\mywork\Training\TrainingOSB\RESTBusinessService

For example:

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

Then the next step, we need go to RESTBusinessService directory and create the following folders (required in accordance with project standards (naming conventions)):

  • BusinessServices
  • ProxyServices
  • WSDLs
  • Schemas
  • Transformations
--> ProxyService folder to place/store/save the proxy services which ends with .proxy
--> BusinessService folder to place/store/save the Business Services which ends with .bix
--> WSDLs folder to store all required artifacts WSDL type
--> Schemas folder to store all required artifacts Schema type
--> Transformations folder to store all required artifacts Transformation type

For example:

Click on Refresh icon, then select Refresh Application, now we are going to view the folders that we created in the previous step.

For example:

We are going to create the XML schema, so for this we need to select the Schemas folder and right-click, then in the options of the pop-up list we must select New -> XML Schema...

Note: An XML Schema describes the structure of an XML document. The XML Schema language is also referred to as XML Schema Definition (XSD).

On Create XML Schema window, we need put the following values:

File Name  RESTBusinessService
Directory  C:\JDeveloper\mywork\Training\TrainingOSB\RESTBusinessService\Schemas
Target Namespace   
Prefix   

For example:

We need to update the XSD file with only two elements, these are process and processResponse both are string type.

For example:
Design
Source

The next step create a contract –> we will create new WSDL for contract with single input and single output, so for this we need to select the WSDLs folder and right-click, then in the options of the pop-up list we must select New -> WSDL (builder)...

For the Interface Type, choose "Synchronous Interface" from two options available –> which will enable the input, output and fault elements to be entered for inputs, outputs and faults respectively.

Basically the information entered in the Create WSDL window should be the following:

File Name  RESTBusinessService.wsdl
Directory  C:\JDeveloper\mywork\Training\TrainingOSB\RESTBusinessService\WSDLs
Namespace  http://xmlns.oracle.com/TrainingOSB/RESTBusinessService/RESTBusinessService
Binding  execute_bind
Binding Type  SOAP 1.2
Create Port Type  Selected
Port Type  execute_ptt
Operation  execute
Interface Type  Synchronous Interface
Input  Message Part Name: request
Output  Message Part Name: response
Fault   

Note: Click green plus icon to add the required elements for input, output and fault (on right-top-corner).

Click OK.

The WSDL have the following design.


Note: It may be of your interest, read about from SOAP 1.1 to SOAP 1.2 in the following URL: https://www.w3.org/2003/06/soap11-soap12

Then, in the next step, we must create the REST Business Service, for this we must select the REST (Service Bus.Service Bus) component, this component is on the right side, in the Components section, when you find this, select it and drag it to External Services section.

Or we can just right click on the External Services section and select the REST option.

Then on REST Binding Configuration Wizard - Step 1 of 2, we are going to fill the fields according to the following table. Click Next.

Name  RestReference
Type  Reference
Reference will be invoked by components using WSDL interfaces  Unchecked

For example:

Then on REST Binding Configuration Wizard - Step 2 of 2, we are going to create our Resources, as a first option we can to select a WADL Document URL.

Note: After the WADL is selected, the Resources and Methods sections should be completed automatically. For this practice I used a REST service that basically makes a GET (task) to WMS External System.

For example:


As a second option we are going to create the wadl manually.

Note: Basically we are going to create the same wadl that we selected in the previous step, the first key condition that we need is to know the host: port, having this we will complete the URI field with this information, then we have to add the Resource Path and as a final step, add the necessary methods and parameters by Resource Path.

For example:

Once the creation of the REST Business Service is finished, we are having the following appearance as a result.
For example:

Then the next step, we need to create the Pipeline service, to do we need select the Pipeline component, this component is located on the right side, on Components section, when you found this, select it and drag it to Pipelines/Split Joins section on work area (canvas).

FOR YOUR INFORMATION: Pipelines define message routing and transformation logic, as well as message handling options. This logic includes activities such as transformation, publishing, logging, reporting, alerts, and exception management. Each of these activities are configured as individual actions within the message flow.

The following primary elements are used to construct a pipeline:

  • A start node.
  • A pipeline pair, one for the request and one for the response. Each pipeline in a pair consists of a sequence of stages that specify actions to perform during request or response processing.
  • A branch node, to branch based on the values in designated parts of the message or message context, or to branch based on the operation invoked.
  • A route node, to define the message destination. The default route node is an echo node that reflects the request as the response.
  • An error handler, which can be attached to any node or stage to handle potential errors at that location.

Then on Create Pipeline Service - Step 1 of 2, we are going to fill the fields according to the following table.

Service Name  RESTBusinessServicePipeline
Location  C:\JDeveloper\mywork\Training\TrainingOSB\RESTBusinessService\ProxyServices
Description   
From Template  Unchecked

For example:

Then on Create Pipeline Service - Step 2 of 2, we are going to fill the fields according to the following table.

WSDL  RESTBusinessService/WSDLs/RESTBusinessService
Binding  execute_bind
Expose as a Proxy Service  Checked
Proxy Name  RESTBusinessServicePipelineProxyService
Proxy Location  C:\JDeveloper\mywork\Training\TrainingOSB\RESTBusinessService\ProxyServices
Proxy Transport  http

Basically we are going to select the WSDL that we created previously, and check the Expose as a Proxy Service field.

For example:

FOR YOUR INFORMATION: Proxy services are Service Bus definitions of generic intermediary web services that are hosted locally on Service Bus. A proxy service communicates with external services through interfaces, which may or may not be identical to that of a service provider or service consumer Business Service. Through pipelines, you can route messages from a proxy service to multiple Business Services using their configured independent interfaces.

Once completed the previous steps, your JDeveloper should be the following appearance.

We are going to do double click on the RESTBusinessServicePipeline component, right after, the RESTBusinessServicePipeline.pipeline will open, as you can see in the following image.

Then we are going to locate the Pipeline Pair component, select it and drag it to the start node (below the RESTBusinessServicePipeline service), having as a result the following appearance:

We are going to change the names of Stages, use the following table for your reference.

Stage1 (Request Pipeline -> RequestStage
Stage1 (Response Pipeline -> ResponseStage

For example:

Then we are going to locate the Service Callout component, select it and drag it to RequestStage node.

For example:

Now we are going to update the Service Callout component, we must select the Service Callout component, with this action the Properties section should be displayed.

For example:


Now the next step is to click on Browse icon, then select the Business Service component, for this exercise the name I gave it is RestReference.bix, in Resource Chooser page select it.

For example:


So we need to update the Properties using as a reference the following table.

Service  RESTBusinessService/BusinessService/RestReference.bix
Operation  GetTask * The operation name is the one you put when you created the REST Business Service
Configuration  Configure Payload Document
Request Payload  getRequest
Response Payload  getResponse

For example:

Then we are going to locate the Insert component, select it and drag it to Request Action node.

For example:

FOR YOUR INFORMATION:
Configuring Actions in Stages and Route Nodes
Actions provide instructions for handling messages in pipeline stages, error handler stages, and route nodes. The context determines which actions are available, as described in the following sections:

  • Communication Actions
  • Flow Control Actions
  • Message Processing Actions
  • Reporting Actions
Message Processing Actions
Action  Insert
Used to...  Insert the result of an XQuery or XSLT expression at an identified place relative to nodes selected by an XPath expression.
Available in 
  • Pipeline stage
  • Error handler stage
  • Route node
For more detailed information read the following URL: https://docs.oracle.com/middleware/1213/osb/develop/GUID-FE2CAC5B-E4DF-49DE-AD3C-36EEAF750BFE.htm#OSBDV2366

Adding Insert Actions
To add an insert action:

1. Navigate to where you want to add the action.
2. Click the appropriate icon, then select Add an Action > Message Processing > Insert.
3. Click Expression to edit an XQuery expression. The XQuery expression is used to create the data that will be inserted at a specified location in a named variable. The XQuery Expression Editor page is displayed.
4. When you finish editing the expression, select the relative location from the list. The relative location is used to control where the insert is performed relative to the result of the XPath expression.
* Before: As sibling before each element or attribute selected by the XPath expression.
* After: As sibling after each element or attribute selected by the XPath expression.
* As first child of: As first child of each element identified by the XPath expression. An error occurs if the result of the XPath returns attributes.
* As last child of: As last child of each element identified by the XPath expression. An error occurs if the XPath returns attributes.
5. Click XPath. The XPath Expression Editor page is displayed.
* XQuery and XPath expressions both return elements.
* The XQuery and XPath expressions both return attributes—in which case, the XQuery expression must return attributes.
6. When you finish editing the XPath expression, enter a context variable in the in variable field. The XPath evaluates the contents of this variable.

For more detailed information read the following URL: https://docs.oracle.com/middleware/1213/osb/develop/GUID-97AB0C09-A8CF-48CD-A173-C2A568B8A2DE.htm#OSBDV2503

To fill the Insert - Properties, use the following table as a reference.

Value (XQuery expression
Position (Relative location as first child of
Location  outbound
XPath  ./ctx:transport/ctx:request


For example:

Then we are going to locate the Assign component, select it and drag it to Response Action node.

Value  fn:replace($getResponse,'""',"null")
Variable  getResponse

For example:

In the next step we are going to locate the nSXD Translate component, select it and drag it to Response Action node.

Translate  Native to XML
Input  $getResponse
nXSD Schema  Static (RESTBusinessService/Resources/RestReference.xsd)
Output  Variable (GetResponseXMLMsg)
Enforce Schema Order  Unchecked

For example:

Cheer up! We are almost done, as the penultimate step we are going to locate the Transport Header component, select it and drag it to Response Action node.

Direction  Inbound Response
Copy Headers  Unchecked
Headers  Set > Content-Type > "application/xml"

For example:

Once completed the previous steps the Pipeline should be have the following design.

For example:

The last step is create a jar configuration file to can deploy it on OSB Console.



Note: If you need additional information about how to do this activity, click on the following link .

Comments

Post a Comment

Popular posts from this blog

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

SOA 12c - FTP Adapter (List Files)

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