Skip to main content

Best way of implementing WebService that uses existing EJB application

Please note these forums are being decommissioned and use the new and improved forums at
No replies
Joined: 2012-05-10

I created EJB server application which communicates well with clients(Java desktop apps). Remote clients just use JNDI lookup to get access to EJBeans deployed on Glassfish server.
After this step I want to extend server application to be more flexible for working with non-Java based clients. I mean browser applications based on Javascript.
The best way is to implement WebService on Glassfish that will call my EJB beans. What I have tried:

1. Created separate "Dynamic Web Project" application in Eclipse calling via JNDI enterpsise beans from the first app. Although WebService was properly deployed it cannot lookup beans from other
application deployed on Glassfish. It was strange because I used portable JNDI names suggested by Glassfish server. Always got Naming
exception "ClassNotFound..." and my lookups from remote clients
worked. After many tries I gave up. (Now I am not sure if calling EJB from another EJB app by WebService app deployed on same Glassfish server is possible)

2. TI found materials how to implement WebService on existing EJB using JAX-WS (@WebService,@WebMethod annotaions). So I didn't have to create
separate WebService application. I just adjusted one of my EJB with mentioned annotaions. This worked fine but I have problems to force JAX-WS to return data in JSON format not in XML(default). I needed JSON.

3. I read more abut implementing WebServices in Java and found (I think the most fresh) approach using JAX-RS. JAX-RS uses annotations like: @Path,@GET,@POST,@Produces...etc
which can turn any class into WebService. The problem is that I cannot access EJB exposed as WebService using JAX-RS because I have no URL path configured.
I have no web.xml file in my Eclipse project where I can configure URL to my EJB. This is because in Eclipse web.xml configuration file is not created for EJB module project - only from Dynamic Web Projects.
I don't know what to do next...

Generally I want to know which of my 1,2,3 approaches is best. In which direction (regarding WebService) should I develop existing EJB module under Eclipse considering my goals below:
1. Solution must use already implemented EJBs in existing application
2. Solution must provide data to clients in JSON format