# Tutorial: Designing a Purchase Order Processing System by Using AquaLogic Integrator

# Actionable Exception Management

This chapter describes the use of worklist for enabling actionable exception management. This chapter explains how to modify the PurchaseOrderFulfillmentJPD to create a worklist task in case of any exception. You will be reusing the worklist artifacts from the downloaded application {TUTORIAL_ROOT}.

This chapter discusses the following topics:

- Enabling Worklist Facets
- Importing Worklist Projects
- Modifying PurchaseOrderFulfillmentJPD for Exception Handling
- Modifying the Purchase Order Aggregator JPD to Handle Errors
- Modifying the PurchaseOrderProcessingServiceProxy to Save the Incoming Messages for Future Reference
- Providing Anonymous Access to Task Plan
- Testing Actionable Exception Management

## Enabling Worklist Facets

This section describes how to enable the worklist project facets to the EAR and Webapp projects.

##### To Enable Worklist Facets

1. Select the EAR folder (UseCase) from Package Explorer.
2. Right-click on the UseCase folder, select Properties.
3. In the Properties for UseCase dialog box, select Project Facets.
4. Click Add/Remove Project Facets....
5. Select AquaLogic Core Facet, and WebLogic Integration Worklist Application Module.
6. Similarly, right-click UseCaseWeb, and select Properties.
7. In the Properties for UseCaseWeb dialog box, click Add/Remove Project Facets.... Select Beehive Controls, Struts, and WebLogic Integration Worklist Application Module.

### Copying Files Required to Enable Actionable Exception Management

Copy the following files into your workspace:

1. Copy PublishError.java from `<TUTORIAL_ROOT>`\ALIntE2EUsecase\UsecaseApp\UseCaseWeb\src\alint\process
   \helper`` into the src\alint.process.helper folder.
2. Copy PublishErrorServiceBrokerControl.java from `<TUTORIAL_ROOT>`\ALIntE2EUsecase\UsecaseApp\UseCaseWeb\src\alint\process into the src\alint.process folder.
3. Copy the following files:

- CreatePOErrorHandlingTask.java
- CreatePOErrorHandlingTaskService.wsdl
- CreatePOErrorHandlingTaskServiceControl.java

from `<TUTORIAL_ROOT>`\ALIntE2EUsecase\UsecaseApp\UseCaseWeb\src\alint\errorhandling\ws into src\alint.errorhandler folder.

## Importing Worklist Projects

This section describes how to import Worklist projects into the workspace, in which you are building your Purchase Order Application.

Note: | You have created a new workspace in Loading the Sample Application

##### To Import Worklist Projects

1. From the BEA WorkSpace Studio menu, click File > Import > General > Existing Projects into Workspace. The Import dialog box is displayed.
2. In the Import Projects dialog box, browse to the directory `<TUTORIAL_ROOT>`/`ALIntE2EUsecase/UsecaseApp` where the tutorial sample application is installed. Select the following files from Project pane:

- Callback Handler
- UsecaseEH
- UsecaseEHWeb

These files are now displayed in Package Explorer.

3. From Package Explorer, right-click on Callback Handler, and select Properties.
4. In the Properties for Callback Handler window, select ALSB Configuration. In the ALSB Configuration pane, select ServiceAccessConfiguration, and click Apply.

The Worklist - related files are imported to the workspace.

## Modifying PurchaseOrderFulfillmentJPD for Exception Handling

1. In Package Explorer, go to src > alint.process > PurchaseOrderFulfillmentJPD.java.
2. Drag and drop the ErrorInfoPublishControl.java into Data Palette.
3. Right-click on the PurchaseOrderFulfillmentJPD in the Design view, and select Add Exception Path to create an Exception Path.
4. From the Data Palette > Controls > publishErrorServiceBrokerControl, drag and drop the void publishError method into the onException path. Right click and select View Code.
5. Copy the following code and paste it into the Source view.

`public void publishErrorServiceBrokerControlPublishError() throws Exception {`

`String errorInfo = context.getExceptionInfo().getException().getMessage();`

