Java EE Web Services with JWS
Web services expose some business logic over the Internet using the HTTP protocol via interfaces described by WSDL. There are several specifications which are part of the Java EE specification including JAX-WS (JSR 224), Web Services 1.2 (JSR 109), JAXB 2.2 (JSR 222), Web Services Metadata 2.0 (JSR 181), and JAXR 1.0 (JSR 93). All together, these specifications are usually referred as the Java Web Services (JWS).
In the GlassFish v3 container, the Metro stack implements the JWS specifications; the Metro stack can also be used as a standalone stack as well. Web services use an annotated POJO model with configuration by exception policy. To expose some business logic it is enough to annotate a class with the @javax.jws.WebService annotation. To define a web service summing a list of integers with a single sumListOfNumbers operation:
@WebService()
public class SummationWebService {
@WebMethod(operationName = "sumListOfNumbers")
public Integer sumListOfNumbers(@WebParam(name = "listOfNumbers")
List listOfNumbers) {
// sum the numbers
}
The @WebMethod annotation specifies the business method of the web service, and the @WebParam annotation specifies the parameter that this operation accepts.
To invoke the web service we generate the stubs from the WSDL of the web service using the JAX-WS tools. The generated stubs handle the underlying details and the client is now easy to implement with a few lines of code:
SummationWebServiceService s = new SummationWebServiceService();
SummationWebService service = s.getPort(SummationWebService.class);
Integer result = service.sumListOfNumbers(nums);
It is also possible to inject a web service stub reference by using the @javax.xml.ws.WebServiceRef annotation. The container generates a stub and injects the stub reference to the annotated field.
After a stub reference is obtained, when we make the web service call, under the hood, the call is encoded in a SOAP message and it is sent to the web service, the service performs the business processing and returns the result as another SOAP message. Finally the client runtime decodes the SOAP message and delivers the result to the application calling the web service.
The sample application is tested on GlassFish v3, you can download the sample code here.
References:
[1] http://javadoc.glassfish.org/javaee6/apidoc/javax/ejb/TimerService.html
[2] Beginning Java EE 6 Platform with GlassFish 3 by Antonio Goncalves
About this entry
You’re currently reading “ Java EE Web Services with JWS ,” an entry on Sirius ICT
- Published:
- 7.26.10 / 4pm
- Category:
- Blog, Development Issues, Thougths and Reflections
No comments
Jump to comment form | comments rss [?] | trackback uri [?]