Package org.apache.ws.resource.handler.axis

Source Code of org.apache.ws.resource.handler.axis.AxisResourceContext

/*=============================================================================*
*  Copyright 2004 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.ws.resource.handler.axis;

import org.apache.axis.handlers.soap.SOAPService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.resource.ResourceContextException;
import org.apache.ws.resource.handler.ResourceHandler;
import org.apache.ws.resource.i18n.Keys;
import org.apache.ws.resource.i18n.MessagesImpl;
import org.apache.ws.resource.impl.AbstractResourceContext;
import org.apache.ws.util.i18n.Messages;

import javax.xml.rpc.handler.MessageContext;
import javax.xml.rpc.handler.soap.SOAPMessageContext;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Hashtable;
import java.util.Iterator;

/**
* LOG-DONE
* Axis version of a ResourceContext.
*
* @author Sal Campana
*/
public class AxisResourceContext
   extends AbstractResourceContext
{
   /**
    * DOCUMENT_ME
    */
   private static final Log LOG = LogFactory.getLog( AxisResourceContext.class.getName(  ) );
   public static final Messages MSG = MessagesImpl.getInstance();
   /**
    * DOCUMENT_ME
    */
   private final String DEFAULT_RESOURCE_KEY_NAME = "ResourceId";

   /**
    * Creates a new {@link AxisResourceContext} object.
    *
    * @param msgContext SOAPMessageContext
    */
   public AxisResourceContext( SOAPMessageContext msgContext )
   {
      super( msgContext );
      mergeServiceOptions( msgContext );
      setResourceIdKeyInformation(  );
   }

   /**
    * Returns the Service name from the Axis MessageContext {@link org.apache.axis.MessageContext#getTargetService()}
    *
    * @param msgContext Jax-RPC MessageContext
    *
    * @return The service name
    */
   protected String getServiceName( MessageContext msgContext )
   {
      if ( msgContext == null )
      {
         throw new IllegalArgumentException( MSG.getMessage(Keys.MESSAGECONTEXT_NULL) );
      }
      org.apache.axis.MessageContext axisMsgContext = (org.apache.axis.MessageContext) msgContext;
      return axisMsgContext.getTargetService(  );
   }

   /**
    * Returns the Service url from the Axis MessageContext {@link org.apache.axis.MessageContext#getProperty(String)}
    * passing it {@link org.apache.axis.MessageContext#TRANS_URL}
    *
    * @param msgContext Jax-RPC MessageContext
    *
    * @return The service URL
    */
   protected URL getServiceURL( MessageContext msgContext )
   {
      if ( msgContext == null )
      {
         throw new IllegalArgumentException( "Null parameter: msgContext" );
      }
      org.apache.axis.MessageContext axisMsgContext = (org.apache.axis.MessageContext) msgContext;
      try
      {
         return new URL( (String) axisMsgContext.getProperty( org.apache.axis.MessageContext.TRANS_URL ) );
      }
      catch ( MalformedURLException murle )
      {
         throw new RuntimeException( "Value of Axis " + org.apache.axis.MessageContext.TRANS_URL + " MessageContext property is not a valid URL.", murle );
      }
   }

   private void setResourceIdKeyInformation(  )
   {
      String keyClassName   = null;
      Class  keyClass       = null;
      String keyQNameString = null;
      try
      {
         keyClassName      = getResourceHome(  ).getResourceKeyClassName(  );
         keyClass          = Class.forName( keyClassName );
         keyQNameString    = (String) getResourceHome(  ).getResourceKeyName(  );
      }
      catch ( ResourceContextException rce )
      {
         LOG.debug(MSG.getMessage(Keys.EXCEPTION_GETTING_HOME,rce));
         rce.printStackTrace( );
         //todo throw exception.....???
      }
      catch ( ClassNotFoundException cnfe )
      {
         LOG.debug(MSG.getMessage(Keys.EXCEPTION_CREATING_CLASS, keyClassName ,cnfe));
         cnfe.printStackTrace( );
         //todo throw exception...??
      }

      if ( keyQNameString == null )
      { //last ditch effort.....
         keyQNameString =
            "{" + getProperty( ResourceHandler.SERVICE_OPT_WSDL_TARGET_NAMESPACE ) + "}"
            + DEFAULT_RESOURCE_KEY_NAME;
      }

      setResourceKeyQname( keyQNameString );
      setResourceKeyClass( keyClass );
   }

   private void mergeServiceOptions( MessageContext msgContext )
   {
      org.apache.axis.MessageContext axisMsgContext = (org.apache.axis.MessageContext) msgContext;
      SOAPService                    service  = axisMsgContext.getService(  );
      Hashtable                      options  = service.getOptions(  );
      Iterator                       iterator = options.keySet(  ).iterator(  );

      while ( iterator.hasNext(  ) )
      {
         String key = (String) iterator.next(  );
         setProperty( key,
                      service.getOption( key ) );
      }
   }
}
TOP

Related Classes of org.apache.ws.resource.handler.axis.AxisResourceContext

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.