1 of 7
Follow @ObjectComputing
1,541 followers
Tweet
RSS
Introduction:
A bewildering mix of JSRs comprise the Java WS space, both in terms of volume and the subtle relationships among them. We almost need a JSR Modeling Language
(JML) to communicate! Defining JML is too ambitious, but the key JSRs are examined in a historical context, so as to set the stage for JSR 181.
Examples explore the JSR 181 development model.
It is assumed that the reader understands web services as an approach to distributed computing, and has a basic knowledge of web service constructs (e.g. WSDL, SOAP).
All examples require JDK 1.6.x.
JAX-RPC 1.x
JAX-RPC represents the first version of web services in Java. See the graphical overview below. Some key points:
The primary spec, JSR 101 ("Java APIs for XML-based RPC"), defines the APIs and conventions for the Java platform, including the WSDL/Java mapping, the SOAP
binding and SOAP handlers. Version 1.0 was released in mid-2002.
Due to scheduling concerns, the JAX-RPC team elected to define its own facilities to bind data between Java and XML. This was in addition to other, more generalized
data binding solutions.
The state-of-the-JVM in this timeframe was JDK 1.4. JSR 88 defines the general deployment API for J2EE. JSR 109 ("Implementing Enterprise Web Services")
implements this API for the WS space. Note that the best practice of the time was XML-based deployment descriptors: i.e. artifacts to describe web services at
deployment time.
Version 1.1 of JAX-RPC appeared in mid-2003 with support for the WS-I Basic Profile 1.0, to improve interoperability with other technologies.
JAX-WS 2.x
10-Jun-16 11:49 AM
2 of 7.
Seismic Shifts.
JSR 224:
JAX-WS adds support for SOAP 1.2 in addition to SOAP 1.1.
JAX-WS will support WS-I Basic Profile 1.1 as it continues to evolve.
JAX-WS may support WSDL 2.0 in JAX-WS version 2.1+
However, the following goals are more interesting:
JAX-WS delegates data binding of Java/XML to JAXB 2.x (aka JSR 222).
JAX-WS "aligns with and complements" the annotations defined by JSR 181. That is, just as JAX-RPC/JSR 109 defines a deployment time facility for the Java/WSDL
mapping, JAX-WS works with JSR 181 to define a development time facility for this mapping, using Java 5 annotations (aka JSR 175).
See the graphical overview below. There are several themes here:
JAX-WS uses delegation to leverage facilities provided by the modern JDK (JAXB and annotations). This is classic division of labor. Note: the diagram shows JSRs, yet
we can loosely apply the OO ideas of composition and encapsulation.
Within the JAX-WS space itself, JSR 224 delegates some work to JSR 181. More on this coming up.
With development time annotations, clearly JAX-WS responds to the criticisms of JAX-RPC with respect to the complex, antiquated nature of deployment descriptors.
A Closer Look
The stage is set for JSR 181: let's dig in.
10-Jun-16 11:49 AM
3 of 7
Example 1: Concatenator
Before listing all of the available annotations in JSR 181, we'll start small, to get a view of the landscape of the JAX-WS tools. The first example (available here) is a trivial
"string concatenation" service.
Server Side Concatenation):
Run the Java6 apt tool on the source code. The JSR 181 processor will generate the necessary artifacts; apt compiles the Java code as well.
Run the Concatenator.main() method.
Once the server is running, we can point a browser to:
10-Jun-16 11:49 AM
4 of 7
Presto! With stunning ease, the web service is available, and follows these JSR 224 conventions:
The targetNamespace for the WSDL is the Java package, with reversed tokens.
The identifiers for service, port, binding and other WSDL elements follow the natural convention by decorating the original SIB name, Concatenator.
The schema types are published to the URI:.
Client Side Concatenation:
Use the wsimport tool to generate the client side support classes for the web service. The generation is predicated on the same WSDL URI shown earlier: wsimport
accepts the WSDL as input and generates/compiles the classes. This example uses a parameter to "keep" the generated classes for viewing.
Compile and run the Client class
10-Jun-16 11:49 AM
5 of 7
build_client:
[javac] Compiling 1 source file to C:\measter\src\jsr181\ex1\client\classes
run_client:
[exec] result = Hello Web Services!
BUILD SUCCESSFUL
Total time: 11 seconds
Recap Annotations
The last example demonstrates the JAX-WS tools. However, the annotations are the heart of JSR 181. The table below gives a broad look at the available annotations:
Annotation
@WebService
Description
Marks a class/interface as a web service
Allows overrides for outer WSDL attributes: targetNamespace, wsdlLocation, portName
@WebMethod
@Oneway
@SOAPBinding
@WebParam
@WebResult
javax.jws.WebService;
javax.jws.WebMethod;
javax.jws.soap.SOAPBinding;
javax.xml.ws.Endpoint;
@WebService(
name="myConcatenatorType",
serviceName="myConcatService",
targetNamespace=""
)
@SOAPBinding(
style=SOAPBinding.Style.RPC
)
public class Concatenator {
// as before
}
10-Jun-16 11:49 AM
6 of 7:
The @WebService annotation overrides the name of the web service, as we don't want a legacy name to be published. Also, @SOAPBinding is overridden to be RPC
style.
The getEstimate method returns an OrderRecord, but we override the name to be "Estimate" in the WSDL.
The placeOrder uses an INOUT parameter: the OrderRecord comes in with populated "estimate" fields and should leave with all fields populated. Note that JAX-WS
enables INOUT params with the Holder<T> class.
@Oneway adds the self-titled semantic to the confirmReceipt method,; }
}
10-Jun-16 11:49 AM
7 of 7
That's it for the server! The client steps through the use case of getting an estimate, making an order and confirming receipt. As with Example 1, JSR 181 and JAX-WS
perform an astounding amount of heavy lifting.
In Productionthe.
JAX-WS RI
The reference implemenation (RI) for JAX-WS is located here. Here is a quick road-map regarding the RI:
Version 2.0 is bundled with Java 6, but exists as a separate download for Java 5. (Strictly speaking, it requires only the annotation support in Java 5.)
Version 2.0.1 existed only as an intermediate version to transition to version 2.1. However, due to a technical issue, version 2.1 required changes to the API and spec,
and is no longer available. At this writing, version 2.1.1 is the most current release.
Some highlights of new features in version 2.1.1:
Ant and Maven support for wsimport and wsgen tools.
Support for standards such as SOAP 1.2 and WS-I Basic Profile 1.1.
Extension support for the WS-* specs within the WSIT umbrella.
Summary!"
Example Notes
The examples in this article use Java 1.6.0, and Ant 1.6.x. It is assumed that Java and Ant are installed on the machine. The first example is inspired by a blog post by
Vivek Pandey.
10-Jun-16 11:49 AM