Friday 25 January 2013

Event Delivery Network

Event Delivery Network allows publish-subscribe type of loose coupling between SCA components. This is similar to JMS/AQ model except that user is spared from remembering and using low level JMS connectivity details. Instead, SOA framework neatly abstracts these details in the Even Delivery Network so that users can purely focus on publishing and subscribing to events.
This approach is highly useful when an event publisher doesn’t know about the number or type of potential subscribers beforehand. Events can be published/subscribed from both as well as components.
In the present example, we will discuss about an event published from BPEL and subscribed by Mediator component. Mediator component shall write the event information to a File on SOA Server to make sure event subscription has successfully been processed.
image
Steps to implement above example:
Step 1. Publish Event using BPEL
Create an SOA project and name it EventDeliveryExample. Select “Composite with BPEL Process” template.
image
image
Create one-way BPEL process and name it EventPublisherProcess. Use following screenshot for other parameter values.
image
Import Order.xsd into the project and select orderDetails as Input element for the BPEL process. Click OK to complete project creation.
image
image
Open composite.xml and click on “Event Definition Creation” icon from top left corner of the window as shown below.
image
Specify “OrderEventDefinition” for EDL File Name.
image
Click on “+” icon in the Events section to create a new event. Select orderDetails element for Element field. Specify “OrderPublishingEvent” for Name field. Click on OK to add event.
image
Click OK from Event Definition dialog.
image
Open EventPublisherProcess from composite.xml. From Component Palette, drag and drop an Invoke activity on to BPEL process.
image
Open Invoke_1 activity. Specify “Invoke_Event” for Name field. Select “Event” as Interaction Type. For Event, select “OrderPublishingEvent” created in the previous steps. Create a new event input variable. Click OK to close Invoke activity.
image
image
Drag and drop an Assign activity. Assign BPEL input variable to event’s input variable.
image image
This completes Event publishing part using BPEL.
Step 2: Subscribe to Event using Mediator component.
Drag and drop a Mediator component on to Components pane in composite.xml. Specify “MediatorSubscriber” as Name. Select “Subscribe to Events” Template. Select “OrderPublishingEvent” from Event section.
image
Now Mediator component has successfully subscribed to OrderPublishingEvent.
image
Lets create a File Adapter to write file to SOA Server’s File System. Drag and drop a “File Adapter” on to “External References” pane.
From Adapter Configuration Wizard, click Next. Enter “OrderWriterService” for Service Name. Click Next and Next again. From Operation dialog, select “Write File” as Operation Type. Specify “WriteOrder” as Operation Name. Click Next.
image image
Enter appropriate Directory Name for Outgoing Files. Specify File Naming Convention as “Order_%SEQ%.txt”. This ensures Order file get a serial number suffix (Example: Order_1.txt, Order_2.txt). Click Next.
image
In Messages section, click on “Define Schema For Native Format” icon next to URL field. Click Next.
image image
Leave default values in “Choose Type” screen.
image
Save following text to Order.txt file and select this file for “File name” field.
ItemName,OrderType,PurchaseDate,FirstName,LastName,AddressLine1,AddressLine2,City,State,Zip,Country
CT,EXPRESS,2011-02-01,Josh,Roy,Flat 14 Sunrise Heights,12 Martin Road,London,Greater London,EXX 5XX,UK
image
Click Next and Next again. Enter appropriate names for Target Namespace. Specify OrderCollection and Order for multiple collection and single record elements respectively. Click Next and Next.
image
From Field Properties section, select “Use the first record as the field names”. Click Next. In the final step, give an appropriate name for generated schema and Finish.
image
From Messages section, click Next and Finish.
image
In composite.xml, wire MediatorSubscriber and OrderWriterService.
image
Double click on MediatorSubcriber. In Static Routing section, click on Transformation icon next to “Transform Using” field. Select “Create New Mapper File” and leave the default name. Click OK.
image
Click on orderDetails  in <sources> and drop on to OrderCollection element in <target>. Save All.
image
Finally, Deploy EventDeliveryExample project. Launch the process by specifying values in Test screen.
image
Order_1.txt should have been created in Outgoing File Directory with the values entered in above screen. This completes the implementation.
You can download the complete JDeveloper project from here.

Oracle B2B Installation

Oracle provides a platform to exchange standard messages between business entities. It comes with pre-built messaging templates and samples. It is part of Oracle . However, we need to separately download and install Oracle Document editor. For traditional Oracle E-Business Suite users, this is similar to XML Gateway, but with more features geared towards SOA implementations.
Installation steps:
Oracle B2B Editor

  • Unzip all three zip files to their respective folders to create ofm_b2b_doc_editor_win_11.1.1.1.0_disk1_1of3, ofm_b2b_doc_editor_win_11.1.1.1.0_disk1_2of3, ofm_b2b_doc_editor_win_11.1.1.1.0_disk1_3of3.
  • Copy contents of Standards directory from ofm_b2b_doc_editor_win_11.1.1.1.0_disk1_2of3, ofm_b2b_doc_editor_win_11.1.1.1.0_disk1_3of3 into ofm_b2b_doc_editor_win_11.1.1.1.0_disk1_1of3/Standards folder.
  • Run ofm_b2b_doc_editor_win_11.1.1.1.0_disk1_1of3/Install.exe. Choose silent mode if you prefer so.
