uCosminexus Application Server, Web Service Development Guide

[Contents][Glossary][Index][Back][Next]

10.21.1 Injecting service classes and ports

When you specify the javax.xml.ws.WebServiceRef annotation in the following fields or methods of the Web Services clients operating on the J2EE server, the J2EE server generates and injects a service class and port when generating a Web Services class instance. For the javax.xml.ws.WebServiceRef annotation, see 19.3 Support range of annotations.

Using the javax.xml.ws.WebServiceRef annotation for injection has the following advantages:

For generating the Web Services client instances, see 10.21.1(2) Generating a Web Services client instance.

Notes
  • You can specify the javax.xml.ws.WebServiceRef annotation only when implementing a Web Services client as a servlet or an EJB, and not when implementing a Web Services client as any other application. For example, you cannot inject a service class or a port in the command line application Web Services clients.
  • Generate a service class or a port instance only once, that is, when starting a J2EE application. Generate only one instance for each service class or port in which the javax.xml.ws.WebServiceRef annotation is specified.
  • Inject a service class or a port every time you generate an instance of a Web Services client.
  • While implementing a Web Services client as an EJB by enabling the pooling in Stateless Session Bean, you can generate instances of multiple Web Services clients when starting a J2EE application. In such cases, generate one instance of a service class or a port in which the javax.xml.ws.WebServiceRef annotation is specified and inject this generated instance in every instance of the Web Services client. For generating Web Services client instances, see 10.21.1(2) Generating an instance of a Web Services client.
  • If the configuration is such that the Web Service A is invoked from the Web Service B, you cannot inject a service class or a port of the Web Service B to the Web Service A by specifying the javax.xml.ws.WebServiceRef annotation.
  • You cannot specify the javax.xml.ws.WebServiceRef annotation in a class which references a Web Services client.
  • You cannot use the reload functionality to replace a J2EE application that uses the javax.xml.ws.WebServiceRef annotation to inject a service class or port. To replace a J2EE application of this type, first stop and delete the application to be replaced and then import and start the new application. For details on the reload functionality, see uCosminexus Application Server Common Container Functionality Guide.
Organization of this subsection
(1) Example of specifying the javax.xml.ws.WebServiceRef annotation
(2) Generating an instance of a Web Services client
(3) Using the handler framework
(4) Enabling features
(5) Changing the properties of a request context

(1) Example of specifying the javax.xml.ws.WebServiceRef annotation

Examples of specifying the javax.xml.ws.WebServiceRef annotation are as follows:

(2) Generating an instance of a Web Services client

When starting a J2EE application, configure the following settings to generate an instance of a Web Services client.

For a servlet
Specify the load-on-startup element in web.xml of the WAR file with a Web Services client. If you do not want to specify the load-on-startup element, generate the instances when running the first Web application. For details, see uCosminexus Application Server Web Container Functionality Guide .

For EJB
Set the pooling in Stateless Session Beans to enabled state. Generate the number of instances equivalent to the minimum pooling in Stateless Session Beans when starting a J2EE application. When not using the pooling in Stateless Session Beans, generate an instance when running the first J2EE application. For details, see uCosminexus Application Server EJB Container Functionality Guide.

Notes
In an environment where the Web Services client and Web Service to connect to, are both deployed to the same J2EE server, an error (KDJW40043-E) occurs while injecting ports or service classes when starting the J2EE server.
Troubleshooting if injection fails:
  • In the wsdlLocation element of the javax.xml.ws.WebServiceRef annotation, specify the WSDL document stored locally by using the relative path or absolute path.
  • Stop the J2EE application that has the Web Services client before you stop the J2EE server. Restart the J2EE server and then start the Web Services client.
  • Deploy Web Service and the Web Services client on different J2EE servers. First, start the J2EE server on which Web Service is deployed and then start the J2EE server on which the Web Services client is deployed.
  • Perform the settings such that you can reference the WSDL document that was locally stored when injecting a service class or a port, by using the catalog functionality.

(3) Using the handler framework

When using the handler framework in a service class or port injected by specifying the javax.xml.ws.WebServiceRef annotation, set the handler chain by using the APIs. For the handler chain settings, see 36.9.2 Setting the handler chain in the Web Services client. We recommend that you configure the handler chain settings when initializing a Web Services client because you need to perform the settings for ports only once. You need not perform the handler chain settings for ports every time you invoke Web Service. You can use the following methods for initializing a Web Services client:

Implementing a Web Services client as a servlet
A method in which the init method or the javax.annotation.PostConstruct annotation is specified

Implementing a Web Services client as an EJB
A method in which the javax.annotation.PostConstruct annotation is specified

(4) Enabling features

By concurrently specifying the javax.xml.ws.WebServiceRef annotation and the annotation for features in the port type fields or in the setter method for port type fields, you can enable the features of the port to be injected. The features will be enabled only if you specify the javax.xml.ws.WebServiceRef annotation in the fields in which the annotation for features is specified or in the setter method for the fields. You, however, cannot specify the annotation for features in the service class type fields or in the setter method for the fields.

When enabling the features, you can specify the following annotations in the ports. For annotations, see 16.2 Customized mapping from Java to WSDL.

You can use attachments in the MTOM/XOP specification format on the ports to be injected, if you enable the feature as follows:

(5) Changing the properties of a request context

We recommend that you change the request context properties of ports to be injected when initializing the Web Services client. You can use the following methods for initializing the Web Services client:

The method of implementing as a servlet
A method in which the init method or the javax.annotation.PostConstruct annotation is specified

The method of implementing as an EJB
A method in which the javax.annotation.PostConstruct annotation is specified

Notes
In the Web Services clients that share a single port across multiple threads, if you change the request context properties of the port while multiple threads are operating, communication errors might occur or invalid SOAP messages might be sent. Therefore, you must change the request context properties of the port that is shared across multiple threads before the shared threads start operating.

You can change the request context properties of a port in the Web Services client that is implemented as a servlet as follows:

...
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.WebServiceRef;
 
import com.sample.AddNumbersImpl;
import com.sample.AddNumbersImplService;
 
public class TestClient extends HttpServlet {
 
    @WebServiceRef(AddNumbersImplService.class)
    AddNumbersImpl port;
 
    @Override
    public void init() {
        // Set the request context during initialization
        Map<String, Object> context = ((BindingProvider)port).getRequestContext();
        context.put("com.cosminexus.jaxws.connect.timeout", 60000);
    }
    ...
}