uCosminexus Application Server, Web Service Development Guide
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.
Examples of specifying the javax.xml.ws.WebServiceRef annotation are as follows:
...
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.WebServiceRef;
import com.sample.AddNumbersImpl;
import com.sample.AddNumbersImplService;
public class TestClient extends HttpServlet {
// An example of a service class
// Inject a service class instance in a service class type field
@WebServiceRef
private AddNumbersImplService service;
// An example of a port
// Inject a port instance in a port type field
@WebServiceRef(AddNumbersImplService.class)
private AddNumbersImpl port;
@Override
public void init() {
// You need not execute the following processes because the Application server injects a service class and a port before
// starting the Web Service client
//service = new AddNumbersImplService();
//port = service.getAddNumbersImplPort();
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException {
...
|
...
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.WebServiceRef;
import com.sample.AddNumbersImpl;
import com.sample.AddNumbersImplService;
public class TestClient extends HttpServlet {
private AddNumbersImplService service;
private AddNumbersImpl port;
@Override
public void init() {
// You need not execute the following process because the application server injects a service class and a port by using the
// setter method when starting the application
//service = new AddNumbersImplService();
//port = service.getAddNumbersImplPort();
}
// An example of a service class
@WebServiceRef
public void setAddNumbersImplService(AddNumbersImplService service) {
// Inject the service class instances into the service argument
this.service = service;
}
// An example of a port
@WebServiceRef(AddNumbersImplService.class)
public void setAddNumbersImpl(AddNumbersImpl port) {
// Inject the port instances into the port argument
this.port = port;
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException {
...
|
When starting a J2EE application, configure the following settings to generate an instance of a Web Services client.
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:
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:
...
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.WebServiceRef;
import com.sample.AddNumbersImpl;
import com.sample.AddNumbersImplService;
public class TestClient extends HttpServlet {
// Enable the MTOM/XOP specification format attachment in the port to be injected
@MTOM
@WebServiceRef(AddNumberImplService.class)
private AddNumbersImpl port;
@Override
public void init() {
...
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException {
...
|
...
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.WebServiceRef;
import com.sample.AddNumbersImpl;
import com.sample.AddNumbersImplService;
public class TestClient extends HttpServlet {
private AddNumbersImpl port;
@Override
public void init() {
...
}
// Enable the MTOM/XOP specification format attachment in the port to be injected
@MTOM
@WebServiceRef(AddNumberImplService.class)
public void setAddNumbersImpl(AddNumbersImpl port) {
this.port = port;
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException {
...
|
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:
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);
}
...
}
|
All Rights Reserved. Copyright (C) 2013, Hitachi, Ltd.