About Me
Facebook
Facebook
Linked In
Linked In
Twitter
Twitter
YouTube
YouTube
Google +
Google +

Friday, May 31, 2013

Developing Web Services using WID & WPS

In this tutorial we are going to learn, compose Web services clients from external WebSphere® servers using SOAP/HTTP to interact with IBM® WebSphere Process Server V7. Implementation of Web Services to invoke from IBM® WebSphere Process Server V7.0 using SOAP/HTTP. Here we are going to use WebSphere Integration Developer for application development.
Service oriented architecture (SOA) enables service clients to invoke service providers in a consistent and flexible manner. WebSphere Process Server and WebSphere Integration Developer together provide a comprehensive set of capabilities for designing, implementing and deploying integration solutions.
In this article, we'll explore Web service bindings in a Process Server environment. We'll look at Web services exposed as SOAP/HTTP, which is hosted on Process Server. You'll also learn how to invoke these Process Server applications through client applications installed on remote non-Process Server environments.
We will also learn how to invoke the Web services using web Service binding and Web Service implementation using WID.
The Business scenario here we are going to explain is to get a Employee details like Employee ID,  Name, Department, Address, Email and Phone no based on Employee ID. The employee details are stored in a XML file and we will get these details by writing Java class.
The following steps need to complete for develop the application.
  • Create Employees XML file.
  • Create a Dynamic Web Project and Create Classes.
  • Generate Web Services.
  • Develop SCA Module and Implementation.
  • Compose Web services client.
  • Test the application.
Create Employees XML file:
Open a Note pad and add the data as shown below and save as Employees.xml in a temp folder.
Create a Dynamic Web Project and Create Classes:
Open Web Sphere Integration Developer V7.0 and open Web Prospective
In WID Window -> Open Prospective -> Others -> select Web -> Click o OK.
In Enterprise Explorer Right click go to Newand select Dynamic Web Project.
Give project name as EAI_EmployeeService, select Target Run time as WebSphere Process Server v7.0, select Dynamic Web Module Version as 2.4, select Configuration as default Configuration for WebSphere Process Server v7.0 and give EAR Project name as EAI_EmployeeServiceEAR then click on finish.
Create Employee class:
Right click on EAI_EmployeeService go to new select Class, give the package name as com.eai.employee, and Name as “Employee” click on finish.
Enter the following code into Employee class.
package com.eai.employee;
public class Employee {
                String EmpID;
                String Name;
                String Designation;
                String Address;
                String Email;
                String Phone;
    public void setEmpID(String EmployeeID)     { 
                EmpID = EmployeeID;  
    } 
    public void setName(String EmpName)      { 
                Name = EmpName;
    }  
    public void setDesignation(String Desg)     { 
                Designation = Desg;
    }
    public void setAddress(String Addr)      { 
                Address = Addr;
    }
    public void setEmail(String EmailID)      { 
                Email = EmailID;
    }
    public void setPhone(String PhoneNo)    { 
                Phone = PhoneNo;
    }
}
Now we need to implement a java class for read the employee data from XML. Create a class with name as “EmployeeService” and enter the following code into EmployeeService.
package com.eai.employee;
import java.net.URL;
import java.util.List;
import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationFactory;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
public class EmployeeService {
                private Configuration config = null;
                public Employee getEmployee(String EmployeeID) throws Exception{
                                System.out.println("***** Enter into getEmployee() *****");
                                System.out.println("***** Attempt to load Employees.xml *****");
                                ConfigurationFactory factory = new ConfigurationFactory();
                                System.out.println("factory"+factory);
                                URL configURL = getClass().getResource("/config.xml");
                                System.out.println("configURL"+configURL);
                                factory.setConfigurationURL(configURL);
                                config = factory.getConfiguration();
                                System.out.println("config"+config);
                                /** Initiate reloading strategy **/
                                XMLConfiguration xmlConfig = (XMLConfiguration)((CompositeConfiguration)config).getConfiguration(0);
                                FileChangedReloadingStrategy fStrategy = new FileChangedReloadingStrategy();
                                fStrategy.setRefreshDelay(5000);
                                xmlConfig.setReloadingStrategy(fStrategy);
                                System.out.println("***** Employees.xml's loaded successfully ! *****");
                                Employee empObj = new Employee();
                                boolean found = false;
                                List<Object> l = config.getList("Employees.Employee.Emp-id");
                                System.out.println("Size of xml data::"+l);
                                if (l==null || l.size()==0){
                                                throw new Exception("Employees Data is empty");
                                }else{
                                                for (int i = 0; i < l.size()&& !found; i++) {
                                                                Object EmpID = l.get(i);
                                                                if (EmployeeID.contains(EmpID.toString())){
                                                                                System.out.println("Employee is matching : "+EmpID);
empObj.setEmpID(EmployeeID);
                                                                                String EName = config.getString("Employees.Employee("+i+").Name");
                                                                                empObj.setName(EName);
                                                                                String Design = config.getString("Employees.Employee("+i+").Designation");
                                                                                empObj.setDesignation(Design);
                                                                                String Address = config.getString("Employees.Employee("+i+").Address");
                                                                                empObj.setAddress(Address);
                                                                                String EMail = config.getString("Employees.Employee("+i+").EMail");
                                                                                empObj.setEmail(EMail);
                                                                                String Phone = config.getString("Employees.Employee("+i+").Phone");
                                                                                empObj.setPhone(Phone);
                                                                                found=true;
                                                                }
                                                }              
                                }
                                System.out.println("***** Exit from getEmployee() *****");
                                return empObj;
                }
}
Generate Web Services:
We can generate web services two ways.
  • Top down approach 
  •  Bottom up approach
Top down approach is where we can generate class from wsdl and bottom up approach is generating wsdl from a class.
Here, we have created class first then generating wsdl from that class, so we are following bottom up approach.
Right click on EmployeeService class go to Web services and select Create Web service.
Select Web Service type Bottom up Java Bean Web Service; make sure you have selected Service Implementation as EmployeeService. In the configuration section, select Server: WebSphere Process Server v7.0, Web Service runtime: IBM WebSphere JAX-RPC, Service Project: EAI_EmployeeService and Service EAR Project: EAI_EmployeeServiceEAR then click on next.
In the Service Endpoint Interface selection screen select all default values and click on next.
In the Web Service Java Bean Identity screen, WSDL port name: EmployeeService, WSDL file: EmployeeService.wsdl, Methods section select getEmployee (java.lang.String)then click on next.
Now our application will take time for publish into WebSphere Process Server. In the next section select finish.
Now our web Service implementation done. It will generate WSDL and XSD’s. Check here for generated files.
Copy the Config.xml and Employees.xml in to EAI_EmployeeService inside src folder.
Develop SCA Module and Implementation
Open WID in Business Integration prospective, Right click and select new-> Library give name as EAI_Libraryclick on finish
Copy the EmployeeService.wsdl from EAI_EmployeeService project and paste into EAI_Library. Now it will show the interface, web Service port and Business Objects in the Library as shown below.
Create a Business Object called as EmployeeInfoBO inEAI_Library and add the following parameters as shown below.
Create an Interface called as EmployeeInterface inEAI_Library, add operation and parameters as shown below.
Create a Module called EAI_EmployeeModulein the business Integration prospective add EAI_Library as dependency.
Right click on Integration Logic select new-> Process
Give name as BP_Employee, click on next select long-running process click on next select interface as EmployeeInterface and operation getEmpInfo then click on finish.
Implement the business Process as shown below.
Open Assembly diagram drag BP_Employee drop into Assembly diagram pallet.
Right click on BP_Employeein Assembly diagram select wire reference to new. It will generate Import component rename as EmployeeServiceWSImport.
Now we need to generate Binding for this import component. Right click on EmployeeServiceWSImport; select Generate Binding -> Web Service Binding.
Select the port EmployeeService, select the transport protocol asSOAP 1.1/HTTP Using JAX-RPC then click on finish.
Then click on ok. Our Module implementation done. We need to generate a Web Service to expose our application to external systems.
Right click on BP_Employee in assembly diagram select Generate Export-> Web Service Binding.
Select the transport protocol as SOAP 1.1/HTTP Using JAX-RPC then click on finish. Now our assembly diagram looks like below figure.
Compose Web services client:
Here we are going to develop Web Service client to communicate with SCA component through web Service.
Right click on EAI_EmployeeModule_EmployeeInterfaceExport1.wsdl from EAI_Lirary select Web Services-> Generate Client.
Select Client type as java Proxy, in the configuration section select Server: WebSphere Process Server v7.0, Web Service runtime: IBM WebSphere JAX-RPC, Client Project: EAI_EmployeeClient, Client EAR Project: EAI_EmployeeClientEAR then click on finish.
Test the application:
Deploy the EAI_EmployeeClientEAR, EAI_EmployeeModule and EAI_EmployeeServiceEAR.
Right click on EAI_EmployeeModule_EmployeeInterfaceExport1.wsdl in EAI_EmployeeClient, select Web Services-> Test with web services Explorer.
Enter EmpID as E111 and click on Go.
The response is shown below.
Verify the log below.
In this article, you've learned how the flexibility of the SCA runtime and client programming model allows Web service clients to invoke Process Server services and how easily communicated with external systems by invoking web services. You can select from many options for client programming based on your unique business requirements: interaction style, operation type, binding type to name a few. We have seen here SOAP/HTTP communication mechanism. We have SOAP/JMS also in web services. This I will post very soon.
File Name
Description
      Size
