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: Do server side handlers really work?
Date Wed, 30 Jul 2003 15:05:07 GMT
Thank I found the responseFlow mapping last night, now it gets called on both the request and
response.  However, I do Not see the SOAP header on the client side.
In the code below I should see the header set on ther server side in "h".?

  CountServiceLocator locator = new CountServiceLocator();
  Count count = locator.getCount(new 
                        URL("http://localhost:8080/axis/services/Count"));
  org.apache.axis.client.Stub stub = (Stub) count;
  stub.setTimeout(45000); //in milliseconds
  stub.setMaintainSession(true); // Invoke Service
  count.add(1);
  SOAPHeaderElement[] h	= stub.getHeaders();

-----Original Message-----
From: chaddad [mailto:chaddad@cobia.net]
Sent: Wednesday, July 30, 2003 4:56 AM
To: axis-user@ws.apache.org
Subject: Re: So server side handlers really work?


Ross - the documentation states that SimpleSessionHandler needs to be mapped into both the
request and response flows on the server.  Because you haven't mapped the handler into the
response flow, the doServer code for when context.getPastPivot() == false will never be executed
which is critical for the proper operation of the handler.

Additionally, you need to map a corresponding SimpleSession handler in the client.   \test\session\TestSimpleSession
demonstrates and example client and server deployment.

here's the information provided in SimpleSessionHandler.java:

 * <p>Essentially, you install it on both the request and response chains of
 * your service, on both the client and the server side.</p>
 *
 * <p>ON THE SERVER:</p>
 * <ul>
 * <li>The REQUEST is checked for a session ID header.  If present, we
 *     look up the correct SimpleSession.  If not, we create a new session.
 *     In either case, we install the session into the MessageContext, and
 *     put its ID in the SESSION_ID property.
 * <li>The RESPONSE gets a session ID header tacked on, assuming we found a
 *     SESSION_ID property in the MessageContext.
 * </ul>
 * <p>ON THE CLIENT:</p>
 * <ul>
 * <li>The RESPONSE messages are checked for session ID headers.  If present,
 *     we pull the ID out and insert it into an option in the AxisClient.
 *     This works because a given Call object is associated with a single
 *     AxisClient.  However, we might want to find a way to put it into the
 *     Call object itself, which would make a little more sense.  This would
 *     mean being able to get to the Call from the MC, i.e. adding a getCall()
 *     API (which would only work on the client side)....
 * <li>When REQUESTS are generated, we look to see if an ID option is present
 *     in the AxisClient associated with the MessageContext.  If so, we
 *     insert a session ID header with the appropriate ID.
 * </ul>


/Chris


---------- Original Message ----------------------------------
From: "Yakulis, Ross (Ross)" <yakulis@avaya.com>
Reply-To: axis-user@ws.apache.org
Date:  Tue, 29 Jul 2003 15:52:46 -0700

>I created a handler, based on the SimpleSession handler in the Axis code base (basically
a simpler version) and configured it for my service.   The handler only gets called before
the pivot and therefore no session is returned.
>If I ignore the pivot and just set the session soap header it is not returne dto the client.
  How exactly should a 
