To code service sample, SampleService.java is needed. It has the
following contains:
- Import java.io.Serializable:
public class SampleService implements Serializable{
//default counter is 100
protected int counter = 100;
//add the counter for the inc number
public String addCounter(String inc){
if (inc != null) {
counter = counter + Integer.parseInt(inc);
} else {
counter++;
}
return String.valueOf(counter);
}
//set default value
public void initialize(String dseInit){
counter = Integer.parseInt(dseInit);
}
//substract counter by dec number
public String subtractCounter(String dec){
if (dec != null){
counter = counter - Integer.parseInt(dec);
} else{
counter--;
}
return String.valueOf(counter);
}
}
This is a JavaBean or a POJO, which provides two functions
as addCouneter() and substractCounter().
- Other works for coding this application is a Drag-Drop using RAD.
Create Stateful and Stateless using the class as superclass and create
AccessBean at same time:
- For the Webservice, create JSR109 service using the generated Stateless
EJB. Then open the client module, add a service reference that refers to the
new generated JSR109 service.
- For the main() invocation, create the StatefullEJBService/StatelessEJBService
class that extends from the corresponding generated AccessBean and JSR109Serivce
extends from the generated Proxy classes. Each of them will implement the
Externalizable interface and parse any tag as needed.
- For the PoolService invocation, make a new class SamplePoolService extends
from SampleService and implements PoolableObject interface, that's all. Then
in the DemoPoolService servlet, the code can be doing in any way to demonstrate
the typical pool usage. There are none logical code in the Web Module, only
the interface implementation.