Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB with Webservice and Remote client view

 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)..
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dieter..Exactly what I was looking for.

Tested the same with sample application.

Appreciate your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic