O'Reilly logo

Java SOA Cookbook by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Consuming a Web Service from a Servlet or EJB

Problem

You have an EJB, servlet, or other container-managed resource that you want to act as the client for your web service.

Solution

Use the @WebServiceRef annotation to inject a reference to the service you want to invoke. Note that this does not have to be only a servlet or EJB. You might also want to invoke a web service from other container-managed resources, such as a Filter, a SessionContextListener, a ServletContextListener, or a TagHandler depending on your use case.

Using @WebServiceRef, you can get a reference to a web service and an injection target for it. Items annotated with @WebServiceRef follow the standard rules for resource injection within Java EE 5. It defines five attributes or properties, as are described in Table 6-1.

Table 6-1. @WebServiceRef properties

PropertyDescription
nameA name that identifies the reference to the component using the resource, as a JNDI name. If annotating a field, the default is the name of the field. If annotating a method, the default is the name of the Java Bean property the method defines. If annotating a class, there is no default.
wsdlLocationThe URL pointing to the WSDL for the referenced web service. This is necessary if you define your own WSDL in a physical file and include it with your WAR or EAR.
typeThe resource class type. If annotating a field, the default value is the type of the field. If annotating a method, the default is the same as the Java Bean property. If annotating a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required