axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yakulis, Ross (Ross)" <yaku...@avaya.com>
Subject RE: Sessions across several services with Client
Date Fri, 23 Apr 2004 22:04:01 GMT
I used handlers bases on the SimpleSesssionHandler.
Mine extended BasicHandler.


public class ClientSessionHandler extends BasicHandler {
	public static final String SESSION_ID = "my.session.id";
	public static final String SESSION_NS = "my.simple.ns";
	private static String sessionId = null;

	/**
	 * Process a MessageContext.
	 */
	public void invoke(MessageContext context) throws AxisFault {
		if (context.isClient() == true) {
			doClient(context);
		} else {}
	}

	/**
	 * Client side of processing.
	 */
	public void doClient(MessageContext context) throws AxisFault {
		if (context.getPastPivot()) {
			/* 
			 * response, check for session id header.
			 */
			Message msg = context.getResponseMessage();
			if (msg == null) {
				return;
			}
			SOAPEnvelope env = msg.getSOAPEnvelope();
			SOAPHeaderElement header =
				env.getHeaderByName(
					SESSION_NS,
					SESSION_ID);
			if (header == null) {
				return;
			}

			/* Got one! */
			try {
				ClientSessionHandler.sessionId = (String) header.getValueAsType(Constants.XSD_STRING);
				/* Note that we processed this header! */
				header.setProcessed(true);
			} catch (Exception e) {
				throw new xxx.ServiceException(e.toString());
			}
		} else {
			/* 
			 * request, add in session id header.
			 */
			if (ClientSessionHandler.sessionId == null) {
				return;
			}
			/* We have a session ID, so insert the header */
			Message msg = context.getRequestMessage();
			if (msg == null) {
				throw new xxx.ServiceException("No Request Message");
			}
			SOAPEnvelope env = msg.getSOAPEnvelope();
			SOAPHeaderElement header =
				new SOAPHeaderElement(
					SESSION_NS,
					cSESSION_ID,
					ClientSessionHandler.sessionId);
			env.addHeader(header);
		}
	}
}


Then you need to set the appropriate client configutation file that
includes your handler.   

      System.setProperty("axis.ClientConfigFile", ".../client-config.wsdd");

Or specify the client config programatically by creating your own engine configuration
factory.

	static {
		try {
			AxisProperties.setProperty(
				EngineConfigurationFactory.SYSTEM_PROPERTY_NAME,
				"xxx.MyEngineConfigurationFactory");
		} catch (Exception e) {
		}
	}


-----Original Message-----
From: Ryan Stutsman [mailto:rstutsman@ogse.com]
Sent: Friday, April 23, 2004 2:58 PM
To: axis-user@ws.apache.org
Subject: RE: Sessions across several services with Client


What you describe is exactly what I have done; however, what I'm asking
is...

How do I then, take that sessionID in response from the login method of
one service and put it into the request header of say getPerson from the
person service.

I can't for the life of me figure out how to 1) get the sessionID from
the header on the Axis client and 2) get the sessionID back into the
Axis client's request header.

I did this in PHP with a nuSOAP client easily because it has a method
for getting and setting header tags.

On Fri, 2004-04-23 at 16:52, Yakulis, Ross (Ross) wrote:
> I am not sure I fully follow your question:
> "but how do I do this with the Axis client".
> Specifically how are you differentiating "axis client"
> from other clients?
> 
> I have done something similar use SOAP headers to pass a session from
> on axis web service to another.  The first web service logs
> on and creates the session token that is returned in the
> SOAPHeader, then that token is propagated to other services.  I did 
> not use the java sessions and did my own session control on the server side.
> 
> Ross
> 
> -----Original Message-----
> From: Ryan Stutsman [mailto:rstutsman@ogse.com]
> Sent: Friday, April 23, 2004 2:48 PM
> To: axis-user@ws.apache.org
> Subject: Sessions across several services with Client
> 
> 
> Hello,
> 
> I have an Axis app server which has several web services.  They all
> share a common session (using the SimpleSessionHandler with the
> sessionID in the SOAP headers right now).  e.g. You start a session on
> the user service it'll follow you to the person service, etc, etc.
> 
> Now, I've gotten a few clients to work with this fine, but how do I do
> this with the Axis client?
> 
> I can't seem to figure out how to SET the sessionID in the request
> header.  I want to override the automatic sessionID with the ID that I
> have from the other service.
> 
> Since there's no MessageContext and locator.getEngine() returns null I'm
> not sure how to attack it.
> 
> Thanks.


Mime
View raw message