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

Comments:

Thankyou for all your efforts that you have put in this. very interesting information.

Posted by uroda on April 24, 2011 at 11:36 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

.. useful blog on java and middleware technologies.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today