« Servlet Reveal | Main

The annotation @WebServiceRef

……… 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.

di

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.

 ws

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:

.............
@WebServiceRef
private MyService myService;
...........
MyItem myItem=myService.getMyItemPort();
//use of myItem
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.

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

TrackBack

TrackBack URL for this entry:
http://blogs.oracle.com/mte1521/mt-tb.cgi/12757

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About This Entry

This page contains a single entry from the blog posted on July 6, 2009 11:40 AM.

The previous post in this blog was Servlet Reveal.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type and Oracle