|
Simplifying SOA Development with J2EE 5.0
Service-oriented applications are fairly difficult to build with J2EE, so J2EE 5.0 is designed to make development simpler by making use of Web Services Metadata annotations defined by JSR 181. EJB 3.0 and Web Services Metadata have the similar goals of providing developer friendliness.
For developing a simple Java web service in J2EE 1.4, you need several web service artifacts: WSDL, mapping files, and several verbose standard and proprietary web services deployment descriptors. The Web Services Metadata specification is taking a configuration-by-default approach similar to EJB 3.0 to make development easier. The Web Services Metadata annotation processor (or web services assembly tool) will generate these files for you so you only have to worry about the implementation class.
Here is how a simple Java web service looks when it's developed using Web Services Metadata:
package oracle.jr181.demo;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService(name = "HelloWorldService",
targetNamespace = "http://hello/targetNamespace" )
public class HelloWorldService {
@WebMethod public String sayhello(String name ) {
return "Hello” +name+ “ from jws";
}
}
As I mentioned previously, EJB 3.0 is simplifying the development of EJBs by using regular Java classes. By making use of EJB 3.0 and Web Services Metadata, developing EJB-based web services is going to be much simpler. Here is how a simple HelloWorld EJB web service looks when using EJB 3.0 and web services metadata. You do not have to worry about creating WSDL, deployment descriptors, etc., and the application server will take care of generating these artifacts during deployment. package oracle.ejb30.ws;
import javax.ejb.Remote;
import javax.jws.WebService;
@WebService
public interface HelloServiceInf extends java.rmi.Remote{
@WebMethod java.lang.String sayHello(java.lang.String name)
throws java.rmi.RemoteException;
}
The following is the implementation class for the HelloWorld EJB in EJB 3.0:
package oracle.ejb30.ws;
import java.rmi.RemoteException;
import javax.ejb.Stateless;
@Stateless(name="HelloServiceEJB")
public class HelloServiceBean implements HelloServiceInf {
public String sayHello(String name) {
return("Hello "+name +" from first EJB3.0 Web Service");
}
}
The above example clearly demonstrates that service development is going to be much simpler with web services metadata and EJB 3.0.
Conclusion
In this article, you learned the basics of building web services using the J2EE platform. You can start building and deploying your web services in your favorite J2EE-compliant application servers such as Oracle Application Server 10g, Sun Java System Application Sever, etc. today. |
|