……… posted by Davide Pisano
To invoke a method on a session bean, a client does not directly instantiate the bean using the new operator. It use the Dependency Injection (DI) to references the session bean. It is a powerful mechanism used from JavaEE 6 to obtain a resource reference on an object field. It is possible to inject various type of resource, as shown in the next picture.
A DI example Using @EJB annotation could be:
Server Code
@Stateless
public class ItemEJB{
.........
Client Code
.........
@EJB ItemEJB itemEJB
..........
Now Shift attention to the annotation WebServiceRef. It provide to injects a reference to a web service. Having a WSDL, is possible write a java proxy (stub) to invoke a Web Service (WS). There are any tools (wsimport or JDeveloper for example) that provide to generate from a WSDL Java classes and interfaces that make possible the WS execution by a client program. Made interfaces are called "Service End-Point interface" (SEI) because it is a Java representation of a WS end-point. the SEI is a proxy that provide to a local java call to the remote WS via HTTP.
The Client can get an instance of the proxy through DI using WebServiceRef. Applying this annotation, the container will injects an instance of the WS. As example if MyService is the service proxy produced by the WSDL using one of the tools mentioned above, it is possible to have:
.............MyService is the SEI and not the WS. The MyService Object MUST extends javax.xml.ws.Service and generaly The Service object is generated by the tool as part of the SEI.
@WebServiceRef
private MyService myService;
...........
MyItem myItem=myService.getMyItemPort();
//use of myItem
If there aren’t containers in our execution environment (it is not a Servlet container, EJB Container or any other that support this annotation), the service class generated by a tool can't be references by the @WebServiceRef annotation but by the new key-word, as in the next example:
.........
MyService myService = new MyService();
MyItem myItem=myService.getMyItemPort();
.........
……… posted by Davide Pisano