Download Link
WPS_WS.zip
Working with WS in WPS Sample
1.39 MB
WPS_WS.pdf
Working with WS in WPS Document
   1.24 MB

continue reading

Sunday, May 26, 2013

Improving application performance in IBM BPM V8.0 by using DynaCache

This tutorial describes an easy and efficient caching mechanism based on DynaCachefor IBM® Business Process Manager V8.0. DynaCacheenhances application performance and provides the flexibility to load or flush cache contents at runtime. For ease of understanding and simplicity, the tutorial depicts how to load data that is accessed frequently by the application into DynaCache via a properties file. For any subsequent read cycle, the data is fetched from DynaCache, thereby improving application performance. 
Introduction:
When developing business process management solutions, you frequently require data that is expensive to fetch or compute. To obtain this data, you can connect to a database, invoke a Web service, and so on. If this data does not change over time, you can often achieve significant performance gains with the appropriate use of caching.
IBM BPM product new feature Called DynaCache. DynaCache stores objects and later retrieves and serves them from its cache based on data-matching rules. It creates a unique user-defined "key" to store and retrieve cache items. Think of DynaCacheas a sophisticated Java Hashtable. The code used to provide the in-memory cache services extends the Java Dictionary class, which is the abstract parent of the Hashtable.
The object cache instance is used to store, distribute, and share Java objects. TheDistributedObjectCacheand DistributedMap APIs are provided so that application scan interacts with the object cache instances. Caches are stored in the JVM heap memory. If enabled, DynaCache supports overflow to disk when needed.

The default DynaCache instance is created if the DynaCache service is enabled in the Administrative Console. This default instance is bound to the global Java Naming and Directory Interface (JNDI) namespace using the name services, cache, and distributed map.
This tutorial covers the following topics:
  • Creating the properties File.
  • Creating the business object and service interface.
  • Building the caching component.
  • Testing the caching component
  • IBM Integration Designer V7.5 or above
  • IBM Process Server V7.5 or above
