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

# Creating a PurchaseOrder Fulfillment System and Invoking External Services

This chapter describes how to create an AquaLogic Service Bus (ALSB) Control called ServiceProviderAccessControl under the alint.process, and consume ServiceProviderAccessContract.wsdl from the File System.

This chapter discusses the following topics:

- Creating AquaLogic Service Bus Control
- Designing PurchaseOrderFulfillmentJPD
- Invoking External Services
- Verifying Transaction Context Propagation
- Securing External Services

## Creating AquaLogic Service Bus Control

ALSB Control is based on the Beehive controls framework, which is used to invoke the ALSB proxies. The proxies have ALSB Control configured with support for security and transaction context propagation from WLI to ALSB.

External services like inventory system, credit card system, and shipping services are proxy services that can be invoked by the ALSB Control. Before you start creating the ALSB Control, create the PurchaseOrderFulfillmentJPD.

##### To create a Purchase OrderFulfillmentJPD and ALSB Control Using Data Palette

1. Switch to Process perspective from your current perspective in Workspace Studio. To select ALSB perspective, click Windows > Open Perspective > Other....
2. Create a PurchaseOrderFulfillmentJPD. In Package Explorer, right-click on src > alint.process, and select New > Other > WebLogic Integration > Process. In the New Process dialog box, enter `PurchaseOrderFulfillmentJPD` as the Name of the Process. Type `alint.process` as the Package, if the package is not already set, as shown in Figure 4-1.
Figure 4-1 New Process

3. Click Finish.
4. In Data Palette, click the down arrow, and select Integration Controls > ALSB. Figure 4-2 shows how to select ALSB control from Data Palette.
Figure 4-2 Data Palette

The Insert Control : ALSB Control wizard is displayed.

5. In the Field Name dialog box, enter the Field Name, as shown in Figure 4-3.
Figure 4-3 New ALSB Control

Click Next.

6. In the Create Control dialog box, enter the Name of the control as `ServiceProviderAccessControl`. Ensure that alint.process is the Package. Figure 4-4 shows the Create Control dialog box.
Figure 4-4 Create Control

Click Next.

7. Click Import to consume the WSDL from the filesystem, and perform the following:

- Artifact Folder: Click Browse next to the Artifact Folder, and navigate to `UseCaseWeb\src\alint\process`.
- Service Resources: Ensure that Service Resource is File System.
- WSDL Location: Click Browse and navigate to `{TUTORIAL_ROOT}``\ALIntE2EUsecase\ExternalSystems\ExtServiceAccess\Resources` folder and select the ServiceProviderAccessContract.wsdl.
Figure 4-5 Consuming WSDL

Click OK. The values are populated, as shown in Figure 4-6.

Figure 4-6 WSDL Details

Click Next.

8. Select the Provide additional binding information to create ALSB Control check box. The other fields are enabled. In the Service URI field, enter `ServiceProviderAccessProxy`. On JNDI URI, enter `t3://localhost:7001` as shown in Figure 4-7.
Figure 4-7 Additional Binding for ALSB Control

Click Next.

9. Select Use XML Type Beans in the No Existing Types Found dialog box. Click Finish.

The ALSB Control is created in the Controls folder of the Data Palette, as shown in Figure 4-8.

Figure 4-8 ALSB Control in Data Palette

## Designing PurchaseOrderFulfillmentJPD

PurchaseOrderFulfillmentJPD is used for state management and process orchestration.

##### To Design PurchaseOrderFulfillmentJPD

1. Drag and drop Client Request from Node Palette to the Design view of PurchaseOrderFulfillment, as shown in Figure 4-9.
Figure 4-9 Client Request Node

2. Double-click on the Client Request node, enter `fulfillPurchaseOrder` in Method Name, and click Add... on the General Setting tab.
3. In the dialog box that is displayed, add the following variable names:

    java.lang.String orderId

    			org.openuri.purchaseOrder.OrderLineItemInfoDocument orderInfo

    			org.openuri.purchaseOrder.CreditCardInfoDocument creditCardInfo

