• No results found

Build Process Order Composite

In document SOASuite12c_Tutorial.pdf (Page 80-117)

You will now create another SOA application that will accept new purchase orders, approve them and forward them to the fulfillment system. You will use a project template to implement the basic order processing scenario, add a call to the payment validation service built in chapter 2 and update the order status in the database based on the outcome of the payment validation.

The order status update will be converted to a BPEL subprocess to make it easily re-usable.

Once completed, your composite will look like this:

High-Level Steps

 Import SOA template.

Before the order is processed, the credit card payment is validated using the validatePayment service built in Chapter 2.

If the payment is denied, the order status is set to Denied and the processing is stopped.

If the payment is authorized, the order status is set to Authorized and the order is processed.

When the order processing is finished, the order status is set to ReadyForShip.

 The Fulfill Order process to pick up orders that are ready to be fulfilled will use this status.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 81 of 392

Steps in Detail Import template

We will start by importing a SOA project template with a number of components already predefined.

These components can:

 Receive an order through a web service call.

Create order number, set order date to current date and set order status =’New’.

 Calculate the total order amount.

 Save the order in the database with status=’New’.

 Return an acknowledgement to the client with the order number.

The template has been provided as part of the resources for the labs, and should be located in the templates folder.

In the previous chapter, we added this location to the list of folders where JDeveloper looks for templates. If you haven’t done that yet, please follow the steps:

In the main JDeveloper menu, select Tools - Preferences

In the Preferences window, select SOA - Templates

Click Add

Navigate to the templates folder

Click Select to accept your choice

 Click OK to close the Preferences window.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 82 of 392

Create a new project ProcessOrder from a project template

In chapter 2, you used project template to accelerate building the Validate Payment service, as well as a custom activity template for the XSLT transformation.

In this section, you will create the ProcessOrder composite (order processing service) based on the provided project template in the e2e-1201-composites application.

Open the e2e-1201-composites application:

Choose File > New > Project… from the menu.

Choose SOA Project

Click OK

Set the following fields:

o Project Name: ProcessOrder

o Directory: Keep the default directory

Click Next

In the next step, choose Start from SOA Template.

If you can’t see ProcessOrderTemplate in the list, click the “+” button to add the folder where your template is located.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 83 of 392

Choose ProcessOrderTemplate.

Click Finish.

A new project with predefined components is created.

Double-click the components and services/references and discover what they do.

Deploy and test the project and make sure there are no errors, following the steps in the section

“Test the SOA project with EM FMWC” in the Appendix.

Use OrderSample_soap.xml (in the sample_input folder) for testing the web service interface.

Please note that this sample file includes the soap envelope needed for testing.

Check if new order records have been created in the database.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 84 of 392

Add the payment validation

The order will only be processed if the payment is valid.

Remember that we already implemented the payment validation in the previous lab. Now we will add a call to invoke this payment validation from process order.

Looking at the ProcessOrder composite, you will see that the BPEL process receiveOrder only sets the order number (which is provided back to the client) and the order date, and then calls

validateAndProcessOrder to validate and process the order.

SOA Suite provides a mechanism to browse services that are deployed in a SOA or Service Bus project in the integrated or a remote application server. The process is detailed below.

There are additional ways to find WSDL services that are available on the file system, in the repository or in other locations.

In this lab, we will browse to the ValidatePS.proxy service, which has been deployed in the same integrated server as the SOA composites.

First, we define a reference to the validate payment service.

In the composite drag-and-drop a SOAP web service into the External References swimlane.

Name it validatePaymentService

Click on the icon next to the WSDL URL field to find the validatePayment WSDL.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 85 of 392

Make sure you select the app server where you deployed the ValidatePayment project.

Select the ValidatePS proxy service

Click OK

 The port is chosen automatically

 Check the box to copy the WSDL file and its dependant artifacts into the project. By doing this, we ensure that the designer does not throw an error when the Service Bus service is not available because the server is down or the service is not deployed.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 86 of 392

Click OK

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 87 of 392

Uncheck “Maintain original directory structure for imported files” and “Rename duplicate files”

Click OK

Now we need to wire the validateAndProcessOrder BPEL process to the newly created SOAP reference

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 88 of 392

Open the validateAndProcessOrder BPEL process and add the call to validatePaymentService.

 You will see that there is now a new partnerlink in the BPEL process for the payment validation.