`// #START: CODE GENERATED - PROTECTED SECTION - you can safely add code above this comment in this method. #//`

`// input transform`

`// method call`

`publishErrorServiceBrokerControl.publishError(this.orderMetadata, errorInfo);`

`// output transform`

`// output assignments`

`// #END : CODE GENERATED - PROTECTED SECTION - you can safely add code below this comment in this method. #//`

`}`

## Modifying the Purchase Order Aggregator JPD to Handle Errors

Open the PurchaseOrderAggregatorJPD from src\alint.process.

##### To Modify the POAggregatorJPD

1. Drag and drop ErrorInfoSubscriptionControl.java from src\alint.process.control into the Data Palette.
2. In the Source view of the JPD, type the following annotation, before the control declaration line:

    @SubscriptionControl.ClassSubscription(channelName = "/ALIntPOApp/ErrorInfo",

            xquery = "data($metadata)",

            xqueryVersion = com.bea.wli.common.XQuery.Version.v2004)

3. Expand the errorInfoSubscriptionControl.java from the Data Palette > Controls folder.
4. Drag and drop the void subsrcibeWithFilterValue, after the ccTxInfoSbscrptnn node in the Design view.
5. Double click on this node. In the Send Data tab, select order Id from Select variables to assign drop-down list.
6. Drag and drop a Parallel node from the Node Palette. The PurchaseOrderAggregatorJPD is now updated as shown in Figure 9-1.
Figure 9-1 Parallel Nodes to the JPD

7. Drag and drop the Parallel node, accessService node, and the archiveOrder node under the first Branch on this newly created Parallel node. The updated JPD is as shown in Figure 9-4.
Figure 9-2 Updated POAggregatorJPD

8. From the Data Palette > Controls > errorInfoSubscriptionControl, drag and drop void onMessage method to the empty parallel branch.
9. Double click onMessage. In the Receive Data tab, select create a new variable from create variables to assign drop-down list.
10. In the Create Variable dialog box, enter errorMessage as the Variable Name. Click OK.

Click Close.

11. Drag and drop a Perform node from the Node Palette under this onMessage node.
12. Rename node to `moveFileToError`.
13. Right-click on this node, and select View Code. Add the following code:

    File orderFile = new File("C:/ALIntApp/PurchaseOrder/New/PO-" + orderId + ".xml");

    orderFile.renameTo(new File("C:/ALIntApp/PurchaseOrder/Error/PO-" + orderId + ".xml"));

14. Drag and drop CreatePOErrorHandlingTaskServiceControl from src > alint.errorhandling.ws into the Data Palette.
15. From the createPoErrorHandlingTaskServiceControl, drag and drop void CreateTask method to the Design view.
16. Right-click on createTask, and select View Code. Edit the arguments of the method:

    createPOErrorHandlingTaskServiceControl.createTask(this.customerName,this.orderId, this.errorMessage, callback.getEndPoint().toExternalForm(), context.getService().getConversationID());

You have now created a worklist task using a webservice wrapper.

## Modifying the PurchaseOrderProcessingServiceProxy to Save the Incoming Messages for Future Reference

##### To Modify the PurchaseOrderProcessing Proxy

1. Open the message flow for PurchaseOrderProcessingProxy.
2. Drag and drop a publish node, so that it is the first node in the pipe line you have already created.

Note: | The pipeline has already been configured to publish to PurchaseOrderAggregatorJPD and PurchaseOrderFulfillmentJPD. The new publish node you are adding will be before these two.

3. Drag and drop Stage Actions > Transport Headers into the Publish node.
4. In the Transport Header Properties pane, ensure Direction is `Outbound Request`.
5. Click on Add Header.
6. Select file and filename from drop down lists in the Name pane.
7. For the expression, Set Header To give the following value:

    $body/pur:PurchaseOrder/pur:PurchaseOrderId/text()

Figure 9-3 Properties of Transport Header

8. Save the proxy.

You have now modified the proxy message flow to save the incoming purchase order to your file system for future reference. The modified proxy, with the transport header is shown in

Figure 9-4 Modified PO Processing Proxy

## Providing Anonymous Access to Task Plan