Table 4-1 lists the parameter and types of these variable names.

Table 4-1 Variable Names
Parameter Name | Type Name
orderId | `String`
orderInfo | `OrderLineItemInfo`
creditCardInfo | `CreditCardInfo`

For more information about creating variables for a JPD, see Creating Variables in Guide to Building Business Process.

4. Click Close. Figure 4-10 shows the parameters of the client request node.
Figure 4-10 Client Request Node - Variable Names

5. Click Receive Data, and assign the variables as shown in Figure 4-11
Figure 4-11 Assigning Variables

6. Create the following variables in the Source view of PurchaseOrderFulfillmentProcess:

    			public org.openuri.purchaseOrder.OrderPriceInfoDocument priceInfo;

    		public CCTransactionInfoDocument ccTranInfoDoc;

    		public org.openuri.purchaseOrder.CCTransactionInfo ccTranInfo;

    		public PurchaseOrderId orderMetadata;

    		public double orderPrice;

Figure 4-12 shows the variable names in Source view.

Note: | In case of compilation errors, add the imports as shown in Figure 4-12 .

Figure 4-12 Create Variables in Source View

1. Edit the fulfillPurchaseOrder method, and add the following assignments:

    orderMetadata = PurchaseOrderId.Factory.newInstance();

    orderMetadata.setOrderId(this.orderId);

Note: | `orderMetadata` is required to publish the results after the inventory and the credit card systems are invoked.

Figure 4-13 shows the fulfillPurchaseOrder method in Source view.

Figure 4-13 fulfillPurchaseOrder Method in Source View

2. Enter the following constants for the credit card and inventory services:

    private static final String CREDIT_CARD_SERVICE = "CreditCardService";

    private static final String INVENTORY_SERVICE = "InventoryService";

You have now added the clientRequest node and the required variables to the ProcessOrderFulfillmentJPD, as shown in Figure 4-14.

Figure 4-14 ProcessOrderFulfillmentJPD

## Invoking External Services

This section describes how to invoke Inventory system and credit card systems:

- To Invoke the Inventory System
- To Invoke the Credit Card System

##### To Invoke the Inventory System

1. In the Data Palette, expand alsbControl, and drag and drop XmlObject accessService(String serviceName_arg,XmlObject_Any_arg) into the PurchaseOrderFulfillmentJPD Design view.
2. Double-click accessService node, and rename node to `updateInventory`. Right-click this updateInventory node, and select View Code. Copy the following code in the Source view:

    public void serviceProviderAccessControlAccessService() throws Exception {

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

            // input transform

            // return method call

            this.priceInfo = org.openuri.purchaseOrder.OrderPriceInfoDocument.Factory.parse(serviceProviderAccessControl.accessService(INVENTORY_SERVICE, this.orderInfoDoc).xmlText());

            // output transform

            // output assignments

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

    System.out.println(“>>>>>>>>Received from update inventory = ” + priceInfo.getOrderPriceInfo ());

    }

Figure 4-15 shows the code in Source view.

Figure 4-15 updateInventory Code

##### To Invoke the Credit Card System

1. From Package Explorer, expand alint.process, and drag and drop ServiceProviderAccessControl into the Data Palette > Controls folder.
2. Expand ServiceProviderAccessControl from the Data Palette, and drag and drop XMlObject accessService(StringserviceName_arg,xmlObject_Any_arg) into PurchaseOrderFulfillmentProcess Design view.
3. Double-click accessService node, and rename node to `transferMoney`. Right-click this transferMoney node, and select View Code. Copy the following code in the Source view:

    public void serviceProviderAccessControlAccessService1() throws Exception {

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

            // input transform

            // return method call

            this.opReceived = serviceProviderAccessControl.accessService(this.CREDIT_CARD_SERVICE, this.ccInfoDoc);

            // output transform

            // output assignments

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

            this.ccTranInfo = org.openuri.purchaseOrder.CCTransactionInfoDocument.Factory.parse(opReceived.xmlText()).getCCTransactionInfo();

            System.out.println(">>>>>>>>>>> Received from transfer money = " + ccTranInfo.getStatus());

        }