But let’s first have a look at what has already been defined in the process.

After assigning the order to a process variable, validateAndProcessOrder calculates the total order amount, which is used to validate the payment. Remember, this was an input to the payment validation service.

 The calculation is done through an XSLT map.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 89 of 392

An assign activity then adds the total order amount to the order message.

The writeOrderScope includes all activities involved in writing the order to the database.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 90 of 392

 If the payment is denied, we will cancel the order and update the order status in the database accordingly.

 The last step in the predefined process is to update the status in the database with the value of the status element in the order message. This will be re-used several times in this process:

o To update the order status with the outcome of the payment validation (Denied or Authorized)

o To update the status to ReadyForShip if the payment has been authorized and the order process has been completed.

Now add the remaining activities to the BPEL process. Before you do that, collapse the scopes to make the design look less crowded.

Add an invoke activity between the writeOrderScope and the updateOrderStatusScope. It should be after the Dehydrate activity. The dehydrate activity is needed in the BPEL after the Order is created, and before the validate Payment service is invoked. This will assist in properly handling an error situation if ValidatePayment composite is down, restarted, and failed

instances of Order process are recovered.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 91 of 392

Wire the invoke activity to the validatePaymentService partnerlink

This opens the invoke activity for editing.

 You can choose to continue editing in this dialog or close the dialog and edit in the property editor.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 92 of 392

 Let’s use this dialog for now to make you aware of both options. You’ll be able to decide later which option you prefer.

Change the name of the invoke activity to validatePayment.

Click the “+” sign next to Input to automatically create the input variable for the invoke activity

Click OK

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 93 of 392

 Create the output variable in the same way

Click OK

Click OK

The invoke activity is now complete.

 Check the property inspector.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 94 of 392

 Before the web service can be invoked, the right values must be assigned to the input variable for the web service call.

Add an Assign activity before the just added Invoke activity

 In the General tab of the property inspector, specify the name as assignPaymentInformation

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 95 of 392

Open the Copy Rules tab and launch the Assign Editor

 Assign the payment information (Billing) from the order variable to the input variable of the validatePayment service (validatePayment_validate_inputVariable) by dragging a map from left to right.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 96 of 392

 This creates a new copy rule:

Click OK

 If you see a warning attached to the assign, click the validate check box on top of the BPEL editor. The warning should now go away.

 We now assign the reply from the web service call - the payment status - to the order message.

Add an assign activity after the invoke activity

Call it setPaymentStatus

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 97 of 392

In the Assign Editor, map the payment status in the output variable of the invoke activity to the status in the order variable.

You will see a new copy rule:

Click OK to close the Assign Editor.

The last step in the BPEL process will update the order status in the database with the payment validation result.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 98 of 392

This is a good point to deploy and test the project again. Feel free to also debug the project, and the BPEL processes to get a feel for what they’re doing.

Please follow the steps outlined in “Test the SOA project with EM FMWC” in the Appendix section.

Use OrderSample_soap.xml as sample message.

When you now open the flow instance in EM FMWC and choose the Composites tab, you will see both composites within one flow instance:

ProcessOrder is the initiating composite

ValidatePayment is participating.

You will also see the service bus proxy service as part of the flow trace.

Make sure there are no errors in the flow trace.

 Change the sample message to cause the payment validation to be denied (increase the order items to extend the daily limit of the credit card, the daily limit is $1000).

Also verify that the PaymentStatus sensor is still set correctly.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 99 of 392

Update the order status in the Database

The database adapter, which updates the order status, has already been defined within the ProcessOrder template and an invocation of the service has been added to the

validateAndProcessOrder BPEL process:

This invocation of the database adapter will now update the order status to Denied or Authorized, according to the return value of validatePayment.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 100 of 392

Use an inline BPEL subprocess for the order status update

The order status update will be used at least once more in the same BPEL process. For this, you have to repeat the same assign and invoke activities that we already used.

This is an error prone process and every time a change is necessary, it has to be implemented in all those places.

To avoid this, we introduced a new feature in SOA Suite 12c called a BPEL subprocess.

BPEL sub-processes come in two flavors – standalone, and inline.