The `ReprocessPOHandlerJPD.java` located at `UsecaseApp\UsecaseEHWeb\src\alint\errorhandling` needs to access task data and reprocess the Purchase Order.

##### To Provide Anonymous Access

1. Log on to Worklist Console: `http://localhost7001/worklistconsole`.

For example, you can provide User Name/ Password as `weblogic`/`weblogic`.

2. From the Worklist System Instance, expand UsecaseEH.
3. Click `/task_plans/POExceptionHandlingTaskPlan`.
4. Click Edit in Task Plan Policies pane.
5. From the Task Plan Policies pane, select add Admin, and Anonymous roles to the Selected Roles column from the Available Roles for Admin, Update, Create, and Query as shown in Figure 9-5.
Figure 9-5 Selecting Roles

6. Click Submit.

The Task Plan policies get updated.

## Testing Actionable Exception Management

After you have published the sample application, enter invalid data in the sample application browser. For example in the Soap body of the TestClient, provide a wrong PurchaseOrder ID. To verify actionable exception management, log on to the Worklist User Portal, and reprocess the error. Also, for more information about testing the sample application, see Testing the Application.

The following steps in this section describes how to verify Actionable Exception Management:

- To Enter Values in the TestClient
- To Verify the Values in Worklist User Portal
- To Modify the .XML File
- To Reprocess the Order in Worklist User Portal

##### To Enter Values in the TestClient

1. In the `http://localhost:7001/UseCaseWeb/alint/client/test/TestClient.jpd`, click TestSoap.
2. In the `SOAP body`, enter the values as follows:

- PurchaseOrderId (POMarch11)
- CreditCardNumber (1234567890123456)
- ExpiryDate (08/08)
- ItemId (XYZ)

Note: | The PurchaseOrderId, and the ItemId are different from the values in the database. See Testing the Application.

3. Click clientRequest1.
4. Click Refresh on the browser.

An exception is thrown, and this can be viewed on the WebLogic Server console as shown in Figure 9-6:

Figure 9-6 Failure Message on WLS Console

##### To Verify the Values in Worklist User Portal

1. Logon to `http://localhost:7001/UsecaseEHWeb/user.portal`.
2. The Purchase Order (PurchaseOrder-POMarch11) you created is listed in the list of Upcoming Tasks. Click PurchaseOrder-POMarch11.
3. In Properties pane of the Task Work window, note that the Rejection Code is the ItemId (XYZ), you specified To Enter Values in the TestClient, as shown in Figure 9-7.
Figure 9-7 Properties Pane

In the next steps, you can correct the values in the Worklist User Portal and reprocess the order, without any exceptions, after modifying the `.xml` file that is now created in the `ALIntApp\Purchase Order\Error` folder. See Creating the Tutorial Environment, for creating these folders.

##### To Modify the .XML File

1. Select the `PO-POMarch11.xml` that is created in `ALIntApp\Purchase Order\Error folder`.
2. Edit the ItemId in `PO-POMarch11.xml` file by providing the following values, by entering the IdemId as `1`.
3. Save the `PO-POMarch11.xml` file`.`

##### To Reprocess the Order in Worklist User Portal

1. Logon to `http://localhost:7001/UsecaseEHWeb/user.portal`.
2. Click Show all tasks in this view from the Upcoming Tasks pane.
3. Click PurchaseOrder-POMarch11 from Task Name column.

The Task Work window is displayed.

4. Click Work.
5. In the next screen, click Reprocess Purchase Order, under Actions pane. Click Next.
6. Enter the desired values for Reviewer Comments, ReviewerContact, ReviewedBy, as shown in Figure 9-8.
Figure 9-8 Reprocessing Purchase Order

7. Click Submit.

The Purchase Order is reprocessed with the correct values, and the transactions are displayed on the WLS console as shown in Figure 9-9.

Figure 9-9 Transaction Completed Message on WLS Console

8. In the `http://localhost:7001/UseCaseWeb/alint/client/test/TestClient.jpd` browser, click Refresh.

The callback message is displayed as shown in Figure 9-9.

Figure 9-10 Callback Message