Figure 5. Associate an interface with the generated service component
Now the interface is associated with the component. We can use the "generate implementation" option to generate the implementation framework.
Figure 6. New Service component generation and implementation
Figure 7. Add the implementation to the generated framework
We need to add the implementation of the convert method to the above class, as shown below:
Listing 1. Convert method implementation
Public double convert (double Celsius ){
Double dcelsius = Celsius. doublevalue ();
Double Fahr;
Fahr = (0.9/0.5) * dcelsius) + 32 );
Return New Double (Fahr );
}
Associate service components with independent references
Next, we will create an independent reference and associate it with the service component so that the JSP client can access the component through the independent reference.
Figure 8. Create an independent reference
You can use the "add reference" button to associate temperatureconverterinterface. WSDL with an independent reference. By default, the independent reference is named temperatureconverterinterfacepartner.
Figure 9. Connecting independent references to service components
Create a client and access the service through independent references
Next, we need to develop the client JSP to test the service components. This JSP will allow users to enter the degree Celsius value. Then JSP will pass the value to the service to convert it to Fahrenheit, and finally display the result.
Figure 10. New JSP file template
The following servicemanager class is used to call components through JSP.
List 2. jsp implementation
String cel = request. getparameter ("Celcius ");
If (cel! = NULL & cel. Length ()> 0 ){
Try {
Servicemanager = new servicemanager ();
Service = (service) servicemanager. locateservice
("Temperatureconverterinterfacepartner ");
Double celdouble = double. valueof (CEL );
Dataobject respobject = (dataobject) service. Invoke ("convert", celdouble );
If (respobject! = NULL ){
Out. println (respobject. getdouble ("Fahrenheit "));
}
} Catch (exception e ){
// Handele it
}
}
Package and deploy applications in WebSphere ESB
Components and clients are now ready and can be packaged and deployed in WebSphere ESB for testing. Export the application as integration module ear, as shown below.
Figure 11. Export a project as an integration module
Figure 12. Export the integration module
Deploy the ear file in WebSphere ESB through the Admin console and access its "url" in the browser ".
Figure 13. Final output
Conclusion
Through this article, you have learned how to use the bottom-up method (from interface to implementation) to create a service component and how to publish it in IBM WebSphere ESB. In addition, I learned how to access this service component from the client through independent references.