FileDocCategorySizeDatePackage
SOAPService.javaAPI DocApache Axis 1.415416Sat Apr 22 18:57:28 BST 2006org.apache.axis.handlers.soap

SOAPService

public class SOAPService extends org.apache.axis.SimpleTargetedChain
A SOAPService is a Handler which encapsulates a SOAP invocation. It has an request chain, an response chain, and a pivot-point, and handles the SOAP semantics when invoke()d.
author
Glen Daniels (gdaniels@apache.org)
author
Doug Davis (dug@us.ibm.com)

Fields Summary
private static Log
log
private Vector
validTransports
Valid transports for this service (server side only!) !!! For now, if this is null, we assume all transports are valid.
private boolean
highFidelityRecording
Does this service require a high-fidelity SAX recording of messages? (default is true)
private int
sendType
How does this service wish data which would normally be sent as an attachment to be sent? Default for requests is org.apache.axis.attachments.Attachments.SEND_TYPE_DEFAULT, and the default for responses is to match the request.
private org.apache.axis.description.ServiceDesc
serviceDescription
Our ServiceDescription. Holds pretty much all the interesting metadata about this service.
private org.apache.axis.AxisEngine
engine
public Map
serviceObjects
A list of our active service objects (these can have lifetimes and be reaped)
public int
nextObjectID
private static Hashtable
sessions
List of sessions (for all services), key=serviceName, value=Service
private boolean
isRunning
ArrayList
actors
Actor list - these are just the service-specific ones
Constructors Summary
public SOAPService(org.apache.axis.Handler serviceHandler)
Convenience constructor for wrapping SOAP semantics around "service handlers" which actually do work.

        this();
        init(null, new MustUnderstandChecker(this), serviceHandler, null, null);
    
public SOAPService()
Standard, no-arg constructor.

        setOptionsLockable(true);
        initHashtable();

        // For now, always assume we're the ultimate destination.
        actors.add("");
    
public SOAPService(org.apache.axis.Handler reqHandler, org.apache.axis.Handler pivHandler, org.apache.axis.Handler respHandler)
Constructor with real or null request, pivot, and response handlers. A special request handler is specified to inject SOAP semantics.

        this();
        init(reqHandler, new MustUnderstandChecker(this), pivHandler, null, respHandler);
    
Methods Summary
public voidaddSession(org.apache.axis.session.Session session)
Add this passed in Session to this Service's list of sessions

    
                     
        
      WeakHashMap map = (WeakHashMap) sessions.get( this.getName() );
      if ( map == null )  {
        map = new WeakHashMap();
        sessions.put( this.getName(), map);
      }
      if ( !map.containsKey(session) ) map.put(session, null);
    
public booleanavailableFromTransport(java.lang.String transportName)

        if (validTransports != null) {
            for (int i = 0; i < validTransports.size(); i++) {
                if (validTransports.elementAt(i).equals(transportName))
                    return true;
            }
            return false;
        }

        return true;
    
public voidclearSessions()
Remove all of this Service's serviceObjects from it known sessions

      WeakHashMap map = (WeakHashMap) sessions.get( this.getName() );
      if ( map == null ) return ;
      Iterator iter = map.keySet().iterator();
      while ( iter.hasNext() ) {
        Session session = (Session) iter.next();
        session.remove( this.getName() );
      }
    
public voiddisableTransport(java.lang.String transportName)
Disable access to this service from a particular transport

        if (validTransports != null) {
            validTransports.removeElement(transportName);
        }
    
public voidenableTransport(java.lang.String transportName)
Make this service available on a particular transport

        if (log.isDebugEnabled()) {
            log.debug(Messages.getMessage(
                "enableTransport00", "" + this, transportName));
        }

        if (validTransports == null)
            validTransports = new Vector();
        validTransports.addElement(transportName);
    
public voidgenerateWSDL(org.apache.axis.MessageContext msgContext)
Generate WSDL. If we have a specific file configured in the ServiceDesc, just return that. Otherwise run through all the Handlers (including the provider) and call generateWSDL() on them via our parent's implementation.

        if (serviceDescription == null ||
                serviceDescription.getWSDLFile() == null) {
            super.generateWSDL(msgContext);
            return;
        }
        InputStream instream = null;

        // Got a WSDL file in the service description, so try and read it
        try {
            String filename= serviceDescription.getWSDLFile();
            File file=new File(filename);
            if(file.exists()) {
                //if this resolves to a file, load it
                instream = new FileInputStream(filename);
            } else if(msgContext.getStrProp(Constants.MC_HOME_DIR)!=null){
                String path = msgContext.getStrProp(Constants.MC_HOME_DIR) +'/" + filename;
                file = new File(path);
                if(file.exists()) {
                    //if this resolves to a file, load it
                    instream = new FileInputStream(path);
                }
            }
            
            if(instream == null) {
                //else load a named resource in our classloader. 
                instream = ClassUtils.getResourceAsStream(this.getClass(),filename);
                if (instream == null) {
                    String errorText=Messages.getMessage("wsdlFileMissing",filename);
                    throw new AxisFault(errorText);
                }
            }
            Document doc = XMLUtils.newDocument(instream);
            msgContext.setProperty("WSDL", doc);
        } catch (Exception e) {
            throw AxisFault.makeFault(e);
        } finally {
            if(instream!=null) {
                try {
                    instream.close();
                } catch (IOException e) { }
            }
        }
    
