Network Deployment (Distributed operating systems), v8.0 > End-to-end paths > Web services - Transports > Use HTTP to transport web services requests for JAX-WS applications
Use HTTP session management support for JAX-WS applications
HTTP session management is performed in the HTTP transport layer by using either cookies or URL rewriting. By providing multiple options for tracking a series of requests, HTTP session management enables Java API for XML-Based Web Services (JAX-WS) applications to appear dynamic to application users.
Develop a JAX-WS dynamic proxy or Dispatch client.
To learn more about developing JAX-WS clients, read about developing a JAX-WS client from a WSDL file or developing a dynamic client using JAX-WS APIs.
We can use HTTP session management to maintain user state information on the server, while passing minimal information back to the user to track the session. We can implement HTTP session management on the application server using either session cookies or URL rewriting.
The interaction between the browser, application server, and application is transparent to the user and the application program. The application and the user are typically not aware of the session identifier provided by the server.
Session cookies
The HTTP maintain session feature uses a single cookie, JSESSIONID, and this cookie contains the session identifier. This cookie is used to associate the request with information stored on the server for that session. On subsequent requests from the JAX-WS application, the session ID is transmitted as part of the request header, which enables the application to associate each request for a given session ID with prior requests from that user. The JAX-WS client applications retrieve the session ID from the HTTP response headers and then use those IDs in subsequent requests by setting the session ID in the HTTP request headers.
URL rewriting
URL rewriting works like a redirected URL as it stores the session identifier in the URL. The session identifier is encoded as a parameter on any link or form that is submitted from a web page. This encoded URL is used for subsequent requests to the same server.
Procedure
- Configure the server to enable session tracking. Specify either session cookies or URL rewriting for your session tracking mechanism using the administration console. Read about configuring session tracking to learn how to track sessions with cookies or with URL rewriting.
- Enable HTTP session management for the JAX-WS client. We can manually set the maintainSession property to true in the policy set binding.
- Enable session management on the client using a HTTP transport policy set file. We can configure the HTTP transport policy using the administration console. On the HTTP transport setting page, select the Session enable checkbox to enable an HTTP session. Read about configuring the HTTP transport property to learn how to set this property. We can also manually set the maintainSession property to yes to enable HTTP session management.
- Enable session management on the client by setting the JAX-WS property, javax.xml.ws.session.maintain, to true.
Results
You have enabled HTTP session management for your JAX-WS application.
Example
The following example is an excerpt from a HTTP Transport policy set that demonstrates how to configure the maintainSession property:
<!-- This is the PolicyType for HTTP transport --> <wsp:ExactlyOne> <wsp:All> <ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :readTimeout>300 </ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :readTimeout> <ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :writeTimeout>300 </ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :writeTimeout> <ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :connectTimeout>180 </ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :connectTimeout> <ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :persistConnection>yes </ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :persistConnection> <ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :messageResendOnce>no </ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :messageResendOnce> <ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :chunkTransferEnc>no </ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :chunkTransferEnc> <ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :acceptRedirectedURL>no </ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :acceptRedirectedURL> <ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :sendExpectHeader>no </ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :sendExpectHeader> <ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :maintainSession>yes </ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :maintainSession> <ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :compressRequest> <ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :compressType name="none"> </ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :compressType> </ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :compressRequest> <ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :compressResponse> <ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :compressType name="none"> </ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :compressType> </ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :compressResponse> <ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :protocolVersion>HTTP/1.1 </ws//publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/ :protocolVersion> </wsp:All> </wsp:ExactlyOne>The following code example is demonstrates how to programmatically enable session management on the client by setting the javax.xml.ws.session.maintain property on the correct JAX-WS object.
Map <String, Object> rc = ((BindingProvider) port).getRequestContext(); ... ... rc.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE); ... ...
Use HTTP to transport web services
Develop a JAX-WS client from a WSDL file
Develop a dynamic client using JAX-WS APIs
Configure session tracking