Meaningless Drivel is fun!*
The moose likes EJB and other Java EE Technologies and the fly likes EJB with Webservice and Remote client view Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB with Webservice and Remote client view" Watch "EJB with Webservice and Remote client view" New topic
Author

EJB with Webservice and Remote client view

Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
Hi

I have a requirement to use EJB 3.1 where only some of its methods will be exposed as webservices and will be consumed by our external client applications where as other components of our application(Servlet etc) should have access to all of its method. At this point,Im not even sure if it is possible with single EJB to achieve both.

E.g. If EJB has 3 method,the external client will be exposed to 1 or 2 method where as the other component of the application should have access to all of the EJB methods.

Thanks in advance.


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 516
    
    4

On the Java class that implements your Web service, specify the @WebMethod annotation on each method that you want to customize for the service. You can use this annotation to exclude a method from your service. By default, all public methods are exposed in a service, including inherited methods that are below the Object class.

http://pic.dhe.ibm.com/infocenter/rsawshlp/v7r5m0/index.jsp?topic=%2Fcom.ibm.ws.jaxws.emitter.doc%2Ftopics%2Ftwsanbuejb.html
http://docs.oracle.com/javaee/5/api/javax/jws/WebMethod.html

So @WebMethod(exclude=false)..


Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
I think I did not post my question properly.

We are using EJB 3.1 which has been exposed as Webserice and this webservice will be consumed by the application outside of our company.

The same EJB can be used by our other part of our applications like another EJB//Servlet running under the same JVM but in different ear or war file.

My question here is can I inject this EJB into another EJB/Servlet or should I call them using Webserice?

Hope my question is clear to you.

Thanks
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 516
    
    4

Sure you can. You expose your EJB using a Web Service endpoint interface and a Remote business interface. You specify the methods you need for each view in the interface (as long as it's not Stateful, of course). You can even use the same interface for the Remote client view and the Web Service endpoint, though that's not necessarily a good idea.

Be advised though, that your parameters and return value have to fulfill all the requirements for both SOAP and EJB.


Then you declare the methods you want to expose in their relevant interfaces. If you want to expose a WebService superset in the remote EJB, you can have the Remote interface extend the Endpoint interface and declare the additional methods... For configuration of the two, check the spec. But they are easy to combine since EJB 3.

You can easily inject the remote view into a Servlet as @EJB, and use the WebService at the same time. It should be possible to reuse the Remote interface as a web service endpoint interface and use @WebMethod annotations to expose the methods you need in the web service as opposed to the remote ejb, but I've never done it as it would look kind of dirty, and it may cause problems later on when changes are required. Better to use two different interfaces.


I hope that answers your question. Otherwise I misunderstood again. :/
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
Thanks Dieter..Exactly what I was looking for.

Tested the same with sample application.

Appreciate your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB with Webservice and Remote client view
 
Similar Threads
Exposing EJB as Webservice...
EJB Transaction Timeout
new to web services
delegate options
Representing VOs