Java Reference
In-Depth Information
DYNAMIC PROXY
The creation of a dynamic proxy within JAX-WS is sometimes referred to as the “static” client pro-
gramming model. The client uses the generated SEI that specifies the types for you; you build the
object tree using factory methods required for the service invocation, and the actual request process-
ing is performed by a delegate under the hood.
This delegate is implemented on the fly by a dynamic proxy object. Dynamic proxies were introduced
in Java SE 1.3. They are supported by java.lang.reflect.Proxy , and exist to implement a list
of interfaces specified at runtime. Because of this, the artifacts that JAX-WS creates are fully port-
able. You can move your client code to another platform and not have to use that platform's tools
to regenerate it. This is similar to how stubs worked with the older JAX-RPC model that JAX-WS
replaces, inasmuch as JAX-RPC also used the SEI. Beyond ease of use, the major difference is that
with JAX-RPC, the tools generated platform-specific stubs, forcing you to recreate the client for the
new platform.
Dynamic proxies stand in distinction to the SAAJ model, in which no SEI is generated for you be-
forehand and you piece together the SOAP message yourself, as we saw in Chapter 5 . This is a lot of
work if you are just performing a straightforward invocation as an SEI might, without any tinkering.
But if you want your client program to sew up a SOAP request on the fly based on runtime properties,
SAAJ is fantastic.
You can use wsimport from the command line, or within Ant or Maven. Let's use a simple
calculator web service as an example. The WSDL of your service is located at ht-
tp://localhost:4933/CalculatorApp/CalculatorWSService?wsdl . It defines a single port type, as
in the following code:
<portType name="CalculatorWS">
<operation name="add">
<input message="tns:add"></input>
<output message="tns:addResponse"></output>
</operation>
</portType>
//The service name element is:
<service name="CalculatorWSService">
NOTE
In order to use this recipe, you need a real WSDL deployed somewhere. If you are using NetBeans,
you can set up and deploy this web service in just a few moments. You could also try deploying the
Endpoint from Creating and Deploying the Simplest Web Service , or using a publicly available ser-
vice from somewhere like StrikeIron.com. Each of these options will give you a different level of
complexity in the generated artifacts, as based on the message types.
Search WWH ::




Custom Search