>server side handler be configured for a service so that it is invoked properly?
>
><?xml version="1.0" encoding="UTF-8"?>
><deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
> <globalConfiguration>
>  <parameter name="adminPassword" value="admin"/>
>  <parameter name="attachments.Directory" value="C:\java\tomcat-4.0.4\webapps\axis\WEB-INF\attachments"/>
>  <parameter name="sendMultiRefs" value="true"/>
>  <parameter name="sendXsiTypes" value="true"/>
>  <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>
>  <parameter name="sendXMLDeclaration" value="true"/>
>  <parameter name="axis.sendMinimizedElements" value="true"/>
>  <requestFlow>
>   <handler type="java:org.apache.axis.handlers.JWSHandler">
>    <parameter name="scope" value="session"/>
>   </handler>
>   <handler type="java:org.apache.axis.handlers.JWSHandler">
>    <parameter name="scope" value="request"/>
>    <parameter name="extension" value=".jwr"/>
>   </handler>
>  </requestFlow>
> </globalConfiguration>
> <handler name="CountSession" type="java:com.xxx.ws.CountSessionHandler"/>
> <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>
> <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>
> <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>
> <service name="AdminService" provider="java:MSG">
>  <parameter name="allowedMethods" value="AdminService"/>
>  <parameter name="enableRemoteAdmin" value="false"/>
>  <parameter name="className" value="org.apache.axis.utils.Admin"/>
>  <namespace>http://xml.apache.org/axis/wsdd/</namespace>
> </service>
> <service name="Version" provider="java:RPC">
>  <parameter name="allowedMethods" value="getVersion"/>
>  <parameter name="className" value="org.apache.axis.Version"/>
> </service>
>  <service name="Count" provider="java:RPC">
>  <operation name="add" qname="ns3:add" xmlns:ns3="urn:com.avaya.Count">
>   <parameter name="in0" type="xsd:int" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
>  </operation>
>  <requestFlow>
>   <handler type="CountSession"/>
>  </requestFlow>
>  <parameter name="allowedMethods" value="add"/>
>  <parameter name="wsdlPortType" value="Count"/>
>  <parameter name="scope" value="Session"/>
>  <parameter name="className" value="com.xxx.ws.CountSoapBindingImpl"/>
>  <parameter name="wsdlServicePort" value="Count"/>
>  <parameter name="wsdlTargetNamespace" value="urn:com.avaya.Count"/>
>  <parameter name="wsdlServiceElement" value="CountService"/>
> </service>
> <transport name="http">
>  <requestFlow>
>   <handler type="URLMapper"/>
>   <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
>  </requestFlow>
> </transport>
> <transport name="local">
>  <responseFlow>
>   <handler type="LocalResponder"/>
>  </responseFlow>
> </transport>
></deployment>
>
>----------------------------
>package com.xxx.ws;
>
>import java.util.Hashtable;
>
>import javax.xml.namespace.QName;
>
>import org.apache.axis.AxisFault;
>import org.apache.axis.Constants;
>import org.apache.axis.Message;
>import org.apache.axis.MessageContext;
>import org.apache.axis.handlers.BasicHandler;
>import org.apache.axis.message.SOAPEnvelope;
>import org.apache.axis.message.SOAPHeaderElement;
>import org.apache.axis.utils.Messages;
>
>public class CountSessionHandler extends BasicHandler {
>	public static final String SESSION_ID = "AvayaSession.id";
>	public static final String SESSION_NS = "com.avaya.ws";
>	public static final String SESSION_LOCALPART = "sessionID";
>	public static final QName sessionHeaderName = new QName(SESSION_NS, SESSION_LOCALPART);
>
>	private Hashtable activeSessions = new Hashtable();
>	private static long sessionId = 12345;
>
>	public void invoke(MessageContext context) throws AxisFault {
>		if (context.isClient() == true) {
>			doClient(context);
>		} else {
>			doServer(context);
>		}
>	}
>
>	public void doClient(MessageContext context) throws AxisFault {
>		System.out.println( "client");
>		return;
>	}
>
>	public void doServer(MessageContext context) throws AxisFault {
>		System.out.println( "Server");
>		if (context.getPastPivot() == true) {
>			System.out.println( "server response");
>			// This is a response.  Add the session header if we have an
>			// ID.
>			Long id = (Long) context.getProperty(SESSION_ID);
>			if (id == null)
>				return;
>			Message msg = context.getResponseMessage();
>			if (msg == null)
>				return;
>			SOAPEnvelope env = msg.getSOAPEnvelope();
>			SOAPHeaderElement header = new SOAPHeaderElement(SESSION_NS, SESSION_LOCALPART, id);
>			env.addHeader(header);
>		} else {
>			System.out.println( "server request ");
>			// Request.  Set up the session if we find the header.
>			Message msg = context.getRequestMessage();
>			if (msg == null)
>				throw new AxisFault(Messages.getMessage("noRequest00"));
>
>			SOAPEnvelope env = msg.getSOAPEnvelope();
>			SOAPHeaderElement header = env.getHeaderByName(SESSION_NS, SESSION_LOCALPART);
>			Long id;
>
>			if (header != null) {
>				// Got one!
>				try {
>					id = (Long) header.getValueAsType(Constants.XSD_LONG);
>				} catch (Exception e) {
>					throw AxisFault.makeFault(e);
>				}
>			} else {
>				id = getNewSession();
>			}
>			context.setProperty(SESSION_ID, id);
>		}
>	}
>
>	private synchronized Long getNewSession() {
>		sessionId++;
>		return (new Long(sessionId));
>	}
>}
>

Mime
View raw message