User: cgjung  
  Date: 02/03/12 03:04:46

  Modified:    jboss.net/src/main/org/jboss/net/axis/server
                        AxisService.java AxisServiceServlet.java
                        EJBProvider.java
  Removed:     jboss.net/src/main/org/jboss/net/axis/server
                        ClassLoaderAwareAxisServer.java
                        ClassLoaderAwareMessageContext.java
  Log:
  Axis Beta RC1 is here. Needs no more to be patched for integrating with the
  jboss classloading architecture. Lots of interna have changed, though.
  
  Adapted the deployment descriptors to support WSDD now.
  
  Revision  Changes    Path
  1.14      +395 -388  
contrib/jboss.net/src/main/org/jboss/net/axis/server/AxisService.java
  
  Index: AxisService.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jboss.net/src/main/org/jboss/net/axis/server/AxisService.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- AxisService.java  1 Mar 2002 22:12:57 -0000       1.13
  +++ AxisService.java  12 Mar 2002 11:04:46 -0000      1.14
  @@ -5,11 +5,13 @@
    * See terms of license at gnu.org.
    */
   
  -// $Id: AxisService.java,v 1.13 2002/03/01 22:12:57 cgjung Exp $
  +// $Id: AxisService.java,v 1.14 2002/03/12 11:04:46 cgjung Exp $
   
   package org.jboss.net.axis.server;
   
   import org.jboss.net.axis.XMLResourceProvider;
  +import org.jboss.net.axis.Deployment;
  +
   import org.jboss.net.DefaultResourceBundle;
   
   import org.jboss.deployment.DeploymentException;
  @@ -23,10 +25,10 @@
   
   import org.apache.axis.MessageContext;
   import org.apache.axis.utils.XMLUtils;
  -import org.apache.axis.utils.Admin;
   import org.apache.axis.AxisFault;
   import org.apache.axis.server.AxisServer;
  -import org.apache.axis.configuration.FileProvider;
  +import org.apache.axis.deployment.wsdd.WSDDProvider;
  +import org.apache.axis.deployment.wsdd.WSDDUndeployment;
   
   import org.jboss.naming.Util;
   import org.jboss.metadata.MetaData;
  @@ -35,7 +37,9 @@
   
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
  +import org.w3c.dom.Attr;
   import org.w3c.dom.Node;
  +import org.w3c.dom.NamedNodeMap;
   import org.w3c.dom.NodeList;
   
   import javax.management.MBeanRegistration;
  @@ -66,75 +70,118 @@
   import java.util.Collection;
   
   /**
  - *   A deployer service that installs and manages Axis within JMX.
  - *   @created 27. September 2001
  - *   @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
  - *   @version $Revision: 1.13 $
  - *   Change notes:
  - *   <ul>
  - *     <li> 01.02.02: CGJ, Adapted to jboss3.0.0DR1 deployment changes. Arrgh! <li>
  - *     <li> 14.12.01: CGJ, Added security domain support. <li>
  - *     <li> 28.11.01: CGJ, Adapted to jboss3.0 single-phase mbean startup. <li>
  - *     <li> 28.11.01: CGJ, Fixed zip-cache problem (sort of). <li>
  - *   </ul>
  + * A deployer service that installs Axis and manages Web-Services 
  + * within JMX.
  + * <br>
  + * <h3>Change History</h3>
  + * <ul>
  + *  <li> jung, 09.03.02: axis alpha 3 and wsdd deployment is here.</li>
  + *  <li> jung, 01.02.02: Adapted to jboss3.0.0DR1 deployment changes. Arrgh! <li>
  + *  <li> jung, 14.12.01: Added security domain support. <li>
  + *  <li> jung, 28.11.01: Adapted to jboss3.0 single-phase mbean startup. <li>
  + *  <li> jung, 28.11.01: Fixed zip-cache problem (sort of). <li>
  + * </ul>
  + * @created 27. September 2001
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
  + * @version $Revision: 1.14 $
    */
   
   public class AxisService
  -extends ServiceMBeanSupport
  -implements AxisServiceMBean, MBeanRegistration, Constants
  -{
  -
  -  /**
  -   * A map of current deployments.
  -   */
  -   Map deployments = new java.util.HashMap();
  +   extends ServiceMBeanSupport
  +   implements AxisServiceMBean, MBeanRegistration {
  +
  +   // 
  +   // Attributes
  +   //
  +
  +   /**
  +    * A map of current deployment names to the
  +    * wsdd docs that created them.
  +    */
  +   protected Map deployments = new java.util.HashMap();
   
      /** the name registered */
  -   ObjectName _name=null;
  +   protected ObjectName _name = null;
   
      /** this is where the axis "web-application" has been installed */
  -   DeploymentInfo myDeploymentInfo=null;
  -
  -   /** Axis administration helper, keeps no state, i think */
  -   final Admin admin=new Admin();
  +   protected DeploymentInfo myDeploymentInfo = null;
   
  -   /** the axis engines */
  -   final static Map axisServerMap=new java.util.HashMap();
  +   /** the engine belonging to this service */
  +   protected AxisServer axisServer;
   
      /** the web deployer that hosts our servlet */
  -   DeployerMBean webDeployer;
  +   protected DeployerMBean webDeployer;
  +
  +   //
  +   // Constructors
  +   //
   
      /** default */
  -   public AxisService()
  -   {
  +   public AxisService() {
         // we fake internationalisation if it is not globally catered
  -      if(log.getCategory().getResourceBundle()==null)
  +      if (log.getCategory().getResourceBundle() == null)
            log.getCategory().setResourceBundle(new DefaultResourceBundle());
      }
   
  +   //
  +   // Some helper methods
  +   //
  +
  +   /** work around broken JarURLConnection caching... thx Jules for the hack ;-) */
  +   private URL fixURL(URL url) throws MalformedURLException {
  +      String urlString = url.toString();
  +      //determine the last slash
  +      int index = urlString.lastIndexOf(":") + 1;
  +      // no slash, we take the last protocol or drive id
  +      if (index == 0) {
  +         // we cannot fix this
  +         return url;
  +      } else {
  +         return new URL(
  +            urlString.substring(0, index) + "/." + urlString.substring(index));
  +      }
  +   }
  +
  +   /** returns the jboss deploy dir */
  +   protected String getDeployDir() throws Exception {
  +      File systemTempDir =
  +         (File) server.getAttribute(ServerConfigImplMBean.OBJECT_NAME, "TempDir");
  +
  +      return new File(new File(systemTempDir, "deploy"), Constants.AXIS_DEPLOY_DIR)
  +         .getCanonicalPath();
  +   }
  +
  +   /** a tiny copy operation */
  +   protected void copy(InputStream in, OutputStream out) throws IOException {
  +
  +      byte[] buffer = new byte[1024];
  +      int read;
  +      while ((read = in.read(buffer)) > 0) {
  +         out.write(buffer, 0, read);
  +      }
  +   }
  +
      //----------------------------------------------------------------------------
      // 'name' interface
      //----------------------------------------------------------------------------
   
  +   /** registers at the MBean server with a default or a preconfigured name */
      public ObjectName getObjectName(MBeanServer server, ObjectName name)
  -   throws MalformedObjectNameException
  -   {
  +      throws MalformedObjectNameException {
         // accept name proposal from JMX in order
         // to allow several instances
  -      if(name==null)
  -      {
  -         _name=new ObjectName(DOMAIN+":"+TYPE+"="+getName());
  -      } else
  -      {
  -         _name=name;
  +      if (name == null) {
  +         _name =
  +            new ObjectName(Constants.DOMAIN + ":" + Constants.TYPE + "=" + 
getName());
  +      } else {
  +         _name = name;
         }
         return _name;
      }
   
      /** return just the proper name part */
  -   public String getName()
  -   {
  -      return NAME;
  +   public String getName() {
  +      return Constants.NAME;
      }
   
      //----------------------------------------------------------------------------
  @@ -142,29 +189,30 @@
      //----------------------------------------------------------------------------
   
      /** starts the associated AxisEngine */
  -   protected void ensureService() throws Exception
  -   {
  +   protected void ensureService() throws Exception {
   
  -      synchronized(AxisService.class)
  -      {
  +      synchronized (AxisService.class) {
            // each engine must have a different context
  -         if(axisServerMap.get(rootContext)!=null)
  -            throw new Exception(AXIS_SERVER_CONTEXT_OCCUPIED);
  +         if (axisServerMap.get(rootContext) != null)
  +            throw new Exception(Constants.AXIS_SERVER_CONTEXT_OCCUPIED);
   
            // find the global config file in classpath
  -         URL resource=getClass().
  -         getClassLoader().getResource(AXIS_CONFIGURATION_FILE);
  +         URL resource =
  +            
getClass().getClassLoader().getResource(Constants.AXIS_CONFIGURATION_FILE);
   
  -         if(resource==null)
  -         {
  -            
log.getCategory().l7dlog(Priority.WARN,COULD_NOT_FIND_AXIS_CONFIGURATION_0,
  -            new Object[]
  -            {AXIS_CONFIGURATION_FILE},null);
  -            throw new Exception(COULD_NOT_FIND_AXIS_CONFIGURATION_0);
  +         if (resource == null) {
  +            log.getCategory().l7dlog(
  +               Priority.WARN,
  +               Constants.COULD_NOT_FIND_AXIS_CONFIGURATION_0,
  +               new Object[] { Constants.AXIS_CONFIGURATION_FILE },
  +               null);
  +            throw new Exception(Constants.COULD_NOT_FIND_AXIS_CONFIGURATION_0);
            }
   
  +         axisServer = new AxisServer(new XMLResourceProvider(resource));
  +
            // Set the base path for the AxisServer to our WEB-INF directory
  -         axisServerMap.put(getRootContext(),new ClassLoaderAwareAxisServer(new 
XMLResourceProvider(resource)));
  +         axisServerMap.put(getRootContext(), axisServer);
         }
      }
   
  @@ -174,233 +222,219 @@
       *  - register Axis servlet in WebContainer
       *  - contact the maindeployer
       */
  -   public void startService() throws Exception
  -   {
  +   public void startService() throws Exception {
         // set up the axis engine
         ensureService();
   
         // we find out through which URLClassLoader we have been loaded
  -      ClassLoader myLoader=getClass().getClassLoader();
  +      ClassLoader myLoader = getClass().getClassLoader();
   
         // and get our web deployment descriptor through the
         // zip-cache faker
  -      URL resource=fixURL(myLoader.getResource(AXIS_DEPLOYMENT_DESCRIPTOR));
  -      InputStream input=resource.openStream();
  -
  -      if(resource==null)
  -      {
  -         log.getCategory().l7dlog(Priority.ERROR,COULD_NOT_DEPLOY_DESCRIPTOR,new 
Object[0],null);
  -         throw new Exception(COULD_NOT_DEPLOY_DESCRIPTOR);
  +      URL resource =
  +         fixURL(myLoader.getResource(Constants.AXIS_DEPLOYMENT_DESCRIPTOR));
  +      InputStream input = resource.openStream();
  +
  +      if (resource == null) {
  +         log.getCategory().l7dlog(
  +            Priority.ERROR,
  +            Constants.COULD_NOT_DEPLOY_DESCRIPTOR,
  +            new Object[0],
  +            null);
  +         throw new Exception(Constants.COULD_NOT_DEPLOY_DESCRIPTOR);
         }
   
  -
         //next we build the deployment structure that should
         //persuade the web-server to run the axis servlet under
         //our root context
  -      File appDir=new File(getDeployDir()+File.separator+getRootContext());
  +      File appDir = new File(getDeployDir() + File.separator + getRootContext());
   
         //seems like the deploymentinfo is a bit intolerant wrt the existance
         appDir.mkdirs();
   
  -      URL myUrl=appDir.toURL();
  -      myDeploymentInfo=new DeploymentInfo(myUrl,null);
  -      myDeploymentInfo.url=new URL("http://net.jboss.org/fake.war";);
  -
  -      Iterator allDeployers=((Collection)  
server.invoke(MainDeployerMBean.OBJECT_NAME,
  -                    "listDeployers",
  -                    new Object[0],
  -                    new String[0])).iterator();
  -
  -      while(allDeployers.hasNext() && webDeployer==null) {
  -     DeployerMBean nextBean=(DeployerMBean) allDeployers.next();
  -     if(nextBean.accepts(myDeploymentInfo)) {
  -             webDeployer=nextBean;
  -     }
  -      }
  -
  -      if(webDeployer!=null) {
  -
  -      myDeploymentInfo.localUrl=myUrl;
  -
  -      try
  -      {
  -         // the target where the deployemnt descriptor goes to
  -         File target=
  -         new File(appDir+WEB_DEPLOYMENT_DESCRIPTOR);
  -         // create intermediate directories if not yet existing
  -         target.getParentFile().mkdirs();
  -         // this is the output stream for writing the descriptor into
  -         FileOutputStream output=new FileOutputStream(target);
  -         try
  -         {
  -            copy(input, output);
  -         } finally
  -         {
  -            output.close();
  -         }
  -      } finally
  -      {
  -         input.close();
  -      }
  -
  -
  -      // generate a jboss-web file in case that we have a non-trivial
  -      // security domain
  -      if(securityDomain!=null)
  -      {
  -         File target=new File(appDir+JBOSS_WEB_DEPLOYMENT_DESCRIPTOR);
  -         PrintStream output=new PrintStream(new FileOutputStream(target));
  -         try
  -         {
  -            //lets hope that is a valid xml format ;-)
  -            
output.println("<jboss-web><security-domain>"+securityDomain+"</security-domain></jboss-web>");
  -         } finally
  -         {
  -            output.close();
  -         }
  -      }
  -
  -      // we use the root context as URL infix
  -      String rootContext="/"+getRootContext()+"/*";
  -
  -      log.getCategory().l7dlog(Priority.INFO,ABOUT_TO_DEPLOY_0_UNDER_CONTEXT_1,new 
Object[]
  -      {myDeploymentInfo,rootContext},null);
  -
  -      // we fake a new deploymentinfo for the war deployer
  -      myDeploymentInfo.webContext=rootContext;
  -
  -      // Call the war deployer through the JMX server to initialise
  -      // and deploy the info
  -      webDeployer.start(myDeploymentInfo);
  +      URL myUrl = appDir.toURL();
  +      myDeploymentInfo = new DeploymentInfo(myUrl, null);
  +      myDeploymentInfo.url = new URL("http://net.jboss.org/fake.war";);
  +
  +      Iterator allDeployers =
  +         ((Collection) server
  +            .invoke(
  +               MainDeployerMBean.OBJECT_NAME,
  +               "listDeployers",
  +               new Object[0],
  +               new String[0]))
  +            .iterator();
  +
  +      while (allDeployers.hasNext() && webDeployer == null) {
  +         DeployerMBean nextBean = (DeployerMBean) allDeployers.next();
  +         if (nextBean.accepts(myDeploymentInfo)) {
  +            webDeployer = nextBean;
  +         }
  +      }
  +
  +      if (webDeployer != null) {
   
  -      try
  -      {
  -         // Register with the main deployer
  -         server.invoke(
  -            MainDeployerMBean.OBJECT_NAME,
  -            "addDeployer",
  -            new Object[] {this},
  -            new String[] {"org.jboss.deployment.DeployerMBean"});
  -      }
  -      catch (Exception e) {log.error("Could not register with MainDeployer", e);
  -      }
  -     } else {
  -     throw new Exception(Constants.CANNOT_FIND_WEB_DEPLOYER);
  -     }
  +         myDeploymentInfo.localUrl = myUrl;
  +
  +         try {
  +            // the target where the deployemnt descriptor goes to
  +            File target = new File(appDir + Constants.WEB_DEPLOYMENT_DESCRIPTOR);
  +            // create intermediate directories if not yet existing
  +            target.getParentFile().mkdirs();
  +            // this is the output stream for writing the descriptor into
  +            FileOutputStream output = new FileOutputStream(target);
  +            try {
  +               copy(input, output);
  +            } finally {
  +               output.close();
  +            }
  +         } finally {
  +            input.close();
  +         }
  +
  +         // generate a jboss-web file in case that we have a non-trivial
  +         // security domain
  +         if (securityDomain != null) {
  +            File target = new File(appDir + 
Constants.JBOSS_WEB_DEPLOYMENT_DESCRIPTOR);
  +            PrintStream output = new PrintStream(new FileOutputStream(target));
  +            try {
  +               //lets hope that is a valid xml format ;-)
  +               output.println(
  +                  "<jboss-web><security-domain>"
  +                     + securityDomain
  +                     + "</security-domain></jboss-web>");
  +            } finally {
  +               output.close();
  +            }
  +         }
  +
  +         // we use the root context as URL infix
  +         String rootContext = "/" + getRootContext() + "/*";
  +
  +         log.getCategory().l7dlog(
  +            Priority.INFO,
  +            Constants.ABOUT_TO_DEPLOY_0_UNDER_CONTEXT_1,
  +            new Object[] { myDeploymentInfo, rootContext },
  +            null);
  +
  +         // we fake a new deploymentinfo for the war deployer
  +         myDeploymentInfo.webContext = rootContext;
  +
  +         // Call the war deployer through the JMX server to initialise
  +         // and deploy the info
  +         webDeployer.start(myDeploymentInfo);
  +
  +         try {
  +            // Register with the main deployer
  +            server.invoke(
  +               MainDeployerMBean.OBJECT_NAME,
  +               "addDeployer",
  +               new Object[] { this },
  +               new String[] { "org.jboss.deployment.DeployerMBean" });
  +         } catch (Exception e) {
  +            log.error("Could not register with MainDeployer", e);
  +         }
  +      } else {
  +         throw new Exception(Constants.CANNOT_FIND_WEB_DEPLOYER);
  +      }
   
      }
   
      /** what to do to stop axis temporarily --> undeploy the servlet */
  -   public void stopService() throws Exception
  -   {
  +   public void stopService() throws Exception {
         // tear down all running web services
         //Is this really what you want to do? Not leave services running anyway? 
  -      for (Iterator apps = new 
java.util.ArrayList(deployments.values()).iterator(); apps.hasNext(); )
  -      {
  -         DeploymentInfo info= (DeploymentInfo) apps.next();
  -         try 
  -         {
  +      for (Iterator apps = new java.util.ArrayList(deployments.values()).iterator();
  +         apps.hasNext();
  +         ) {
  +         DeploymentInfo info = (DeploymentInfo) apps.next();
  +         try {
               //unregister through server so it's bookeeping is up to date.
  -            server.invoke(MainDeployerMBean.OBJECT_NAME,
  -                          "undeploy",
  -                          new Object[] {info},
  -                          new String[] {"org.jboss.deployment.DeploymentInfo"});
  -         } 
  -         catch(Exception e) 
  -         {
  -            log.error("Could not undeploy deployment "+info,e);
  +            server.invoke(
  +               MainDeployerMBean.OBJECT_NAME,
  +               "undeploy",
  +               new Object[] { info },
  +               new String[] { "org.jboss.deployment.DeploymentInfo" });
  +         } catch (Exception e) {
  +            log.error("Could not undeploy deployment " + info, e);
            }
         }
   
         // deregister from main deployer such that we do not get
         // web services assigned anymore
  -      try
  -      {
  +      try {
            // Register with the main deployer
            server.invoke(
               MainDeployerMBean.OBJECT_NAME,
               "removeDeployer",
  -            new Object[] {this},
  -            new String[] {"org.jboss.deployment.DeployerMBean"});
  -      }
  -      catch (Exception e) 
  -      {
  +            new Object[] { this },
  +            new String[] { "org.jboss.deployment.DeployerMBean" });
  +      } catch (Exception e) {
            log.error("Could not deregister from MainDeployer", e);
         }
   
         // undeploy Axis servlet
  -      try
  -      {
  +      try {
            // undeploy axis servlet
  -         log.getCategory().l7dlog(Priority.INFO,ABOUT_TO_UNDEPLOY_0,new Object[]
  -         {myDeploymentInfo},null);
  +         log.getCategory().l7dlog(
  +            Priority.INFO,
  +            Constants.ABOUT_TO_UNDEPLOY_0,
  +            new Object[] { myDeploymentInfo },
  +            null);
   
            webDeployer.stop(myDeploymentInfo);
   
  -      } catch (Exception e)
  -      {
  -         log.getCategory().error(COULD_NOT_STOP_AXIS, e);
  -      } finally
  -      {
  -         synchronized(AxisService.class)
  -         {
  -            ((AxisServer) axisServerMap.get(getRootContext())).stop();
  +      } catch (Exception e) {
  +         log.getCategory().error(Constants.COULD_NOT_STOP_AXIS, e);
  +      } finally {
  +         synchronized (AxisService.class) {
  +            axisServer.stop();
               axisServerMap.remove(getRootContext());
            }
            super.stopService();
  -         myDeploymentInfo=null;
  +         myDeploymentInfo = null;
         }
   
      }
   
      //----------------------------------------------------------------------------
  -   // static helper that relates contexts and axis engines
  -   //----------------------------------------------------------------------------
  -
  -   /** return the engine if initialised */
  -   public static synchronized AxisServer getAxisServer(String context)
  -   {
  -      return (AxisServer) axisServerMap.get(context);
  -   }
  -
  -
  -   //----------------------------------------------------------------------------
      // security domain
      //----------------------------------------------------------------------------
   
  -
      /** name of the security domain, null if none */
  -   String securityDomain=null;
  +   String securityDomain = null;
   
  -   public String getSecurityDomain()
  -   {
  +   public String getSecurityDomain() {
         return securityDomain;
      }
   
  -   public void setSecurityDomain(String name)
  -   {
  -      log.getCategory().l7dlog(Priority.INFO,SET_SECURITY_DOMAIN_TO_0,new Object[]
  -      {name},null);
  -      securityDomain=name;
  +   public void setSecurityDomain(String name) {
  +      log.getCategory().l7dlog(
  +         Priority.INFO,
  +         Constants.SET_SECURITY_DOMAIN_TO_0,
  +         new Object[] { name },
  +         null);
  +      securityDomain = name;
      }
   
      //----------------------------------------------------------------------------
      // root context  plug
      //----------------------------------------------------------------------------
   
  -   protected String rootContext=DEFAULT_ROOT_CONTEXT;
  +   protected String rootContext = Constants.DEFAULT_ROOT_CONTEXT;
   
  -   public String getRootContext()
  -   {
  +   public String getRootContext() {
         return rootContext;
      }
   
      /** the root context must be constant for the lifetime of the service */
  -   public void setRootContext(String name)
  -   {
  -      log.getCategory().l7dlog(Priority.INFO,SET_ROOT_CONTEXT_0,new Object[]
  -      {name},null);
  -      rootContext=name;
  +   public void setRootContext(String name) {
  +      log.getCategory().l7dlog(
  +         Priority.INFO,
  +         Constants.SET_ROOT_CONTEXT_0,
  +         new Object[] { name },
  +         null);
  +      rootContext = name;
      }
   
      //----------------------------------------------------------------------------
  @@ -417,63 +451,56 @@
       *         deployed by this deployer
       */
      public boolean accepts(DeploymentInfo sdi) {
  -    if(sdi.url.getFile().endsWith(WSR_FILE_EXTENSION)) {
  -      try
  -      {
  -         if(sdi.localCl.getResource(WEB_SERVICE_DESCRIPTOR)!=null) {
  -          return true;
  +      if (sdi.url.getFile().endsWith(Constants.WSR_FILE_EXTENSION)) {
  +         try {
  +            if (sdi.localCl.getResource(Constants.WEB_SERVICE_DESCRIPTOR) != null) {
  +               return true;
  +            }
  +         } catch (Exception e) {
            }
  -      } catch (Exception e) { }
  -    }
  +      }
         return false;
      }
   
  -  /*
  -   * Init a deployment
  -   *
  -   * parse the XML MetaData.  Init and deploy are separate steps allowing for 
subDeployment
  -   * in between.
  -   *
  -   * @param url    The URL to deploy.
  -   *
  -   * @throws MalformedURLException    Invalid URL
  -   * @throws IOException              Failed to fetch content
  -   * @throws DeploymentException      Failed to deploy
  -   */
  +   /*
  +    * Init a deployment
  +    *
  +    * parse the XML MetaData.  Init and deploy are separate steps allowing for 
subDeployment
  +    * in between.
  +    *
  +    * @param url    The URL to deploy.
  +    *
  +    * @throws MalformedURLException    Invalid URL
  +    * @throws IOException              Failed to fetch content
  +    * @throws DeploymentException      Failed to deploy
  +    */
   
  -   public void init(DeploymentInfo sdi)
  -    throws DeploymentException {
  +   public void init(DeploymentInfo sdi) throws DeploymentException {
         try {
  -        URL metaInfos=null;
  +         URL metaInfos = null;
   
  -        if(sdi.metaData==null) {
  -            metaInfos=sdi.localCl.
  -              getResource(WEB_SERVICE_DESCRIPTOR);
  -        } else {
  -          metaInfos=(URL) sdi.metaData;
  -        }
  +         if (sdi.metaData == null) {
  +            metaInfos = sdi.localCl.getResource(Constants.WEB_SERVICE_DESCRIPTOR);
  +         } else {
  +            metaInfos = (URL) sdi.metaData;
  +         }
   
  -        sdi.metaData=
  -          XMLUtils.newDocument(metaInfos.openStream());;
  +         sdi.metaData = XMLUtils.newDocument(metaInfos.openStream());
   
            //Resolve what to watch
  -         if (sdi.url.getProtocol().startsWith("http"))
  -         {
  +         if (sdi.url.getProtocol().startsWith("http")) {
               // We watch the top only, no directory support
               sdi.watch = sdi.url;
   
  -         } else if(sdi.url.getProtocol().startsWith("file"))
  -         {
  -            sdi.watch=metaInfos;
  +         } else if (sdi.url.getProtocol().startsWith("file")) {
  +            sdi.watch = metaInfos;
            }
   
  -
         } catch (Exception e) {
  -        throw new DeploymentException("problem in init"+e.getMessage());
  +         throw new DeploymentException("problem in init" + e.getMessage());
         }
      }
   
  -
      /**
       * Describe <code>create</code> method here.
       *
  @@ -483,16 +510,18 @@
       * @param sdi a <code>DeploymentInfo</code> value
       * @exception DeploymentException if an error occurs
       */
  -   public void create(DeploymentInfo sdi)
  -      throws DeploymentException 
  -   {
  -      log.getCategory().l7dlog(Priority.INFO,ABOUT_TO_CREATE_AXIS_0,new Object[]
  -         {sdi},null);
  -
  -      if(deployments.containsKey(sdi.url)) {
  -        throw new DeploymentException("attempting to redeploy a depoyed module! " + 
sdi.url);
  +   public void create(DeploymentInfo sdi) throws DeploymentException {
  +      log.getCategory().l7dlog(
  +         Priority.INFO,
  +         Constants.ABOUT_TO_CREATE_AXIS_0,
  +         new Object[] { sdi },
  +         null);
  +
  +      if (deployments.containsKey(sdi.url)) {
  +         throw new DeploymentException(
  +            "attempting to redeploy a depoyed module! " + sdi.url);
         } else {
  -        deployments.put(sdi.url,sdi);
  +         deployments.put(sdi.url, sdi);
         }
   
      }
  @@ -506,180 +535,158 @@
       * @param sdi a <code>DeploymentInfo</code> value
       * @exception DeploymentException if an error occurs
       */
  -   public void start(DeploymentInfo sdi)
  -      throws DeploymentException 
  -   {
  -      log.getCategory().l7dlog(Priority.INFO,ABOUT_TO_START_AXIS_0,new Object[]
  -         {sdi},null);
  +   public void start(DeploymentInfo sdi) throws DeploymentException {
  +      log.getCategory().l7dlog(
  +         Priority.INFO,
  +         Constants.ABOUT_TO_START_AXIS_0,
  +         new Object[] { sdi },
  +         null);
   
         // remember old classloader
  -      ClassLoader previous=Thread.currentThread().getContextClassLoader();
  +      ClassLoader previous = Thread.currentThread().getContextClassLoader();
   
         // build new classloader for naming purposes
  -      URLClassLoader serviceLoader=URLClassLoader.
  -        newInstance(new URL[0],sdi.ucl);
  +      URLClassLoader serviceLoader = URLClassLoader.newInstance(new URL[0], 
sdi.ucl);
   
  -      try
  -      {
  +      try {
            InitialContext iniCtx = new InitialContext();
  -         Context envCtx=null;
  +         Context envCtx = null;
   
            // create a new naming context java:comp/env
  -         try
  -         {
  +         try {
               // enter the apartment
               Thread.currentThread().setContextClassLoader(serviceLoader);
               envCtx = (Context) iniCtx.lookup("java:comp");
               envCtx = envCtx.createSubcontext("env");
  -         } finally
  -         {
  +         } finally {
               // enter the apartment
               Thread.currentThread().setContextClassLoader(previous);
            }
   
  -         // we create a new message context
  -         // connected to our singleton servlet
  -         MessageContext msgContext = new MessageContext((AxisServer) 
axisServerMap.get(getRootContext()));
  -         Document doc=(Document) sdi.metaData;
  +         Document doc = (Document) sdi.metaData;
            // the original command
  -         Element root=doc.getDocumentElement();
  +         Element root = doc.getDocumentElement();
            // the deployment command document
  -         Document deployDoc=XMLUtils.newDocument();
  +         Document deployDoc = XMLUtils.newDocument();
            // create command
  -         Element deploy=deployDoc.createElementNS("m","deploy");
  -         deploy.setAttributeNS("xmlns","m","AdminService");
  +         Element deploy =
  +            deployDoc.createElementNS(root.getNamespaceURI(), "deployment");
  +         NamedNodeMap attributes = root.getAttributes();
  +         for (int count = 0; count < attributes.getLength(); count++) {
  +            Attr attribute = (Attr) attributes.item(count);
  +            deploy.setAttributeNodeNS((Attr) deployDoc.importNode(attribute, true));
  +         }
  +
            // and insert the nodes from the original document
            // and sort out the ejb-ref extensions
  -         NodeList children=root.getChildNodes();
  -         for(int count=0;count<children.getLength();count++)
  -         {
  -            Node actNode=children.item(count);
  -            if(actNode instanceof Element && ((Element) 
actNode).getTagName().equals("ejb-ref"))
  -            {
  -               String 
refName=MetaData.getElementContent(MetaData.getUniqueChild((Element)actNode,"ejb-ref-name"));
  -               String 
linkName=MetaData.getElementContent(MetaData.getUniqueChild((Element)actNode,"ejb-link"));
  -               if(refName==null)
  -                  throw new DeploymentException(this.EJB_REF_MUST_HAVE_UNIQUE_NAME);
  -               if(linkName==null)
  -                  throw new DeploymentException(this.EJB_REF_MUST_HAVE_UNIQUE_LINK);
  +         NodeList children = root.getChildNodes();
  +         for (int count = 0; count < children.getLength(); count++) {
  +            Node actNode = children.item(count);
  +            if (actNode instanceof Element
  +               && ((Element) actNode).getTagName().equals("ejb-ref")) {
  +               String refName =
  +                  MetaData.getElementContent(
  +                     MetaData.getUniqueChild((Element) actNode, "ejb-ref-name"));
  +               String linkName =
  +                  MetaData.getElementContent(
  +                     MetaData.getUniqueChild((Element) actNode, "ejb-link"));
  +               if (refName == null)
  +                  throw new 
DeploymentException(Constants.EJB_REF_MUST_HAVE_UNIQUE_NAME);
  +               if (linkName == null)
  +                  throw new 
DeploymentException(Constants.EJB_REF_MUST_HAVE_UNIQUE_LINK);
   
                  Util.bind(envCtx, refName, new LinkRef(linkName));
  -            } else
  -            {
  -               deploy.appendChild(deployDoc.importNode(actNode,true));
  +            } else {
  +               deploy.appendChild(deployDoc.importNode(actNode, true));
               }
            }
            // insert command into document
            deployDoc.appendChild(deploy);
   
  -         try
  -         {
  +         try {
               Thread.currentThread().setContextClassLoader(serviceLoader);
  -            // and run the axis administrator
  -            admin.AdminService(msgContext, deployDoc);
  -         } catch(AxisFault e)
  -         {
  -            throw new DeploymentException(COULD_NOT_DEPLOY_DESCRIPTOR,e);
  -         } finally
  -         {
  +           new Deployment(deploy).deployToRegistry(((XMLResourceProvider) 
axisServer.
  +                     getConfig()).getDeployment());
  +             axisServer.refreshGlobalOptions();
  +                     axisServer.saveConfiguration();
  +         } catch (Exception e) {
  +            throw new DeploymentException(Constants.COULD_NOT_DEPLOY_DESCRIPTOR, e);
  +         } finally {
               Thread.currentThread().setContextClassLoader(previous);
            }
  -      } catch(NamingException e)
  -      {
  -         throw new DeploymentException(COULD_NOT_DEPLOY_DESCRIPTOR,e);
  +      } catch (NamingException e) {
  +         throw new DeploymentException(Constants.COULD_NOT_DEPLOY_DESCRIPTOR, e);
         }
      }
   
  -   public void stop(DeploymentInfo sdi)
  -      throws DeploymentException 
  -   {
  -      log.getCategory().l7dlog(Priority.INFO,ABOUT_TO_STOP_AXIS_0,new Object[]
  -         {sdi},null);
  -      if(!deployments.containsKey(sdi.url)) {
  -         throw new DeploymentException("Attempting to undeploy a not-deployed unit! 
" + sdi.url);
  +   /** stop a given deployment */
  +   public void stop(DeploymentInfo sdi) throws DeploymentException {
  +      log.getCategory().l7dlog(
  +         Priority.INFO,
  +         Constants.ABOUT_TO_STOP_AXIS_0,
  +         new Object[] { sdi },
  +         null);
  +      if (!deployments.containsKey(sdi.url)) {
  +         throw new DeploymentException(
  +            "Attempting to undeploy a not-deployed unit! " + sdi.url);
         }
  -      // we create a new message context
  -      MessageContext msgContext = new MessageContext((AxisServer) 
axisServerMap.get(getRootContext()));
         // this was the deployment command
  -      Element root=(Element) ((Document) sdi.metaData).getDocumentElement();
  +      Element root = (Element) ((Document) sdi.metaData).getDocumentElement();
         // from which we extract an undeployment counterpart
  -      Document undeployDoc=XMLUtils.newDocument();
  -      Element undeploy=undeployDoc.createElementNS("m","undeploy");
  -      undeploy.setAttributeNS("xmlns","m","AdminService");
  +      Document undeployDoc = XMLUtils.newDocument();
  +      Element undeploy =
  +         undeployDoc.createElementNS(root.getNamespaceURI(), "undeployment");
  +      NamedNodeMap attributes = root.getAttributes();
  +      for (int count = 0; count < attributes.getLength(); count++) {
  +         Attr attribute = (Attr) attributes.item(count);
  +         undeploy.setAttributeNodeNS((Attr) undeployDoc.importNode(attribute, 
true));
  +      }
         // all service and handler entries are copied for
         // that purpose
  -      NodeList children=root.getElementsByTagName("service");
  -      for(int count=0;count<children.getLength();count++)
  -      {
  -         Node actNode=children.item(count);
  -         undeploy.appendChild(undeployDoc.importNode(actNode,true));
  -      }
  -      children=root.getElementsByTagName("handler");
  -      for(int count=0;count<children.getLength();count++)
  -      {
  -         Node actNode=children.item(count);
  -         undeploy.appendChild(undeployDoc.importNode(actNode,true));
  +      NodeList children = root.getElementsByTagName("service");
  +      for (int count = 0; count < children.getLength(); count++) {
  +         Node actNode = children.item(count);
  +         undeploy.appendChild(undeployDoc.importNode(actNode, true));
  +      }
  +      children = root.getElementsByTagName("handler");
  +      for (int count = 0; count < children.getLength(); count++) {
  +         Node actNode = children.item(count);
  +         undeploy.appendChild(undeployDoc.importNode(actNode, true));
         }
         // put command into document
         undeployDoc.appendChild(undeploy);
   
  -      try
  -      {
  -         // and call the administrator
  -         admin.AdminService(msgContext,undeployDoc);
  -      } catch(AxisFault e)
  -      {
  -         throw new DeploymentException(COULD_NOT_UNDEPLOY,e);
  +      try {
  +             // and call the administrator
  +                     new WSDDUndeployment(undeploy).
  +                             undeployFromRegistry(((XMLResourceProvider) 
axisServer.getConfig()).
  +                                     getDeployment());
  +        axisServer.refreshGlobalOptions();
  +             axisServer.saveConfiguration();
  +      } catch (Exception e) {
  +         throw new DeploymentException(Constants.COULD_NOT_UNDEPLOY, e);
         }
      }
   
  -   public void destroy(DeploymentInfo sdi)
  -      throws DeploymentException
  -   {
  -      log.getCategory().l7dlog(Priority.INFO,ABOUT_TO_DESTROY_AXIS_0,new Object[]
  -         {sdi},null);
  +   /** destroy a given deployment */
  +   public void destroy(DeploymentInfo sdi) throws DeploymentException {
  +      log.getCategory().l7dlog(
  +         Priority.INFO,
  +         Constants.ABOUT_TO_DESTROY_AXIS_0,
  +         new Object[] { sdi },
  +         null);
      }
   
      //
  -   // Some helper methods
  +   // Statics
      //
   
  -   /** work around broken JarURLConnection caching... thx Jules for the hack ;-) */
  -   private URL fixURL(URL url) throws MalformedURLException
  -   {
  -      String urlString=url.toString();
  -      //determine the last slash
  -      int index=urlString.lastIndexOf(":")+1;
  -      // no slash, we take the last protocol or drive id
  -      if(index==0)
  -      {
  -         // we cannot fix this
  -         return url;
  -      } else
  -      {
  -         return new URL(urlString.substring(0,index)+
  -         "/."+urlString.substring(index));
  -      }
  -   }
  -
  -   protected String getDeployDir() throws Exception {
  -      File systemTempDir = (File)
  -         server.getAttribute(ServerConfigImplMBean.OBJECT_NAME, "TempDir");
  -
  -      return new File(new File(systemTempDir, "deploy"),
  -                      AXIS_DEPLOY_DIR).getCanonicalPath();
  -   }
  -
  -   protected void copy(InputStream in, OutputStream out)
  -   throws IOException
  -   {
  +   /** the axis engines */
  +   final static Map axisServerMap = new java.util.HashMap();
   
  -      byte[] buffer = new byte[1024];
  -      int read;
  -      while ((read = in.read(buffer)) > 0)
  -      {
  -         out.write(buffer, 0, read);
  -      }
  +   /** return the engine if initialised */
  +   public static synchronized AxisServer getAxisServer(String context) {
  +      return (AxisServer) axisServerMap.get(context);
      }
   
  -}
  +}
  \ No newline at end of file
  
  
  
  1.2       +26 -29    
contrib/jboss.net/src/main/org/jboss/net/axis/server/AxisServiceServlet.java
  
  Index: AxisServiceServlet.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jboss.net/src/main/org/jboss/net/axis/server/AxisServiceServlet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AxisServiceServlet.java   3 Oct 2001 13:20:31 -0000       1.1
  +++ AxisServiceServlet.java   12 Mar 2002 11:04:46 -0000      1.2
  @@ -24,36 +24,33 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
    * @created 7. September 2001, 19:17
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   
  -public class AxisServiceServlet extends AxisServlet implements Constants {
  -    
  -    /** Creates new AxisServlet */
  -    public AxisServiceServlet() {
  -    }
  -    
  -    /** override AxisServlet.getEngine() in order to redirect to
  -     *  the corresponding AxisEngine
  -     */
  -    public AxisServer getEngine() {
  -            if (getServletContext().getAttribute(AXIS_ENGINE_ATTRIBUTE) == null) {
  -                // we need to extract the engine from the 
  -                // rootcontext
  -                String installation=getServletContext().getRealPath("");
  -                if(installation.indexOf(File.separator)!=-1)
  -                    
installation=installation.substring(installation.lastIndexOf(File.separator)+1);
  -                // call the static service method to find the installed engine
  -                getServletContext().setAttribute(AXIS_ENGINE_ATTRIBUTE,
  -                    AxisService.getAxisServer(installation));   
  -            }
  -            
  -            return 
(AxisServer)getServletContext().getAttribute(AXIS_ENGINE_ATTRIBUTE);
  -    }
  -     
  -    /** return only special message contexts*/
  -    public MessageContext createMessageContext(AxisEngine engine) {
  -        return new ClassLoaderAwareMessageContext(engine);
  -    }
  -    
  +public class AxisServiceServlet extends AxisServlet {
  +
  +   /** Creates new AxisServlet */
  +   public AxisServiceServlet() {
  +   }
  +
  +   /** override AxisServlet.getEngine() in order to redirect to
  +    *  the corresponding AxisEngine.
  +    */
  +   public AxisServer getEngine() {
  +      if (getServletContext().getAttribute(Constants.AXIS_ENGINE_ATTRIBUTE) == 
null) {
  +         // we need to extract the engine from the 
  +         // rootcontext
  +         String installation = getServletContext().getRealPath("");
  +         if (installation.indexOf(File.separator) != -1)
  +            installation =
  +               installation.substring(installation.lastIndexOf(File.separator) + 1);
  +         // call the static service method to find the installed engine
  +         getServletContext().setAttribute(
  +            Constants.AXIS_ENGINE_ATTRIBUTE,
  +            AxisService.getAxisServer(installation));
  +      }
  +
  +      return (AxisServer) 
getServletContext().getAttribute(Constants.AXIS_ENGINE_ATTRIBUTE);
  +   }
  +
   }
  
  
  
  1.2       +53 -62    
contrib/jboss.net/src/main/org/jboss/net/axis/server/EJBProvider.java
  
  Index: EJBProvider.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jboss.net/src/main/org/jboss/net/axis/server/EJBProvider.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EJBProvider.java  7 Oct 2001 20:06:11 -0000       1.1
  +++ EJBProvider.java  12 Mar 2002 11:04:46 -0000      1.2
  @@ -1,9 +1,12 @@
   /*
  - * EJBProvider.java
  + * JBoss, the OpenSource J2EE webOS
    *
  - * Created on 5. Oktober 2001, 13:02
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
    */
   
  +// $Id: EJBProvider.java,v 1.2 2002/03/12 11:04:46 cgjung Exp $
  +
   package org.jboss.net.axis.server;
   
   import org.apache.axis.Handler;
  @@ -16,67 +19,55 @@
   import java.lang.reflect.Method;
   
   /**
  - *
  - * @author  jung
  - * @version
  + * A JBoss compatible EJB Provider.
  + * <br>
  + * <h3>Change History</h3>
  + * <ul>
  + * <li> jung, 09.03.02: axis alpha 3 is here. </li>
  + * </ul>
  + * <br>
  + * <h3>To Do</h3>
  + * <ul>
  + * <li> jung, 12.03.02: need to support home methods.</li>
  + * </ul>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
  + * @created 5. Oktober 2001, 13:02
  + * @version $Revision: 1.2 $
    */
   
   public class EJBProvider extends org.apache.axis.providers.java.EJBProvider {
  -    
  -    /** Creates new EJBProvider */
  -    public EJBProvider() {
  -    }
  -    
  -    protected Object getNewServiceObject(MessageContext msgContext, String clsName)
  -        throws Exception {
  -                   Handler serviceHandler = msgContext.getServiceHandler();
  -            
  -            Object home;
  -            
  -            try {
  -                Context context = new InitialContext();
  -                
  -                if (null == context) {
  -                    throw new AxisFault("EJBProvider can't get Context");
  -                }
  -                
  -                home =  context.lookup(clsName);
  -                
  -                if (null == home) {
  -                    throw new AxisFault("EJBProvider can't get Bean Home");
  -                }
  -            }
  -            catch (Exception exception) {
  -                throw new AxisFault(exception);
  -            }
  -            
  -            Class homeClass = home.getClass();
  -            Class params[] = new Class[0];
  -            Method createMethod = homeClass.getMethod("create", params);
  -            
  -            Object args[] = new Object[0];
  -            Object result = createMethod.invoke(home, args);
  -            
  -            return result;
  -    }
  -    
  -    /**
  -     * Invoke the message by obtaining various common fields, looking up
  -     * the service object (via getServiceObject), and actually processing
  -     * the message (via processMessage).
  -     */
  -    public void invoke(MessageContext msgContext) throws AxisFault {
  -        
  -        // enter the right deployment-time classloader in order to
  -        // reinstall the right naming, security, etc. environment
  -        ClassLoader old=Thread.currentThread().getContextClassLoader();
  -        
Thread.currentThread().setContextClassLoader(msgContext.getClassLoader().getParent());
  -        
  -        try{
  -            super.invoke(msgContext);
  -        } finally {
  -            Thread.currentThread().setContextClassLoader(old);
  -        }
  -    }
  -    
  +
  +   /** Creates new EJBProvider */
  +   public EJBProvider() {
  +   }
  +
  +   /**
  +    * Invoke the message by delegating to super
  +    */
  +   public void invoke(MessageContext msgContext) throws AxisFault {
  +      super.invoke(msgContext);
  +   }
  +
  +   /**
  +    * Return the object which implements the service.
  +    * 
  +    * @param msgContext the message context
  +    * @param clsName The JNDI name of the EJB home class
  +    * @return an object that implements the service
  +    */
  +   protected Object getNewServiceObject(MessageContext msgContext, String clsName)
  +      throws Exception {
  +      Handler serviceHandler = msgContext.getService();
  +
  +      // Get the EJB Home object from JNDI
  +      Object ejbHome = new InitialContext().lookup(clsName);
  +
  +      // Invoke the create method of the ejbHome class without actually
  +      // touching any EJB classes (i.e. no cast to EJBHome)
  +      Method createMethod = ejbHome.getClass().getMethod("create", 
empty_class_array);
  +      Object result = createMethod.invoke(ejbHome, empty_object_array);
  +
  +      return result;
  +   }
  +
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to