You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by at...@apache.org on 2004/08/06 04:23:37 UTC

cvs commit: jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/servletcontainer TomcatManager.java

ate         2004/08/05 19:23:37

  Modified:    portal/src/webapp/WEB-INF/conf jetspeed.properties
               portal   maven.xml
               maven-plugin plugin.jelly
               portal/src/test/org/apache/jetspeed/deployment
                        TestSimpleDeployment.java
               portal/src/webapp/WEB-INF/assembly jetspeed-spring.xml
               portal/src/java/org/apache/jetspeed/tools/pamanager/servletcontainer
                        TomcatManager.java
  Added:       applications/security/src/webapp/META-INF tomcat-context.xml
  Log:
  Embedded Tomcat context file support for hot deployed war files (JS2-104)
  
  Revision  Changes    Path
  1.62      +7 -1      jakarta-jetspeed-2/portal/src/webapp/WEB-INF/conf/jetspeed.properties
  
  Index: jetspeed.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/webapp/WEB-INF/conf/jetspeed.properties,v
  retrieving revision 1.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- jetspeed.properties	4 Aug 2004 19:48:04 -0000	1.61
  +++ jetspeed.properties	6 Aug 2004 02:23:37 -0000	1.62
  @@ -107,6 +107,12 @@
   #---------------------------------------------------------------------------------
   # Run Auto-Deployment set up
   #----'-----------------------------------------------------------------------------
  +# THE NEXT PROPERTY DEFINITION MAY NOT BE MODIFIED (NOT EVEN BE PADDED WITH WHITESPACE) 
  +# BECAUSE ITS FILTERED BY ANT DURING DEPLOYMENT.
  +# ITS CONCREET VALUE WILL BE SET FROM BUILD PROPERTY org.apache.jetspeed.catalina.version.major 
  +autodeployment.catalina.version.major=4
  +autodeployment.catalina.base=${applicationRoot}/../../
  +autodeployment.catalina.engine=Catalina
   autodeployment.server=localhost
   autodeployment.port=8080
   autodeployment.user=@AUTODEPLOYMENT_USER@
  
  
  
  1.94      +7 -0      jakarta-jetspeed-2/portal/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/maven.xml,v
  retrieving revision 1.93
  retrieving revision 1.94
  diff -u -r1.93 -r1.94
  --- maven.xml	5 Aug 2004 04:49:30 -0000	1.93
  +++ maven.xml	6 Aug 2004 02:23:37 -0000	1.94
  @@ -597,6 +597,13 @@
           <filter token="AUTODEPLOYMENT_USER" value="${org.apache.jetspeed.services.autodeployment.user}"/>
           <filter token="AUTODEPLOYMENT_PASSWORD" value="${org.apache.jetspeed.services.autodeployment.password}"/>
         </filterset>
  +      <!-- Below filter is special because this concerns a numeric property for which a non-numeric token results
  +           in a test failure (TestSpringEngine)
  +           This property therefore MUST remain defined EXACTLY as specified for this filter to be able to work
  +      -->
  +      <filterset begintoken="autodeployment.catalina.version.major" endtoken="4">
  +        <filter token="=" value="autodeployment.catalina.version.major=${org.apache.jetspeed.catalina.version.major}"/>
  +      </filterset>
       </copy>
     </postGoal>
     
  
  
  
  1.13      +14 -0     jakarta-jetspeed-2/maven-plugin/plugin.jelly
  
  Index: plugin.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/maven-plugin/plugin.jelly,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- plugin.jelly	3 Aug 2004 13:57:44 -0000	1.12
  +++ plugin.jelly	6 Aug 2004 02:23:37 -0000	1.13
  @@ -158,6 +158,13 @@
             <filter token="AUTODEPLOYMENT_USER" value="${org.apache.jetspeed.services.autodeployment.user}"/>
             <filter token="AUTODEPLOYMENT_PASSWORD" value="${org.apache.jetspeed.services.autodeployment.password}"/>
           </filterset>
  +        <!-- Below filter is special because this concerns a numeric property for which a non-numeric token results
  +             in a test failure (TestSpringEngine)
  +             This property therefore MUST remain defined EXACTLY as specified for this filter to be able to work
  +        -->
  +        <filterset begintoken="autodeployment.catalina.version.major" endtoken="4">
  +          <filter token="=" value="autodeployment.catalina.version.major=${org.apache.jetspeed.catalina.version.major}"/>
  +        </filterset>
         </copy>
        </util:available>
       
  @@ -187,6 +194,13 @@
         <filterset begintoken="@" endtoken="@">
           <filter token="AUTODEPLOYMENT_USER" value="${org.apache.jetspeed.services.autodeployment.user}"/>
           <filter token="AUTODEPLOYMENT_PASSWORD" value="${org.apache.jetspeed.services.autodeployment.password}"/>
  +      </filterset>
  +      <!-- Below filter is special because this concerns a numeric property for which a non-numeric token results
  +           in a test failure (TestSpringEngine)
  +           This property therefore MUST remain defined EXACTLY as specified for this filter to be able to work
  +      -->
  +      <filterset begintoken="autodeployment.catalina.version.major" endtoken="4">
  +        <filter token="=" value="autodeployment.catalina.version.major=${org.apache.jetspeed.catalina.version.major}"/>
         </filterset>
       </copy>
     	
  
  
  
  1.18      +4 -4      jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/deployment/TestSimpleDeployment.java
  
  Index: TestSimpleDeployment.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/deployment/TestSimpleDeployment.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- TestSimpleDeployment.java	4 Aug 2004 03:57:08 -0000	1.17
  +++ TestSimpleDeployment.java	6 Aug 2004 02:23:37 -0000	1.18
  @@ -143,7 +143,7 @@
       {
   
           System.out.println("Deployment src: " + deploySrc);
  -        manager = new TomcatManager("", 0, "", "");
  +        manager = new TomcatManager("", "", 0, "", 0, "", "");
           SimpleRegistry simpleRegistry = new InMemoryRegistryImpl();
           DeployDecoratorEventListener ddel = new DeployDecoratorEventListener(simpleRegistry, deployRootFile
                   .getAbsolutePath());
  @@ -244,7 +244,7 @@
       
       public void testUndeployVersusRedeploy() throws Exception
       {
  -        manager = new TomcatManager("", 0, "", "");
  +        manager = new TomcatManager("", "", 0, "", 0, "", "");
           
           DeployPortletAppEventListener dpal = new DeployPortletAppEventListener(webAppsDir, new FileSystemPAM(
                   webAppsDir, portletRegistry, entityAccess, windowAccess, portletCache, manager), portletRegistry, portletFactory );
  @@ -461,7 +461,7 @@
        */
       public void tearDown() throws Exception
       {
  -        manager = new TomcatManager("", 0, "", "");
  +        manager = new TomcatManager("", "", 0, "", 0, "", "");
           FileSystemPAM pam = new FileSystemPAM(webAppsDir, portletRegistry, entityAccess, windowAccess, portletCache, manager);
   
           try
  
  
  
  1.1                  jakarta-jetspeed-2/applications/security/src/webapp/META-INF/tomcat-context.xml
  
  Index: tomcat-context.xml
  ===================================================================
  <!--
  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.
  
    $Id: tomcat-context.xml,v 1.1 2004/08/06 02:23:37 ate Exp $
  -->
  <Context crossContext="true">
  </Context>
  
  
  
  1.8       +7 -4      jakarta-jetspeed-2/portal/src/webapp/WEB-INF/assembly/jetspeed-spring.xml
  
  Index: jetspeed-spring.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/webapp/WEB-INF/assembly/jetspeed-spring.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- jetspeed-spring.xml	4 Aug 2004 14:14:45 -0000	1.7
  +++ jetspeed-spring.xml	6 Aug 2004 02:23:37 -0000	1.8
  @@ -316,10 +316,13 @@
     	   class="org.apache.jetspeed.tools.pamanager.servletcontainer.TomcatManager" 
     	   init-method="start" destroy-method="stop"
     >  	   
  -  	   <constructor-arg index="0"><value>${autodeployment.server}</value></constructor-arg>
  -  	   <constructor-arg index="1"><value>${autodeployment.port}</value></constructor-arg>
  -  	   <constructor-arg index="2"><value>${autodeployment.user}</value></constructor-arg>
  -  	   <constructor-arg index="3"><value>${autodeployment.password}</value></constructor-arg>
  +       <constructor-arg index="0"><value>${autodeployment.catalina.base}</value></constructor-arg>
  +       <constructor-arg index="1"><value>${autodeployment.catalina.engine}</value></constructor-arg>
  +       <constructor-arg index="2"><value>${autodeployment.catalina.version.major}</value></constructor-arg>
  +  	   <constructor-arg index="3"><value>${autodeployment.server}</value></constructor-arg>
  +  	   <constructor-arg index="4"><value>${autodeployment.port}</value></constructor-arg>
  +  	   <constructor-arg index="5"><value>${autodeployment.user}</value></constructor-arg>
  +  	   <constructor-arg index="6"><value>${autodeployment.password}</value></constructor-arg>
     </bean>
     <!--
     	Application Server Manager for JBoss.
  
  
  
  1.8       +110 -32   jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/servletcontainer/TomcatManager.java
  
  Index: TomcatManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/servletcontainer/TomcatManager.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TomcatManager.java	4 Aug 2004 04:01:00 -0000	1.7
  +++ TomcatManager.java	6 Aug 2004 02:23:37 -0000	1.8
  @@ -16,6 +16,8 @@
   package org.apache.jetspeed.tools.pamanager.servletcontainer;
   
   import java.io.File;
  +import java.io.FileInputStream;
  +import java.io.FileOutputStream;
   import java.io.IOException;
   import java.io.InputStream;
   import java.net.MalformedURLException;
  @@ -32,6 +34,11 @@
   import org.apache.commons.httpclient.methods.PutMethod;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.jdom.Document;
  +import org.jdom.JDOMException;
  +import org.jdom.input.SAXBuilder;
  +import org.jdom.output.Format;
  +import org.jdom.output.XMLOutputter;
   import org.picocontainer.Startable;
   
   /**
  @@ -46,18 +53,25 @@
   public class TomcatManager implements ApplicationServerManager, Startable
   {
       private static final String DEFUALT_MANAGER_APP_PATH = "/manager";
  +    private static final String EMBEDDED_CONTEXT_FILE_PATH = "/META-INF/tomcat-context.xml";
       protected static final Log log = LogFactory.getLog("deployment");
   
  +    private String catalinaBase;
  +    private String catalinaEngine;
  +    private int catalinaVersionMajor;
       private String hostUrl;
       private int hostPort;
       private String userName;
       private String password;
  -
  +    
  +    private String catalinaContextPath;
  +    
       private String managerAppPath = DEFUALT_MANAGER_APP_PATH;
       private String stopPath = managerAppPath + "/stop";
       private String startPath = managerAppPath + "/start";
       private String removePath = managerAppPath + "/remove";
       private String deployPath = managerAppPath + "/deploy";
  +    private String undeployPath = managerAppPath + "/undeploy";
       private String installPath = managerAppPath + "/install";
       private String reloadPath = managerAppPath + "/reload";
       private String serverInfoPath = managerAppPath + "/serverinfo";
  @@ -76,22 +90,33 @@
   
       private HttpMethod install;
   
  -    protected GetMethod testConnectionMethod;
  -
  -    public TomcatManager(String hostName, int hostPort, String userName, String password) throws HttpException, IOException
  +    public TomcatManager(String catalinaBase, String catalinaEngine, int catalinaVersionMajor, String hostName, int hostPort, String userName, String password) throws HttpException, IOException
       {
           super();
  +        
  +        if ( !catalinaBase.endsWith("/") )
  +        {
  +            this.catalinaBase = catalinaBase + "/";
  +        }
  +        else
  +        {
  +            this.catalinaBase = catalinaBase;
  +        }    
  +        this.catalinaEngine = catalinaEngine;
  +        this.catalinaVersionMajor = catalinaVersionMajor;
           this.hostUrl = hostName;
           this.hostPort = hostPort;
           this.userName = userName;
           this.password = password;        
  +        
  +        if ( catalinaVersionMajor > 4 )
  +        {
  +            catalinaContextPath = this.catalinaBase + "/conf/" + this.catalinaEngine + "/" + this.hostUrl + "/";
  +        }
       }
   
  -  
  -
       public void start() 
       {     
  -
           client = new HttpClient();
   
           HostConfiguration hostConfig = new HostConfiguration();
  @@ -102,15 +127,13 @@
           client.getState().setAuthenticationPreemptive(true);
           client.getState().setCredentials(null, hostUrl, new UsernamePasswordCredentials(userName, password));
   
  -        testConnectionMethod = new GetMethod(serverInfoPath);
  -        //        try
  -        //        {
  -        //            client.executeMethod(test);
  -        //        }
  -        //        finally
  -        //        {
  -        //            test.releaseConnection();
  -        //        }
  +        if ( catalinaVersionMajor > 4 )
  +        {
  +            // Tomcat 5 deprecated manager/install and manager/remove.
  +            // Those are now handled by manager/deploy and manager/undeploy respectively.
  +            installPath = deployPath;
  +            removePath = undeployPath;
  +        }
           start = new GetMethod(startPath);
           stop = new GetMethod(stopPath);
           remove = new GetMethod(removePath);
  @@ -175,7 +198,6 @@
   
       public String remove(String appPath) throws HttpException, IOException
       {
  -
           try
           {
               remove.setQueryString(buildPathQueryArgs(appPath));
  @@ -189,11 +211,72 @@
           }
       }
   
  -    public String install(String warPath, String contexPath) throws HttpException, IOException
  +    public String install(String warPath, String contextPath) throws HttpException, IOException
       {
           try
           {
  -            install.setQueryString(buildWarQueryArgs(warPath, contexPath));
  +            File contextFile = new File(warPath+EMBEDDED_CONTEXT_FILE_PATH);
  +            File warPathFile = new File(warPath);
  +            String canonicalWarPath = warPathFile.getCanonicalPath();
  +
  +            if ( contextPath == null )
  +            {
  +                contextPath = "/"+ warPathFile.getName();
  +            }
  +            else if (!contextPath.startsWith("/"))
  +            {
  +                contextPath = "/" + contextPath;
  +            }
  +
  +            if ( contextFile.exists() )
  +            {
  +                FileInputStream fileInputStream = null;
  +                FileOutputStream fileOutputStream = null;
  +                
  +                try
  +                {
  +                    SAXBuilder saxBuilder = new SAXBuilder();
  +                    fileInputStream = new FileInputStream(contextFile);
  +                    Document document = saxBuilder.build(fileInputStream);
  +                    if (!document.getRootElement().getName().equals("Context"))
  +                    {
  +                        throw new IOException(EMBEDDED_CONTEXT_FILE_PATH+" invalid!!!");
  +                    }
  +                    document.getRootElement().setAttribute("path", contextPath);
  +                    document.getRootElement().setAttribute("docBase", canonicalWarPath);
  +                    XMLOutputter output = new XMLOutputter(Format.getPrettyFormat());
  +                    
  +                    File newContextFile = null;
  +                    if ( catalinaVersionMajor > 4 )
  +                    {
  +                        newContextFile = new File( catalinaContextPath+warPathFile.getName()+".xml");
  +                    }
  +                    else 
  +                    {
  +                        newContextFile = new File( warPathFile.getParentFile(), warPathFile.getName()+".xml");
  +                    }
  +                    fileOutputStream = new FileOutputStream(newContextFile);
  +                    output.output(document, fileOutputStream);
  +                    fileOutputStream.flush();
  +                    
  +                    install.setQueryString(buildConfigQueryArgs(newContextFile.getCanonicalPath(), contextPath));
  +                }
  +                catch (JDOMException e)
  +                {
  +                    IOException ioe = new IOException(EMBEDDED_CONTEXT_FILE_PATH+" invalid");
  +                    ioe.initCause(e);
  +                    throw ioe;
  +                }
  +                finally
  +                {
  +                    if ( fileInputStream != null )
  +                        fileInputStream.close();
  +                    if ( fileOutputStream != null )
  +                        fileOutputStream.close();
  +                }
  +            }
  +            else
  +                install.setQueryString(buildWarQueryArgs(canonicalWarPath, contextPath));
   
               client.executeMethod(install);
               return install.getResponseBodyAsString();
  @@ -241,21 +324,16 @@
   
       protected NameValuePair[] buildWarQueryArgs(String warPath, String appPath) throws MalformedURLException
       {
  -        if (appPath != null)
  -        {
  -            if (!appPath.startsWith("/"))
  -            {
  -                appPath = "/" + appPath;
  -            }
  -            return new NameValuePair[] {
  +        return new NameValuePair[] {
                   new NameValuePair("war", new File(warPath).toURL().toString()),
                   new NameValuePair("path", appPath)};
  -        }
  -        else
  -        {
  -            return new NameValuePair[] { new NameValuePair("war", warPath)};
  -        }
  +    }
   
  +    protected NameValuePair[] buildConfigQueryArgs(String configPath, String appPath) throws MalformedURLException
  +    {
  +        return new NameValuePair[] {
  +                new NameValuePair("config", new File(configPath).toURL().toString()),
  +                new NameValuePair("path", appPath)};
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org