O'Reilly logo

Java EE 6 with GlassFish 3 Application Server by David R. Heffelfinger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exposing EJBs as web services

In addition to creating web services, as described in the previous section, public methods of stateless session beans can easily be exposed as web services. The following example illustrates how to do this:

package net.ensode.glassfishbook;

import javax.ejb.Stateless;
import javax.jws.WebService;

@Stateless
@WebService
public class DecToHexBean 
{
  public String convertDecToHex(int i) 
  {
    return Integer.toHexString(i);
  }
}

As we can see, the only thing we need to do to expose a stateless session bean's public methods is decorate its class declaration with the @WebService annotation. Needless to say, as the class is a session bean, it also needs to be decorated with the @Stateless annotation.

Just like regular stateless session ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required