image
  • Finally, installation confirmation screen will appear at the end of installation. I had about 51 folders under STANDARDS section of installation.
image
  • Run from Programs.
image
image
Oracle B2B Console

Java embeded activity Usage

Developing and deploying Java Embedding activity in BPEL 2.0 in SOA Suite 11g calling a custom Java Class that has dependencies on 3rd party libraries

Java Embedded activity can call a custom Java class that relies on 3rd party Java libraries. This means that a lot of existing functionality from the Java open source community is at the disposal of the BPEL developer. This article shows a simple example of developing and deploying a BPEL process that uses Java Embedded Activity that calls a custom Java Class that uses Apache HttpClient to make Http POST calls. The article demonstrates how to develop the BPEL process, the Java Embedded activity, Java Class and how to deploy the SOA Composite application. It also presents the results of running the composite application.

Steps for a simple, straightforward demonstration:
1. Create SOA Composite application in JDeveloper 11g – based on the BPEL template
Image
Image
Image
2. Create the directory Application_Root\project\SCA-INF\lib
3. Copy 3rd party libraries to the directory created in the previous step
Image
4. Create the custom Java Class – in the SCA-INF\src directory
Image
The code of this Java Class is the following – inspired by a previous blog article: http://technology.amis.nl/blog/15098/create-simple-java-application-to-post-json-message-to-cometd-bayeux-channel-using-apache-httpclient-and-maven-style-netbeans-project.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package nl.amis.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
public class HttpPoster {
  public static String postMessageToUrl(String url, String message) {
      DefaultHttpClient httpClient = new DefaultHttpClient();
      String response;
        try {
            response = postToURL(url, message, httpClient);
        } catch (UnsupportedEncodingException e) { response = e.getMessage();
        } catch (IOException e) {
            response = e.getMessage();
        }catch (RuntimeException e) {
            response = e.getMessage();
        }
        httpClient.getConnectionManager().shutdown();
       return response;
  }
  private static String postToURL(String url, String message, DefaultHttpClient httpClient) throws IOException, IllegalStateException, UnsupportedEncodingException, RuntimeException {
      HttpPost postRequest = new HttpPost(url);
      StringEntity input = new StringEntity(message);
      input.setContentType("application/json");
      postRequest.setEntity(input);
      HttpResponse response = httpClient.execute(postRequest);
      if (response.getStatusLine().getStatusCode() != 200) {
          throw new RuntimeException("Failed : HTTP error code : "
                  + response.getStatusLine().getStatusCode());
      }
      BufferedReader br = new BufferedReader(
              new InputStreamReader((response.getEntity().getContent())));
      String output;
      StringBuffer totalOutput = new StringBuffer();
      System.out.println("Output from Server .... \n");
      while ((output = br.readLine()) != null) {
          System.out.println(output);
          totalOutput.append(output);
      }
      return totalOutput.toString();
  }
}
5. Add the 3rd party library JARs to the project definition in JDeveloper:
Image
6. Create the Java Embedding activity in the BPEL process
Image
7. (optionally rename the activity) and Double click the activity to start editing the Java snippet
Image
Image
?
1
2
3
4
5
6
7
String input = ((XMLText)getVariableData("inputVariable", "payload", "/client:process/client:input/text()")).getText();
System.out.println("Hello, World from BPEL with Java Embedded - input = "+input);
String message = "Message from BPEL process instance, invoked with input variable with value "+input;
String url = "http://localhost:7101/PostHandler/postbox";
String response = HttpPoster.postMessageToUrl(url, message);
System.out.println("response after posting message to url "+url+" is "+response);
setVariableData("outputVariable", "payload", "/client:processResponse/client:result", response);
8. Add import statements for the non-JKD classes used in the Java snippet
Image
9. Deploy the SOA Composite applications.
Note: all Java classes in SCA-INF/src and all JAR files in SCA-INF/lib are included in the SAR:
Image
10. Test-run the BPEL process through its Web Service interface
The Java snippet reads an input variable, writes some logging to the console, passes the value of the input variable to the custom Java class that performs an HTTP POST request (handled by an extremely simple Servlet that does nothing but write the request contents to the console and return a standard response). This response is put on the outputVariable by the Java snippet.
When making this call to the BPEL process:
Image
This output is found in the SOA Suite console:
Image
And the output from the Servlet is
Image
Finally the response from the BPEL process – including the response from servlet invoked by the Java snippet:
Image

Resources

Download a zip-file with the SOA Composite application and the extremely simple Servlet project: BPELWithJavaHttpPostInside.zip.

xslt padding with characters call template for left pad and right pad

  Could a call-template be written that took two parameters ?   a string, and a   number) return the string with empty spaces appended t...