Saturday, December 19, 2020

Migration from GlassFish Application Server 3.1.2 to GlassFish Application Server 5.1 - EJB and Jersey Rest Services

GlassFish Application Server 3.1.2

Had used Enterprise Java Bean(EJB)s for developing Rest services using Jersey 1.x implementation and GlassFish Application Server 3.1.2.  Stateless EJBs were used using the annotations, and a sample EJB was declared as follows:

@Path("email/address")
@Local
@Stateless(name = "emailAddressProvider", mappedName = "ejb/emailAddressProvider")
public class EmailAddressProvider {

    . . .
    // REST methods
    . . .
}

This worked well without any issues, and was able to use call EJB services from other EJBs using the @EJB annotation.

GlassFish Application Server 5.1

GlassFish Applicaiton Server 5.1 supports Rest services implementation of Jersey 2.1.  While migrating the application from GlassFish Application Server 3.1.2 to 5.1, the code which worked well in GlassFish Application Server 3.1.2, failed to be deployed in GlassFish Applicaiton Server 5.1 with the message that the EJB EmailAddressProvider was not found while serving the Rest Services.  After a few trial and errors, and looking at the deployment of the application in the GlassFish Applicaiton Server it was observed that the EJB was named as EmailAddressProvider, and not emailAddressProvider.  Once the EJB name was changed to EmailAddressProvider,  the REST services were functional as expected.  The final sample code used for defining the REST services using EJBs was as follows:

@Path("email/address")
@Local
@Stateless(name = "EmailAddressProvider", mappedName = "ejb/emailAddressProvider")
public class EmailAddressProvider {

    . . .
    // REST methods
    . . .
}