Saturday, February 26, 2011

How to setup a BPEL project in Carbon Studio from an existing BPEL artifact


In this blog post is about how to setup a WSO2 Carbon Studio BPEL project from an existing BPEL artifact.
Suppose there's a BPEL process, and you need to edit it via WSO2 Carbon Studio. We can't directly open a BPEL process via Carbon Studio. First you need to create a BPEL project and import the BPEL process to that BPEL project.

How to create Carbon Studio BPEL project from an existing BPEL process
  • Start Eclipse Carbon Studio. Here you need to make sure you have installed Carbon Studio in Eclipse version you use.
  • In the menu bar goto File -> New -> Other -> BPEL Project . Then the following dialog will appear.

  • Click on Next. Then the following dialog will appear.

  • Add a Project name .Under Configuration click on Modify and put a check on BPEL 2.0 Facet. Click OK.


  • Then click Finish in “New BPEL Project” dialog box.
  • Now the Carbon Studio BPEL project has been created. And now we need to import the process files to this project.
  • For that; first extract a process we have provided. 
  • Then in Carbon Studio; Right click on the project in the “Project Explorer” Window -> Import... Then the following wizard will pop up. Choose “File System”, then click Next.


  • Then the following dialog will appear. And give the location of the previously extracted BPEL process in 7. Then add all the files in that BPEL process. Then Click on Finish.

  • Now the Carbon Studio project is created and you can edit the BPEL process via our editor.


How to deploy and run BPEL projects
  • In Carbon Studio goto File -> Export. Then in the appearing dialog choose "WSO2 BPS BPEL Artifact". Then export the project.
 
  • Add the created BPEL artifact to WSO2 BPS via Web UI.

Friday, February 25, 2011

Java Iterator - Best practices


In a recent code review at WSO2, Afkham Azeez mentioned some java best practices. This was something I didn't knew before. There are two ways to use a java iterator. One method is using a While-loop. The other way is to use For-loop. But the first method can drive you into errors if not correctly handled. Look at the following code.
List<String> list = new ArrayList<String>();
    list.add("1");
    list.add("2");
    list.add("3");

Iterator<String> iter = list.iterator();
    while ( iter.hasNext() ){
      System.out.println( iter.next() );
    }

System.out.println(iter.next());

If you see carefully, now the iterator can been used outside the while-loop and it might throw NoSuchElementException as iter.hasNext() is not called, in each iter.next() call.

By using a for-loop we can avoid this by restricting the iterator to be accessed only inside the for-loop scope.

eg -
List<String> list = new ArrayList<String>();
    list.add("1");
    list.add("2");
    list.add("3");

for ( Iterator<String> iter = list.iterator(); iter.hasNext(); ) {
      System.out.println( iter.next() );
    }