224
Developing Client Applications to Use a Web Service
ability and so forth. The developer might configure this endpoint address
dynamically at runtime.
Stubs may be configured statically or dynamically. A stub's static configura
tion is set from the WSDL file description at the time the stub is generated.
Instead of using this static configuration, a client may use methods defined by the
javax.xml.rpc.Stub
interface to dynamically configure stub properties at run
time. Two methods are of particular interest:
_setProperty
to configure stub
properties and
_getProperty
to obtain stub property information. Clients can use
these methods to obtain or configure such properties as the service's endpoint
address, user name, and password.
Generally, it is advisable to cast vendor specific stub implementations into a
j
avax.xml.rpc.Stub
object for configuration. This ensures that configuration is
done in a portable manner and that the application may be run on other JAX RPC
implementations with minimal changes, if any.
Code Example 5.8 shows how a J2EE client might use
Stub
interface methods
to look up and set the endpoint address of a Web service.
Service opcPurchaseOrderSvc =
(Service) ic.lookup(AdventureKeys.PO_SERVICE);
PurchaseOrderIntf port =
opcPurchaseOrderSvc.getPort(PurchaseOrderIntf.class);
((Stub)port)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY,
"http://localhost:8000/webservice/PoEndpointEJB");
Code Example 5.8
Setting Properties on a Stub
In a J2EE environment, the J2EE container reserves the right to use two secu
rity related properties for its own purposes. As a result, J2EE clients using any of
the three communication modes (stub, dynamic proxy, or DII) should not config
ure these two security properties:
javax.xml.rpc.security.auth.username
javax.xml.rpc.security.auth.password
However, J2SE developers do need to set these two security properties if they
invoke a Web service that requires basic authentication. When using DII, the client
New Page 1