costin      01/02/10 11:17:29

  Modified:    src/share/org/apache/tomcat/startup Main.java Tomcat.java
               src/share/org/apache/tomcat/util/test HttpRequest.java
  Log:
  Cosmetic changes.
  
  - pass the guessed home to Tomcat.
  - move back to "execute()" pattern
  - add explicit setters for all the attributes we expect. Someday we'll
  remove the setAttribute() and reuse the ant code that sets properties.
  ( or the code from XmlMapper ).
  - only one execute() method in Tomcat, args are parsed in execute()
  - added "enableAdmin" option that generates the apps-admin.xml config
  with trusted=true. It's easier to type a command than to edit a file :-)
  - a bit of re-ordering for better reading
  
  Also:
  - in test/HttpRequest, return the URI for all requests ( instead of only GET)
  
  Revision  Changes    Path
  1.25      +2 -1      jakarta-tomcat/src/share/org/apache/tomcat/startup/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/Main.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- Main.java 2001/02/10 16:45:18     1.24
  +++ Main.java 2001/02/10 19:17:28     1.25
  @@ -203,9 +203,10 @@
            Object proxy=cls.newInstance();
   
               IntrospectionUtils.setAttribute( proxy,"args", args );
  +         IntrospectionUtils.setAttribute( proxy,"home", homeDir );
               IntrospectionUtils.setAttribute( proxy,"parentClassLoader",
                                             sharedCl );
  -            IntrospectionUtils.execute(  proxy, "executeWithAttributes" );
  +            IntrospectionUtils.execute(  proxy, "execute" );
            return;
        } catch( Exception ex ) {
            System.out.println("Guessed home=" + homeDir);
  
  
  
  1.55      +77 -33    jakarta-tomcat/src/share/org/apache/tomcat/startup/Tomcat.java
  
  Index: Tomcat.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/Tomcat.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- Tomcat.java       2001/02/10 16:45:18     1.54
  +++ Tomcat.java       2001/02/10 19:17:28     1.55
  @@ -28,6 +28,10 @@
   
       private String action="start";
   
  +    String home=null;
  +    String args[];
  +    ClassLoader parentClassLoader;
  +    
       // null means user didn't set one
       String configFile=null;
       // relative to TOMCAT_HOME
  @@ -37,10 +41,47 @@
       public Tomcat() {
        super("tc_log");
       }
  +    //-------------------- Properties --------------------
  +    
  +    public void setHome(String home) {
  +     this.home=home;
  +    }
  +    
  +    public void setArgs(String args[]) {
  +     this.args=args;
  +    }
  +    
  +
  +    public void setAction(String s ) {
  +     action=s;
  +    }
  +
  +    public void setParentClassLoader( ClassLoader cl ) {
  +     parentClassLoader=cl;
  +    }
  +    // -------------------- main/execute --------------------
  +    
  +    public static void main(String args[] ) {
  +     try {
  +         Tomcat tomcat=new Tomcat();
  +         tomcat.setArgs( args );
  +            tomcat.execute();
  +     } catch(Exception ex ) {
  +         System.out.println(sm.getString("tomcat.fatal"));
  +         System.err.println(Logger.throwableToString(ex));
  +         System.exit(1);
  +     }
  +    }
   
       public void execute() throws Exception {
  +     //      String[] args=(String[])attributes.get("args");
  +        if ( args == null || ! processArgs( args )) {
  +         setAction("help");
  +     }
        if( "stop".equals( action )){
            stop();
  +     } else if( "enableAdmin".equals( action )){
  +         enableAdmin();
        } else if( "help".equals( action )) {
            printUsage();
        } else if( "start".equals( action )) {
  @@ -48,13 +89,32 @@
        }
       }
   
  +    // -------------------- Actions --------------------
  +
  +    public void enableAdmin() throws IOException
  +    {
  +     System.out.println("Overriding apps-admin settings ");
  +     FileWriter fw=new FileWriter( home + File.separator +
  +                                   "conf" + File.separator +
  +                                   "apps-admin.xml" );
  +     PrintWriter pw=new PrintWriter( fw );
  +     pw.println( "<webapps>" );
  +     pw.println( "  <Context path=\"/admin\"");
  +     pw.println( "           docBase=\"webapps/admin\"");
  +     pw.println( "           trusted=\"true\">");
  +     pw.println( "    <SimpleRealm");
  +        pw.println( "      filename=\"conf/users/admin-users.xml\" />");
  +     pw.println( "  </Context>");
  +     pw.println( "</webapps>" );
  +     pw.close();
  +    }
  +     
       public void stop() throws Exception {
        System.out.println(sm.getString("tomcat.stop"));
        try {
            StopTomcat task=
                new  StopTomcat();
   
  -//       task.setConfig( configFile );
            task.execute();     
        }
        catch (TomcatException te) {
  @@ -75,35 +135,16 @@
        ServerXmlReader sxmlConf=new ServerXmlReader();
        sxmlConf.setConfig( configFile );
        tcat.addInterceptor( sxmlConf );
  -        ClassLoader cl=(ClassLoader)attributes.get("parentClassLoader");
  -        //System.out.println("parentClassLoader:"+cl);
  -        //System.out.println("thisClassLoader:"+this.getClass().getClassLoader());
  +        ClassLoader cl=parentClassLoader;
  +
           if (cl==null) cl=this.getClass().getClassLoader();
  -        //System.out.println("parentClassLoader:"+cl);
  +
           tcat.getContextManager().setParentLoader(cl);
        tcat.initContextManager();
   
        tcat.start();
       }
   
  -    public void setAction(String s ) {
  -     action=s;
  -    }
  -
  -    public static void main(String args[] ) {
  -     try {
  -         Tomcat tomcat=new Tomcat();
  -            if( ! tomcat.processArgs( args )) {
  -                tomcat.setAction("help");
  -            }
  -            tomcat.execute();
  -     } catch(Exception ex ) {
  -         System.out.println(sm.getString("tomcat.fatal"));
  -         System.err.println(Logger.throwableToString(ex));
  -         System.exit(1);
  -     }
  -    }
  -
       // -------------------- Command-line args processing --------------------
   
   
  @@ -128,6 +169,8 @@
                return false;
            } else if (arg.equals("-stop")) {
                action="stop";
  +         } else if (arg.equals("-enableAdmin")) {
  +             action="enableAdmin";
            } else if (arg.equals("-g") || arg.equals("-generateConfigs")) {
                // config generation is now a module. //doGenerate=true;
            } else if (arg.equals("-f") || arg.equals("-config")) {
  @@ -147,16 +190,17 @@
        return true;
       }
   
  +    // Hack for Main.java, will be replaced with calling the setters directly
       public void setAttribute(String s,Object o) {
  -        attributes.put(s,o);
  -    }
  -    public void executeWithAttributes() throws Exception {
  -       String[] args=(String[])attributes.get("args");
  -        if ( args != null ){
  -            if( ! processArgs( args )) {
  -                setAction("help");
  -            }
  -        } else setAction("help");
  -        execute();
  +     if( "home".equals( s ) )
  +         setHome( (String)o);
  +     else if("args".equals( s ) ) 
  +         setArgs((String[])o);
  +     else if( "parentClassLoader".equals( s ) ) {
  +         setParentClassLoader((ClassLoader)o);
  +     } else {
  +         System.out.println("Tomcat: setAttribute " + s + "=" + o);
  +         attributes.put(s,o);
  +     }
       }
   }
  
  
  
  1.2       +9 -5      
jakarta-tomcat/src/share/org/apache/tomcat/util/test/HttpRequest.java
  
  Index: HttpRequest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/test/HttpRequest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HttpRequest.java  2001/02/09 03:48:15     1.1
  +++ HttpRequest.java  2001/02/10 19:17:29     1.2
  @@ -420,14 +420,18 @@
       /** Return a URI (guessed) from the requestLine/fullRequest
        */
       public String getURI() {
  -     String toExtract=fullRequest;
  +     String toExtract=getRequestLine();
        if( fullRequest==null ) toExtract=requestLine;
        if( toExtract==null ) return null;
   
  -     if( ! toExtract.startsWith("GET")) return null;
  -     StringTokenizer st=new StringTokenizer( toExtract," " );
  -     st.nextToken(); // GET
  -     return st.nextToken();
  +     //      if( ! toExtract.startsWith("GET")) return null;
  +     try {
  +         StringTokenizer st=new StringTokenizer( toExtract," " );
  +         st.nextToken(); // GET
  +         return st.nextToken();
  +     } catch( Exception ex ) {
  +         return "";
  +     }
       }
   
       // -------------------- Repository for requet definitions ----------
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to