Package org.apache.muse.core.platform.axis2

Source Code of org.apache.muse.core.platform.axis2.AxisIsolationLayer

/*=============================================================================*
*  Copyright 2006 The Apache Software Foundation
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*=============================================================================*/

package org.apache.muse.core.platform.axis2;

import org.w3c.dom.Element;

import org.apache.axiom.om.OMElement;
import org.apache.axis2.context.OperationContext;

import org.apache.muse.core.Environment;
import org.apache.muse.core.platform.AbstractIsolationLayer;
import org.apache.muse.ws.addressing.MessageHeaders;

/**
*
* AxisIsolationLayer is an Axis2 web service class; that is, it can be
* deployed as an Axis2 service using the services.xml file. This class will
* be the web service for <b>all</b> Muse applications that run on Axis2.
* The deployment descriptor, muse.xml, is used to configure the resource
* types that are created and managed by this service.
*
* @author Dan Jemiolo (danj)
*
*/

public class AxisIsolationLayer extends AbstractIsolationLayer
{
    //
    // the context provided for the very first request - we need
    // to save this in order to do initialization tasks (then it
    // can be nullified). Axis2 services don't have methods similar
    // to JAX-RPC ServiceLifecycle init() and destroy() so we have
    // to grab the value in setOperationContext() and then kick off
    // initialization tasks from there. oy.
    //
    private static OperationContext _initialOpContext = null;
   
    protected Environment createEnvironment()
    {
        return new AxisEnvironment(getInitialContext());
    }
   
    protected OperationContext getInitialContext()
    {
        return _initialOpContext;
    }
   
    /**
     *
     * Parses the information in the incoming SOAP envelope and gives it
     * to the implied resource router for further processing. The results
     * of the operation are added to the outgoing envelope. All faults are
     * serialized and added to the outgoing envelope, so no exceptions
     * should be thrown from this method.
     *
     * @param request
     *        The contents of the incoming SOAP body.
     *       
     * @return The contents of the outgoing SOAP body.
     *
     */
    public final OMElement handleRequest(OMElement request)
    {
        AxisEnvironment env = (AxisEnvironment)getRouter().getEnvironment();
       
        Element soapBody = null;
       
        //
        // handle empty SOAP bodies
        //
        if (request != null)
            soapBody = env.convertToDOM(request);
       
        Element soapResponse = null;
       
        //
        // if the initialization failed, there will be a fault
        // waiting to be serialized/sent back
        //
        if (hasFailedToInitialize())
            soapResponse = getCauseOfFailure().toXML();
       
        //
        // otherwise, proceed as normal with routing
        //
        else
            soapResponse = getRouter().invoke(soapBody);
       
        //
        // all done - don't forget to clean up the context or
        // we'll have a memory leak
        //
        env.removeAddressingContext();
       
        return env.convertToAxiom(soapResponse);
    }

    protected void setInitialContext(OperationContext opContext)
    {
        _initialOpContext = opContext;
    }
   
    /**
     *
     * Because Axis2 doesn't use JAX-RPC ServiceLifecycle methods (or
     * something similar), we use this as our initialization routine.
     * This method is called via reflection for any Axis2 service that
     * implements it. When this method is called, we first check to see
     * if Muse has bee initialized - if not, we kick off initialization.
     * We then proceed with normal request handling.
     *
     * @param opContext
     *
     */
    public void setOperationContext(OperationContext opContext)
    {
        //
        // is this the first time this is being called? initialize!
        //
        if (!hasBeenInitialized())
        {
            setInitialContext(opContext);
           
            initialize();
           
            setInitialContext(null);
        }
       
        //
        // for all requests, we need to save the OpContext so that
        // we can access the SOAP envelope in handleRequest()
        //
        if (!hasFailedToInitialize())
        {
            AxisEnvironment env = (AxisEnvironment)getRouter().getEnvironment();
            MessageHeaders wsa = env.convertContext(opContext);
            env.addAddressingContext(wsa);
        }
    }
}
TOP

Related Classes of org.apache.muse.core.platform.axis2.AxisIsolationLayer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.