You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by StanleyAllen <st...@nehushtan.com> on 2007/06/08 00:58:46 UTC

cookies for out-of-band data

I have what seems to me to be a relatively simple problem.  I have a
web service implemented in Axis (1.2) for which I cannot easily change
the interface.  The service needs to be able to receive out-of-band
(OOB) data for each call -- that is, extra data beyond the parameters
normally passed through the method invocation.  The service is
stateful and it should set the cookie; the client needs to maintain
the session and send the cookie for all future invocations of the service.
The OOB data is a string

For some reason, I can't seem to find the right combination of
service/client
code to make this work.

This is what I've got on the client side:

	XYZServiceLocator locator = new XYZServiceLocator();
	XYZ WSport = (XYZ) locator.getXYZService();
	locator.setMaintainSession(true);
	WSPort.call1(a,b);
	MessageContext mc = locator.getCall().getMessageContext();
	String cookie1 = (String) mc.getProperty(HTTPConstants.HEADER_COOKIE);
	String cookie2 = (String) mc.getProperty(HTTPConstants.HEADER_COOKIE2);
	System.out.println("cookie1 : '" + cookie1 + "'");
	System.out.println("cookie2 : '" + cookie2 + "'");

and later in the client:

	// this cookie value may be different than the one received from call1()
	mc.setProperty
		(HTTPConstants.HEADER_COOKIE2, "ExerciseName=" + exerciseNameStr);
	WSPort.call2();

And on the service side, I have this skeleton:

      public class XYZSoapBindingSkeleton implements
		XYZinterface, org.apache.axis.wsdl.Skeleton, ServiceLifecycle
      {
		public static ServletEndpointContext sec;

		..... normal generated skeleton code  ....

		public void init(Object context) throws ServiceException
		{
			try
			{
				if (sec == null)
				{
					System.out.println("RHIND skeleton getting fresh endpoint context");
					sec = (ServletEndpointContext) context;
				}
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}
		}

		public void destroy()
		{
		}
	}

Also on the service sode, I've got this Impl:

	public class XYZSoapBindingImpl implements XYZInterface
	{
		public void call1 (String a, String b)
		{
			... other logic ...

			HttpSession ssn = XYZSoapBindingSkeleton.sec.getHttpSession();

			// This prints a JSESSIONID value.  It is the same as the one
			// printed by the next-to-last line of the client snippet above
			System.out.println("Http Session id = " + ssn.getId());

			// use ssn to set ExerciseName cookie to forExercise.   but HOW!?!?!?!

			// logic below doesn't work -- on the client, the value of cookie2 is
			// always null (the printout from the last line of the client snippet
above)
			javax.xml.rpc.handler.MessageContext localMc =
				XYZSoapBindingSkeleton.sec.getMessageContext();
			localMc.setProperty
				(HTTPConstants.HEADER_COOKIE2, "ExerciseName=" + a);

			... other logic ...
		}

		public void call2 ()
		{
			... other logic ...

			HttpSession ssn = XYZSoapBindingSkeleton.sec.getHttpSession();

			// this prints the same JSESSIONID value as call1 and the client
			System.out.println("Http Session id = " + ssn.getId());

			String Exname;

			//  use ssn to get ExerciseName cookie.    HOW!?!?!?!

			// This prints null
			javax.xml.rpc.handler.MessageContext localMc =
				XYZSoapBindingSkeleton.sec.getMessageContext();
			String exCookie =
				(String) localMc.getProperty (HTTPConstants.HEADER_COOKIE2);
			System.out.println("localMc cookie2 = " + exCookie);

			// This prints null also
			MessageContext mc = MessageContext.getCurrentContext();
			String exCookieB =
				(String) mc.getProperty(HTTPConstants.HEADER_COOKIE2);
			System.out.println("mc cookie2 = " + exCookieB);

			... other logic

		}
	}

Apparently what I'm trying to do on the service side will not set the
cookie so that the client can read it.  And the cookie I'm sending from
the client is not being seen by the service.  What am I missing?

Thanks,

Stanley


-- 
View this message in context: http://www.nabble.com/cookies-for-out-of-band-data-tf3886854.html#a11017805
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org