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 |