public java.util.ArrayListgetActors()
Get the merged actor list for this service, including engine-wide actor URIs.

return

        ArrayList acts = (ArrayList)actors.clone();  // ??? cache this?

        if (engine != null) {
            acts.addAll(engine.getActorURIs());
        }

        return acts;
    
public org.apache.axis.AxisEnginegetEngine()

        return engine;
    
public synchronized org.apache.axis.description.ServiceDescgetInitializedServiceDesc(org.apache.axis.MessageContext msgContext)
Returns a service description with the implementation class filled in. Syncronized to prevent simutaneous modification of serviceDescription.


        if (!serviceDescription.isInitialized()) {

            // Let the provider do the work of filling in the service
            // descriptor.  This is so that it can decide itself how best
            // to map the Operations.  In the future, we may want to support
            // providers which don't strictly map to Java class backends
            // (BSFProvider, etc.), and as such we hand off here.
            if (pivotHandler instanceof BasicProvider) {
                ((BasicProvider)pivotHandler).initServiceDesc(this, msgContext);
            }

        }

        return serviceDescription;
    
public java.util.ListgetRoles()

        return getActors();
    
public intgetSendType()

        return sendType;
    
public java.util.ArrayListgetServiceActors()
Get the service-specific actor list

return


               
       
        return actors;
    
public org.apache.axis.description.ServiceDescgetServiceDescription()

        return serviceDescription;
    
public org.apache.axis.constants.StylegetStyle()

        return serviceDescription.getStyle();
    
public org.apache.axis.encoding.TypeMappingRegistrygetTypeMappingRegistry()

        return serviceDescription.getTypeMappingRegistry();
    
public org.apache.axis.constants.UsegetUse()

        return serviceDescription.getUse();
    
public voidinvoke(org.apache.axis.MessageContext msgContext)

        HandlerInfoChainFactory handlerFactory = (HandlerInfoChainFactory) this.getOption(Constants.ATTR_HANDLERINFOCHAIN);
        HandlerChainImpl handlerImpl = null;
        if (handlerFactory != null) handlerImpl = (HandlerChainImpl) handlerFactory.createHandlerChain();
        boolean result = true;

        try {
            if (handlerImpl != null) {
                try {
                    result = handlerImpl.handleRequest(msgContext);
                }
                catch (SOAPFaultException e) {
                    msgContext.setPastPivot(true);
                    handlerImpl.handleFault(msgContext);
                    return;
                }
            }

            if (result) {
                try {
                    super.invoke(msgContext);
                } catch (AxisFault e) {
                    msgContext.setPastPivot(true);
                    if (handlerImpl != null) {
                        handlerImpl.handleFault(msgContext);
                    }
                    throw e;
                }
            } else {
                msgContext.setPastPivot(true);
            }

            if ( handlerImpl != null) {
                handlerImpl.handleResponse(msgContext);
            }
        } catch (SOAPFaultException e) {
            msgContext.setPastPivot(true);
            throw AxisFault.makeFault(e);

        } catch (RuntimeException e) {
            SOAPFault fault = new SOAPFault(new AxisFault("Server", "Server Error", null, null));
            SOAPEnvelope env = new SOAPEnvelope();
            env.addBodyElement(fault);
            Message message = new Message(env);
            message.setMessageType(Message.RESPONSE);
            msgContext.setResponseMessage(message);
            throw AxisFault.makeFault(e);
        }
        finally {
            if (handlerImpl != null) {
                handlerImpl.destroy();
            }
        }
    
public booleanisRunning()
Is this service suspended?

return

        return isRunning;
    
public booleanneedsHighFidelityRecording()

        return highFidelityRecording;
    
public voidsetEngine(org.apache.axis.AxisEngine engine)
Tell this service which engine it's deployed to.

        if (engine == null)
            throw new IllegalArgumentException(
                    Messages.getMessage("nullEngine"));

        this.engine = engine;
        ((LockableHashtable)options).setParent(engine.getOptions());
        TypeMappingRegistry tmr = engine.getTypeMappingRegistry();
        getTypeMappingRegistry().delegate(tmr);
    
public voidsetHighFidelityRecording(boolean highFidelityRecording)

        this.highFidelityRecording = highFidelityRecording;
    
public voidsetPropertyParent(java.util.Hashtable parent)

        if (options == null) {
            options = new LockableHashtable();
        }
        ((LockableHashtable)options).setParent(parent);
    
public voidsetRoles(java.util.List roles)
Set the service-specific role list

param
roles a List of Strings, each containing a role URI

        actors = new ArrayList(roles);
    
public voidsetSendType(int sendType)

        this.sendType = sendType;
    
public voidsetServiceDescription(org.apache.axis.description.ServiceDesc serviceDescription)

        if (serviceDescription == null) {
            // FIXME: Throw NPE?
            return;
        }
        this.serviceDescription = serviceDescription;
        //serviceDescription.setTypeMapping((TypeMapping)this.getTypeMappingRegistry().getDefaultTypeMapping());
    
public voidsetStyle(org.apache.axis.constants.Style style)

        serviceDescription.setStyle(style);
    
public voidsetUse(org.apache.axis.constants.Use style)

        serviceDescription.setUse(style);
    
public voidstart()
Placeholder for "resume this service" method

        isRunning = true;
    
public voidstop()
Placeholder for "suspend this service" method

        isRunning = false;