Note: | Here you are not calculating the order price that is being passed to the external credit card system. You will calculate it in Aggregating the Purchase Order Fulfillment Results..

## Verifying Transaction Context Propagation

##### To Verify Transaction Context Propagation

1. Right-click PurchaseOrderFulfillmentJPD.java in the src > alint.process folder in Package Explorer, and select Run As > Run on Server.
2. The following URL: `http://localhost:7001/UseCaseWeb/alint/process/PurchaseOrderFulfillmentJPD.jpd` is displayed in the internet browser.
3. Click the Test Soap tab. In the `fulfillPurchaseOrder` XML file, enter the values as follows:

- PurchaseOrderId (any purchase order id)
- CreditCardNumber (1234567890123456)
- ExpiryDate (08/08)
- ItemId (2)

4. Click fulfillPurchaseOrder.

You can now verify the debug messages on the server console that are printed when the purchase order is processed. Note that the Transaction ID is the same in inventory and credit card system debug statements, indicating that they are invoked in context of the same transaction. See Figure 4-16.

Figure 4-16 Debug Messages on Server Console

The transaction context is propagated from the PurchaseOrderFulfillmentJPD to the external systems - credit card service and inventory service.

Business processes in WebLogic Integration are transactional in nature. Every step of a process is executed within the context of a transaction. A transaction ensures that one or more operations execute as an atomic unit of work.

The ALSB control provides an option to propagate the transaction context of the JPD to AquaLogic Service Bus, which can be specified using the annotation provided for the transactional purpose.

Similarly, JPD transport supports optional transaction propagation from ALSB to WLI, which depends on the QOS parameters and propagate transaction attribute in the JPD transport configuration.

## Securing External Services

ALINT supports the propagation of security context. By default, the current authenticated subject (associated with the executing thread) is propagated to ALSB when no principal/credential is specified as part of the `SBTransport` annotation in the ALSB Control (`ServiceProviderAccessControl.java`).

Note: | Switch to the External Systems workspace to secure the external systems. To switch to a new workspace, select File > Switch Workspace....

The external systems, credit card system and inventory system, are protected. The InventorySystem and CreditCardSystem JPDs are available in Package Explorer at the following locations:

- `ExtSystemWeb\src\alint\system\InventorySystemJPD.java`
- `ExtSystemWeb\src\alint\system\CreditCardSystemJPD.java`

You can provide permissions to the administrator to execute the InventorySystem and CreditCardSystem JPDs.

Notes: | In the Source view, `@Security(rolesAllowed="IntegrationAdmin")` is commented. To protect these JPDs from being accessed, remove the comments (`//`) from this annotation in the Source views of the JPDs.

Note: | After you have removed the comment tag, only users with `role = IntegrationAdmin` can execute the InventorySystem and CreditCardSystem JPDs.

The JPDs are protected using the `@Security` annotation, as shown in Figure 4-17.

Figure 4-17 Securing the External Services

After modifying the changes to the JPDs, do the following:

1. In the Package Explorer, go the ExtSystemWeb`` > src > alint > system, right-click on any of the JPDs, for example, InventorySystemJPD, and select Run As > Run on Server:
2. Accept the default values, and click Finish.

Switch to the UseCase workspace that you were using. To switch to a new workspace, select File > Switch Workspace....

The client is authenticated using the `basic auth` method when the `PurchaseOrderProcessingProxy` is invoked. The security context is propagated to the WLI layer (PurchaseOrderFulfillmentJPD) to ALSB (ServiceProviderAccessProxy) to the external systems (inventory and credit card systems).

You can review PurchaseOrderFulfillmentJPD to verify that you do not provide any username and password to access the external services. For information about verifying security context propagation, see Verifying Security Context Propagation.