Unmanaged JAX-WS clients do not allow injection of @WebServiceRef or @WebServiceRefs resources

Technote (troubleshooting)


Problem(Abstract)

WebSphere Application Server Version 6.1 Feature Pack for Web Services only supports unmanaged Java™ API for XML-Based Web Services (JAX-WS) clients.

Because these JAX-WS clients are not container-managed, resource injection does not occur for any annotations that might be found within the client such as the @WebServiceRef or @WebServiceRefs annotation. This behavior occurs regardless of whether the resource is a JAX-WS related resource type or some other resource type such as transaction or security. The use of these annotations can produce unexpected behavior.

The following example illustrates an excerpt of JAX-WS client code using the @WebServiceRef annotation. In this example, a NullPointerException exception is produced because resource injection does not occur for a particular service. The injection of the @WebServiceRef resource does not occur because JAX-WS clients are not container managed.


@WebServiceRef
private static MyService service = null;

public static void main(String[] args ) {
try {
port = service.getMyTestPort();
// NullPointerException occurs here because "service" is null;
....

Cause

Because JAX-WS clients are not container-managed, injection of @WebServiceRef or @WebServiceRefs resources does not occur.

Resolving the problem

Do not use @WebServiceRef or @WebServiceRefs annotations in JAX-WS clients.

Alternatively, you can create the reference in the client code.

The following code snippets illustrate how you can create the reference in the client code using client annotations rather than using the @WebServiceRef or @WebServiceRefs annotations for JAX-WS endpoints that are not supported in the Feature Pack for Web Services. These code snippets are based on the example provided in section 7.9.1 of the JAX-WS 2.0 specification.

1. Getting access to a Service Interface

Example 1a - This example demonstrates the supported way to create the reference in the client code to access a service interface.

// The (optional) WSDL Location and Service QName would be specified by the client.
URL wsdlLocation = ...
QName serviceQName = ...
public StockQuoteService stockQuoteService = Service.create(wsdlLocation, serviceQName);

Example 1b - This example demonstrates the unsupported use of the @WebServiceRef annotation for resource injection. With the Feature Pack for Web Services, the values for the @WebServiceRef annotation is null or the value is not initialized depending on how the value is declared. Resource injection does not occur.

// The (optional) WSDL Location and Service QName would be obtained from the JSR-109 client deployment descriptor or as attributes on the annotation.
// which is not supported in WSFP.
@WebServiceRef
public StockQuoteService stockQuoteService;

2. Getting access to a Service Endpoint Interface

Example 2a - This example demonstrates the supported way to create the reference in the client code to access a service endpoint interface.

// You must create the service first, and then get access to the SEI using the getPort.
public StockQuoteService stockQuoteService = Service.create(wsdlLocation, serviceQName);
private StockQuoteProvider = stockQuoteService.getPort(portName, StockQuoteProvider.class);

Example 2b - This example demonstrates the unsupported use of the @WebServiceRef annotation for resource injection to access a service endpoint interface. With the Feature Pack for Web Services, the values for the @WebServiceRef annotation is null or the value is not initialized depending on how the value is declared. Resource injection does not occur.

@WebServiceRef(StockQuoteService.class)
private StockQuoteProvider stockQuoteProvider;


For more information on the supported JAX-WS annotations in the Feature Pack for Web Services, see the "JAX-WS annotations" topic in the Information Center for the Feature Pack for Web Services.

Related information

Release notes for the Feature Pack for Web Services
JAX-WS annotations

Rate this page:

(0 users)Average rating

Add comments

Document information


More support for:

WebSphere Application Server
Web Services (for example: SOAP or UDDI or WSGW or WSIF)

Software version:

6.1

Operating system(s):

AIX, HP-UX, IBM i, Linux, Solaris, Windows

Software edition:

Feature Pack for Web Services

Reference #:

1264135

Modified date:

2007-06-28

Translate my page

Machine Translation

Content navigation