This tutorial is based on a fictional service that retrieves States details, such as Capital City, Population and Official Language. You can implement this retrieval in different ways:
  • Straightforward approaches retrieve the values from a database based on the States name, or invoke a Web service that returns the details.
  • An alternative approach is to use DynaCaching. Since States details rarely change, this particular service is a strong candidate for caching. With this approach, States Details are stored in a properties file. A Java class reads the properties file and loads the values into the cache. This prevents the frequent read calls made for the properties file, and the application can effectively read the values from the cache. This approach improves application performance and also optimizes resource utilization.
In this section, you create a Since States properties file with the States Name mapping to Capital City, Population and Official Language.

Create a new text file and name it StateDetails.propertiesPopulate the properties file as shown in below.

Creating the business object and the service interface 
In this section, you create the business object and the service interface in the library.

Create Library                   

Open Integration Designer with a new workspace, and open the Business Integration perspective.
Right click on Business Integration view select new Library give name as EAI_Library. Select File > New > Library as shown in below.
Name the library EAI_Library and click Finish as shown in Figure below.


Create a business object named StateInfoBO.
Select EAI_Library > New > Business Object as shown in below Figure

Add the fields to the business object as shown in below Figure

 Create the service interface named StateInformationInterface.
Right-click the Interface in the Business Integration Explorer of EAI_Library and create a new interface. Name the interface StateInformationInterface.

Create a request-response operation named getStateInfo with an input parameter called StateName of type String and an output parameter called StateInfo of type StateInfoBO, as shown in below Figure. Save the changes.

 
Select File > New > Module as shown in below Figure to create a new module named EAI_DynaCacheModule and click Next   


Select EAI_Library from the Selected Required Libraries and click Finish as shown in Figure.
Right click on EAI_DynaCacheModule and select Properties. Add com.ibm.ws.runtime.jar as an external JAR file in the Java Build Path as shown in below Figure. This JAR file is located at <AppServer root>/plugins


Expand the EAI_DynaCacheModule under the Business Integration Explorer, and double-click the Assembly Diagram to open it.
Once the Assembly Diagram is open, click Java under the Components category from the Palette, and then click the blank area of the Assembly Diagram.
Rename the Java Component to StateInfoService. Use its pop-up toolbar to add an interface to the component. Use the StateInformationInterface interface for the interface. Save the assembly diagram, and then save all changes.
Double-click the StateInfoService component to generate its implementation. Give the package name as com.bpm.dynacache. A stub method is generated for the getStateInfo operation.
Enter the code snippet shown in Listing 1 for the getStateInfo operation of the StateInfoServiceImplJava class.

Enter the code snippet shown in Listing 2 after the StateInfoServiceImpl constructor to initialize the default DynaCache.

Listing 2. Java code to initialize cache

Save all changes.


In this section, you deploy the module to the test server and verify that the service behaves as expected. On the Assembly Diagram, right-click StateInfoServicecomponent and select Test Component. The Integration Test Client pop-up opens.
In the Initial request parameters panel, populate the SateName field with the value of AP, as shown in below Figure. Verify that the Integration Test Component contains the parameters as shown in below Figure.

Continue the test by selecting the deployment location and click Finish. At this point, your test server starts and your module is deployed automatically.

For the first run, the Java component fetches the State details for AP from the properties file. It then inserts the details into DynaCache. For any subsequent runs, it reads the country details for AP from DynaCache. Verify the response Business Object as shown in below Figure.

Verify via the console, which is shown in below Figure, that the State details were fetched from the properties file and inserted into the cache.
Rerun the same scenario and use the console to verify that for this run, the State details were fetched directly from the cache due to the insertion in the previous step.
This tutorial described how to configure DynaCache. This involved creating a properties file, creating the business object and service interface, building the caching component, and testing the component.



File Name
Description
   Size
Download Link
DynaCache.zip
DynaCacheApplication
12.0 KB
EAI_DynaCache.pdf
 DynaCache Document
  214 KB


continue reading

Designed By AMEER BASHA G