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 java.util.logging.Level;

import org.w3c.dom.Element;

import org.apache.axiom.om.OMElement;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.context.MessageContext;

import org.apache.muse.core.Environment;
import org.apache.muse.core.platform.AbstractIsolationLayer;
import org.apache.muse.core.routing.ResourceRouter;
import org.apache.muse.util.LoggingUtils;
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
{
    protected Environment createEnvironment()
    {
        return new AxisEnvironment();
    }
   
    /**
     *
     * 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)
    {
        //
        // is this the first time this is being called? initialize!
        //
        if (!hasBeenInitialized())
            initialize();
       
        Element soapResponse = null;
       
        //
        // for all requests, we need to save the addressing headers so that
        // we can access the SOAP envelope in handleRequest()
        //
        if (hasFailedToInitialize())
            soapResponse = getCauseOfFailure().toXML();
       
        else
            soapResponse = invoke(request);

        //
        // be sure to handle empty SOAP body in the response
        //
        if (soapResponse == null)
            return null;

        AxisEnvironment env = (AxisEnvironment)getRouter().getEnvironment();
        return env.convertToAxiom(soapResponse);
    }
   
    public Element invoke(OMElement request)
    {
        ResourceRouter router = getRouter();
        AxisEnvironment env = (AxisEnvironment)router.getEnvironment();
       
        //
        // log incoming SOAP envelope
        //
        // NOTE: This is kind of hack-ish, but we check to see if the
        //       current log level is 'FINE' before we try and log the
        //       message. We don't actually have to do this - the JDK
        //       logging API fine() will do this for us - but because
        //       we have to translate from Axiom to DOM once already,
        //       I don't want to do it twice unless the tracing is being
        //       used. If SOAP-level tracing is on, it's likely that this
        //       is not being used in a production system, so we can afford
        //       the performance hit of an extra conversion.
        //
        if (router.getLog().getLevel() == Level.FINE)
        {
            SOAPEnvelope soap = MessageContext.getCurrentMessageContext().getEnvelope();
            Element soapAsDOM = env.convertToDOM(soap);
            LoggingUtils.logMessage(router.getLog(), soapAsDOM, true);
        }
       
        MessageHeaders wsa = env.convertContext();       
        env.addAddressingContext(wsa);
       
        Element soapBody = null;
       
        //
        // handle empty SOAP bodies
        //
        if (request != null)
            soapBody = env.convertToDOM(request);
   
        Element soapResponse = getRouter().invoke(soapBody);
       
        //
        // all done - don't forget to clean up the context or
        // we'll have a memory leak
        //
        env.removeAddressingContext();
       
        return soapResponse;       
    }
}
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.