6-16 Getting Started With JAX-WS Web Services for Oracle WebLogic Server
extends GenericServlet { ...
private BackendServiceService _service; ...
Client ID ClientIdentityFeature clientIdFeature =
new ClientIdentityFeatureMyBackendServiceAsyncClient; features.addclientIdFeature;
... _features = features.toArraynew WebServiceFeature[features.size];
... BackendService port = _service.getBackendServicePort_features;
... java.io.Closeable_port.close;
} }
6.6.2 Accessing the Server-generated Client ID
Client IDs that are generated automatically by the server use the following format: applicationname[_applicationversion]:componentname:uniqueID
Where:
■
applicationname —Name of the application hosting the client.
■
applicationversion —Version of the application. Only used if multiple
versions of the same application is running simultaneously.
■
componentname —Name of the component Web application or EJB hosting the
client.
■
uniqueID —Calculated based on the information that is available when the client
instance is created. The uniqueID is constructed by choosing one of the following whichever is available:
– Web service reference name, as defined by the WebServiceRef annotation.
– [portNamespaceURI:portLocalName][:][endpointAddress]
—port name, endpoint address, or both separated by a colon.
– Port class simple name.
The following information, when available, may also be concatenated to the uniqueID
, separated by a colon :, in the order presented below:
– WSDL location minus ?wsdl
– Features used to create the client instance, represented by the features class
name and separated by dash -.
Note: As described in this section, in order to ensure that the client
ID is unique, the server-generated version may be long and difficult to read. To guarantee that the client ID is presented in a user-friendly
format, it is recommended that you define the client ID during port initialization, as described in
Section 6.6.1, Defining the Client ID During Port Initialization
.
Invoking Web Services 6-17
For example, assume that you deploy a Web service client with the following information associated with it:
■
Application name: example
■
Component: Web application called BestPracticeClient
■
Port name: http:exampleBackendServicePort
■
Port class: BackendService
■
WSDL: jar:file:E:p4devsrc1034wlsmoduleswseetestserverbuil
doutputexampleBackendService.warWEB-INFBackendServiceSe rvice.wsdl
The server-generated client ID will be: example:BestPracticeClient:http:example:BackendServicePort:jar:file:E:p4dev
src1034wlsmoduleswseetestserverbuildoutputexampleBackendService.warWEB- INFBackendServiceService.wsdl:AsyncClientTransportFeature-ClientIdentityFeature
Each time the code is executed, assuming it is in the same containment hierarchy, the same client ID is generated. This provides a stable client ID that can be used across
server VM instances and allows for asynchronous responses to be delivered to the client even after a server restart.
The following example demonstrates how to access the server-generated client ID. This example is excerpted from Web Service Client Best Practices Example in
Programming Advanced Features of JAX-WS Web Services for Oracle WebLogic Server.
Example 6–3 Example of Accessing the Server-generated Client ID
... Create a port without explicitly defining the client ID to view the client ID that is
generated automatically. ClientIdentityFeature dummyClientIdFeature = new ClientIdentityFeaturenull;
BackendService dummyPort = _service.getBackendServicePortdummyClientIdFeature; System.out.printlnGenerated Client Identity is: + dummyClientIdFeature.getClientId;
Best Practice: Explicitly close client instances when processing is complete. If not closed, the port will be closed automatically when it goes out of scope.
Note, this client ID will remain registered and visible until our container Web application is undeployed.
java.io.CloseabledummyPort.close;
Note: A given Client ID can be used from multiple locations in the
client code, but care should be taken to initialize any port or Dispatch instance that uses that client ID in the same way same features,
service, and so on as was used in any other location for that client ID.
For best practice information on the recommended approach to client instance port or Dispatch initialization, see Roadmap for
Developing Web Service Clients in Getting Started With JAX-WS Web Services for Oracle WebLogic Server.
6-18 Getting Started With JAX-WS Web Services for Oracle WebLogic Server
6.6.3 Client Identity Lifecycle