About the standalone subprocess:

 This is a fragment of a BPEL process, which includes a number of activities that will be re-used across a number of other BPEL processes.

 The standalone subprocess doesn’t have an interface and can only be called from another BPEL process, but it can have partner links.

 In the composite view, the wire to a subprocess is shown as dotted line to indicate that this is not a wire between actual components.

 We introduced a new “call” activity in BPEL to be able to invoke a subprocess.

 In the first release of SOA Suite 12c, we only support subprocesses in the same composite

 Standalone subprocesses are visible in the component palette.

About the inline subprocess:

 For groups of activities that are re-used within just one BPEL process, you can use an inline subprocess.

 It’s part of the parent BPEL process code and not visible in the composite view.

 We also use a call activity for this.

 You can either define parameters to be set or use the process parameters.

 The inline subprocess is visible in the BPEL palette.

 Activities must be in a scope in order to be converted into a subprocess

 At run-time, the subprocess code is re-entrant and re-usable – only one copy is stored in memory, even if it is called 20 times.

To learn more about BPEL subprocesses, please see chapter Oracle SOA Suite Templates and Reusable Subprocesses in soa-dev-guide.pdf.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 101 of 392

The order status update scope will be converted into an inline BPEL subprocess as it’s only used within the same BPEL process.

Collapse the scope updateOrderStatusScope.

 Right-click on the scope.

Choose Convert to a Subprocess.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 102 of 392

Name it updateOrderStatusSP (By default it uses the scope name)

Leave Replace Scope with Subprocess Call checked. This will automatically replace the current scope with a Call activity

 Optionally set a label, comment and choose an image for your new subprocess.

Click OK

You will now see a new call activity in your process

You can also see the subprocess in the palette under Subprocesses

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 103 of 392

You can see and edit the definition of the subprocess when switching from Main Process to the subprocess on top of the BPEL editor

 You can see all partner links that are available in the main process, in case you want to add another invoke.

 You can make changes to this subprocess, which will be reflected in every call.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 104 of 392

 Before we test the process, let’s change the name of the call activity.

Select the call activity and change the name in the property inspector to updateOrderStatus.

 Deploy, test and debug the process again, the actual result should not change.

 You will notice that you now see the call activity in your audit trail with the activities included in the subprocess:

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 105 of 392

Similarly, in the flow trace, we also show the call activity and all activities included in the subprocess below it:

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 106 of 392

Add an Order Number sensor to the Order Process composite

We already have a sensor for the payment status, now we will also define one for the order number.

At this point, composite sensors can only be set on services and references. The SOAP interface receiveorder_client_ep returns the orderNumber in the order acknowledgement message. That’s where we will define the sensor.

Go to the composite view of the ProcessOrder composite.

Right-click on the SOAP interface receiveorder_client_ep

Choose Configure Sensors

Choose receiveorder_client_ep

 Click the “+” icon to create a new composite sensor

Name: OrderNumber

 This sensor will be created from a variable

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 107 of 392

Pick the OrderNumber in the out message

Click OK

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 108 of 392

 Optionally: use expressions and filters to define the sensor

Make sure Enterprise Manager is checked, so that you can see the sensor in the flowtrace

Click OK

Click OK

 Note the sensor icon

 Deploy and test the composite

 Check to see if the sensor is set in the Flow Trace of the new instance together with the payment status sensor.

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 109 of 392

Update the order status to “ReadyForShip” if the payment has been authorized

If the payment is valid, the order status is set to “ReadyForShip” in the database. This status update will trigger the order fulfillment process, which will be built in a latter chapter.

If the payment is not valid, processing ends here.

First we add an If statement. The order will only continue if the payment was authorized. Otherwise processing is stopped and an email is sent to the customer informing him of his unauthorized payment.

If in BPEL 2.0 is the equivalent of switch in BPEL 1.1.

Open the validateAndProcessOrder BPEL process if it’s not already open

Add an If under the sub process call. (You find the If activity under BPEL Constructs – Structured Activities)

Oracle Confidential – Do not distribute to third parties

Chapter 3: Process Order: Build Process Order Composite Page 110 of 392

We will check if the payment has been ‘Authorized’ or ‘Denied’

Select the If construct and open the property inspector window, if it’s not already open.

Change the name to “IfPaymentValid”

 Edit the condition by clicking the icon for the XPath Expression Builder

 Expand the variable order and enter the status element into the Expression field by clicking

 Expand the variable order and enter the status element into the Expression field by clicking

In document SOASuite12c_Tutorial.pdf (Page 80-117)