I'm using it successfully in Axis 1.1 via request handlers and a custom
version SimpleSessionHandler. There, you will see that Message context
contains a list of ActiveSessions, and each section is in turn nothing
but a hash table with stuff that survives across invocations.

All my web service methods receive as parameter ID that allows the
handler to look up the correct session for any request (next I'd like to
hide them in the SOAP header). The constructor for my Axis service class
refers to the message context and gets the session. Once there, you use
that session object as you would in jsp (session.set/get).

Your wsdd seems correct. 

-----Original Message-----
From: Yakubovich, Alexey [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, June 15, 2004 3:56 PM
To: [EMAIL PROTECTED]
Subject: session in AddressBook sample

Hi, Axis users!

That's the third mail on the same topic... Sorry to repeat again about
the same... No only AddressBook sample seems not working, but the whole
Axis session implementation (class
org.apache.axis.session.SimpleSession) also seems to be a joke.  Please,
answer anybody who managed to use session in Axis web services, if not
with explanation how, but at least with positive statement that it could
work!  After failure with original example I tried with
SimpleSessionHandler and with SimpleSession ... and with <parameter
name="scope" value="Session"/> 

Just on case I attached the deploy.wsdd and
AddressBookSOAPBindingImpl.java files.

//----------------------------------------------------------------------
----------
<deployment xmlns="http://xml.apache.org/axis/wsdd/";
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java";>
  <handler name="session"
type="java:org.apache.axis.handlers.SimpleSessionHandler"/>
  <service name="AddressBook" provider="java:RPC" style="rpc"
use="encoded">
      <requestFlow>
        <handler type="session"/>
      </requestFlow>
      <responseFlow>
        <handler type="session"/>
      </responseFlow>
      <parameter name="wsdlTargetNamespace"
value="urn:AddressFetcher2"/>
      <parameter name="wsdlServiceElement" value="AddressBookService"/>
      <parameter name="wsdlServicePort" value="AddressBook"/>
      <parameter name="className"
value="aly.learn.webSrvs.addr.AddressBookSOAPBindingSkeleton"/>
      <parameter name="wsdlPortType" value="AddressBook"/>
      <parameter name="allowedMethods" value="*"/>
      <parameter name="scope" value="Session"/>
      <typeMapping
        xmlns:ns="urn:AddressFetcher2"
        qname="ns:phone"
        type="java:aly.learn.webSrvs.addr.Phone"
        serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
 
deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
        encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
      />
      <typeMapping
        xmlns:ns="urn:AddressFetcher2"
        qname="ns:address"
        type="java:aly.learn.webSrvs.addr.Address"
        serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
 
deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
        encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
      />
      <typeMapping
        xmlns:ns="urn:AddressFetcher2"
        qname="ns:stateType"
        type="java:aly.learn.webSrvs.addr.StateType"
        serializer="org.apache.axis.encoding.ser.EnumSerializerFactory"
 
deserializer="org.apache.axis.encoding.ser.EnumDeserializerFactory"
        encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
      />
  </service>
</deployment>

//-----------------------------------------------------------------
package aly.learn.webSrvs.addr;

import java.util.HashMap;
import java.util.Map;
import org.apache.axis.MessageContext;
import org.apache.axis.session.Session;

public class AddressBookSOAPBindingImpl implements AddressBook 
{
    private static String addressesName = "ADDR_MAP_NAME";
//    private Map addrMap = new HashMap();

    public void addEntry(String name, Address address) throws
java.rmi.RemoteException 
    {
        MessageContext mc = MessageContext.getCurrentContext();
        Session session = mc.getSession();
        Object value = session.get(addressesName);
        
        Map addrMap = (Map) session.get(addressesName);
        if(addrMap == null)
        {
            System.out.println("addEntry(): No addr map in session
yet!");
            addrMap = new HashMap(); 
            session.set(addressesName, addrMap);
        }
        
        addrMap.put(name, address);
    }
    
    public Address getAddressFromName(java.lang.String name) throws
java.rmi.RemoteException 
    {
        Address addr = null;
        
        MessageContext mc = MessageContext.getCurrentContext();
        Session session = mc.getSession();
        Object value = session.get(addressesName);
        
        if(value == null)
                        System.out.println("getAddressFromName(): No
addr map in session yet!");
        else
        {
            Map addrMap = (Map)value;
            addr = (Address)addrMap.get(name);
        }
                        
        return addr;
    }
}

Reply via email to