Inside Scoop on J2EE : Tips and tricks on J2EE and Oracle Application Server by Debu Panda
Updated: 2/22/2006; 8:58:35 AM.

 

Subscribe to "Inside Scoop on J2EE" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Monday, February 20, 2006

Development of EJB3 Web service with Web services metadata (JSR-181)  is real easy. You just annotate the end-point interface with @WebService annotation, compile, package as ejb-jar in an EAR and deploy in Java EE server like OC4J 10.1.3 that supports both EJB3 and Web services metadata.  

 

 

I got few questions from customer, how do I access an EJB3 web service? What context root does it get bound to by default ?

 

Unfortunately this is server specific!  So let me take an example and illustrate how this works in OC4J 10.1.3.

 

Following is an example of a service endpoint for a HelloWorld web service

 

import javax.jws.WebService;

import javax.jws.WebMethod;

 

@WebService

public interface HelloServiceInf extends java.rmi.Remote{

    @WebMethod java.lang.String sayHello(java.lang.String name) throws java.rmi.RemoteException;

 

}

 

The actual bean class, which provides the implementation of the EJB, is just a plain Java class that implements the endpoint interface.

 

@Stateless(name="HelloServiceEJB")

public class HelloServiceBean implements HelloServiceInf {

 

     public String sayHello(String name) {

        return("Hello "+name +" from first EJB3.0 Web Service");

    }

 

}

 

You compile, package and deploy to OC4J. The server does all heavy lifting tasks such as generation of WSDL, mapping file and other artifacts during deployment and binding this web service to a context URI.

 

  

In OC4J 10.1.3, you can access a EJB web service from the following URL http://host:port/<;ejb-jar-Name>/EJBName

 

If you have an EJB webservice with class named HelloWorldBean packaged in ejb1.jar then you can access the service at http://host:port/ejb1/HelloWorldBean. However if you have used the @Stateless(name="HelloServiceEJB") as in our example then the URI becomes http://host:port/ejb1/HelloServiceEJB

 

The question that to comes mind that how do I change the context root or end-point URI or webservice port for an EJB3 web service. JSR-181 does not standardize specifying any such configurations and left open to the vendors.

 

There are two ways to specify you want to specify your EJB3 web service:

 

1. Package an oracle-webservices.xml with information. For example, if I want to change my context root for the EJB3 web service then I’ve the following in the oracle-webervices.xml:

 <context-root>/mywebservice</context-root>

 

2. The other option is to use our proprietary annotation if you really hate XML:oracle.webservices.annotations.Deployment

 

 

Following is an example of Oracle’s deployment annotation:

 

@Deployment(contextPath="mywebservice",

            uriPath="myhelloservice",

            portName="HelloServicePort")

 

See documentation at  for details on this annotation.

 

Hope this helps! 


6:04:58 AM    comment []

© Copyright 2006 Debu Panda.

PS: These are my own thoughts and not of my employer ..



Click here to visit the Radio UserLand website.
 


February 2006
Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28        
Dec   Mar