You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2002/05/01 21:55:46 UTC
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/jk/config GeneratorApache2.java GeneratorJk1.java GeneratorJk2.java WebXml2Jk.java
costin 02/05/01 12:55:46
Modified: jk/java/org/apache/jk/config GeneratorJk1.java
GeneratorJk2.java WebXml2Jk.java
Added: jk/java/org/apache/jk/config GeneratorApache2.java
Log:
Few more updates.
Generate all possible config files.
The Apache2-jk2 config is experimental ( for the 'native' mapper ),
but it uses the native apache modules to support Wellcome-Files,
it has correct security mappings, etc.
Revision Changes Path
1.2 +15 -10 jakarta-tomcat-connectors/jk/java/org/apache/jk/config/GeneratorJk1.java
Index: GeneratorJk1.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/config/GeneratorJk1.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GeneratorJk1.java 1 May 2002 17:00:18 -0000 1.1
+++ GeneratorJk1.java 1 May 2002 19:55:45 -0000 1.2
@@ -103,6 +103,7 @@
String vhost;
String cpath;
String worker;
+ PrintWriter out;
public void setWebXmlReader(WebXml2Jk wxml ) {
this.wxml=wxml;
@@ -111,42 +112,46 @@
worker=wxml.worker;
}
- public void generateStart(PrintWriter out ) {
+ public void generateStart( ) throws IOException {
+ File base=wxml.getJkDir();
+ File outF=new File(base, "jk.conf");
+ out=new PrintWriter( new FileWriter( outF ));
+
out.println("# This must be included in the virtual host section for " + vhost );
}
- public void generateEnd(PrintWriter out ) {
-
+ public void generateEnd() {
+ out.close();
}
- public void generateServletMapping( PrintWriter out, String servlet, String url ) {
+ public void generateServletMapping( String servlet, String url ) {
out.println( "JkMount " + cpath + url + " " + worker);
}
- public void generateFilterMapping( PrintWriter out, String servlet, String url ) {
+ public void generateFilterMapping( String servlet, String url ) {
out.println( "JkMount " + cpath + url + " " + worker);
}
- public void generateLoginConfig( PrintWriter out, String loginPage,
+ public void generateLoginConfig( String loginPage,
String errPage, String authM ) {
out.println( "JkMount " + cpath + loginPage + " " + worker);
}
- public void generateErrorPage( PrintWriter out, int err, String location ) {
+ public void generateErrorPage( int err, String location ) {
}
- public void generateMimeMapping( PrintWriter out, String ext, String type ) {
+ public void generateMimeMapping( String ext, String type ) {
}
- public void generateWelcomeFiles( PrintWriter out, Vector wf ) {
+ public void generateWelcomeFiles( Vector wf ) {
}
- public void generateConstraints( PrintWriter out, Vector urls, Vector methods, Vector roles, boolean isSSL ) {
+ public void generateConstraints( Vector urls, Vector methods, Vector roles, boolean isSSL ) {
for( int i=0; i<urls.size(); i++ ) {
String url=(String)urls.elementAt(i);
1.2 +18 -12 jakarta-tomcat-connectors/jk/java/org/apache/jk/config/GeneratorJk2.java
Index: GeneratorJk2.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/config/GeneratorJk2.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GeneratorJk2.java 1 May 2002 17:00:18 -0000 1.1
+++ GeneratorJk2.java 1 May 2002 19:55:45 -0000 1.2
@@ -103,6 +103,7 @@
String vhost;
String cpath;
String worker;
+ PrintWriter out;
public void setWebXmlReader(WebXml2Jk wxml ) {
this.wxml=wxml;
@@ -111,28 +112,33 @@
worker=wxml.worker;
}
- public void generateStart(PrintWriter out ) {
+ public void generateStart( ) throws IOException {
+ File base=wxml.getJkDir();
+ File outF=new File(base, "jk2map.properties");
+ out=new PrintWriter( new FileWriter( outF ));
+
out.println("# Autogenerated from web.xml" );
}
- public void generateEnd(PrintWriter out ) {
-
+ public void generateEnd() {
+ out.close();
}
- public void generateServletMapping( PrintWriter out, String servlet, String url ) {
+
+ public void generateServletMapping( String servlet, String url ) {
out.println( "[url:" + vhost + cpath + url + "]");
out.println( "group=" + worker );
out.println( "servlet=" + servlet);
out.println();
}
- public void generateFilterMapping( PrintWriter out, String servlet, String url ) {
+ public void generateFilterMapping( String servlet, String url ) {
out.println( "[url:" + vhost + cpath + url + "]");
out.println( "group=" + worker );
out.println( "filter=" + servlet);
out.println();
}
- public void generateLoginConfig( PrintWriter out, String loginPage,
+ public void generateLoginConfig( String loginPage,
String errPage, String authM ) {
out.println("[url:" + vhost + cpath + loginPage + "]" );
out.println( "group=" + worker );
@@ -142,31 +148,31 @@
out.println();
}
- public void generateErrorPage( PrintWriter out, int err, String location ) {
+ public void generateErrorPage( int err, String location ) {
}
- public void generateMimeMapping( PrintWriter out, String ext, String type ) {
+ public void generateMimeMapping( String ext, String type ) {
}
- public void generateWelcomeFiles( PrintWriter out, Vector wf ) {
+ public void generateWelcomeFiles( Vector wf ) {
}
- public void generateConstraints( PrintWriter out, Vector urls, Vector methods, Vector roles, boolean isSSL ) {
+ public void generateConstraints( Vector urls, Vector methods, Vector roles, boolean isSSL ) {
for( int i=0; i<urls.size(); i++ ) {
String url=(String)urls.elementAt(i);
out.println("[url:" + vhost + cpath + url + "]");
out.println( "group=" + worker );
for( int j=0; j<roles.size(); j++ ) {
- String role=(String)roles.elementAt(i);
+ String role=(String)roles.elementAt(j);
out.println( "role=" + role);
}
for( int j=0; j<methods.size(); j++ ) {
- String m=(String)methods.elementAt(i);
+ String m=(String)methods.elementAt(j);
out.println( "method=" + m);
}
if( isSSL )
1.4 +125 -107 jakarta-tomcat-connectors/jk/java/org/apache/jk/config/WebXml2Jk.java
Index: WebXml2Jk.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/config/WebXml2Jk.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WebXml2Jk.java 1 May 2002 17:00:18 -0000 1.3
+++ WebXml2Jk.java 1 May 2002 19:55:45 -0000 1.4
@@ -172,29 +172,53 @@
/** Start section( vhost declarations, etc )
*/
- void generateStart(PrintWriter out );
+ void generateStart() throws IOException ;
- void generateEnd(PrintWriter out );
+ void generateEnd() throws IOException ;
- void generateServletMapping( PrintWriter out,
- String servlet, String url );
- void generateFilterMapping( PrintWriter out, String servlet, String url );
+ void generateServletMapping( String servlet, String url )throws IOException ;
+ void generateFilterMapping( String servlet, String url ) throws IOException ;
- void generateLoginConfig( PrintWriter out, String loginPage,
- String errPage, String authM );
+ void generateLoginConfig( String loginPage,
+ String errPage, String authM ) throws IOException ;
- void generateErrorPage( PrintWriter out, int err, String location );
-
- void generateMimeMapping( PrintWriter out, String ext, String type );
-
- void generateWelcomeFiles( PrintWriter out, Vector wf );
-
- void generateConstraints( PrintWriter out, Vector urls, Vector methods, Vector roles, boolean isSSL );
+ void generateErrorPage( int err, String location ) throws IOException ;
+
+ void generateConstraints( Vector urls, Vector methods, Vector roles, boolean isSSL ) throws IOException ;
}
// -------------------- Implementation --------------------
- void generate(PrintWriter out, MappingGenerator gen, Node webN ) {
+ Node webN;
+ File jkDir;
+
+ /** Return the top level node
+ */
+ public Node getWebXmlNode() {
+ return webN;
+ }
+
+ public File getJkDir() {
+ return jkDir;
+ }
+
+ /** Extract the wellcome files from the web.xml
+ */
+ public Vector getWellcomeFiles() {
+ Node n0=getChild( webN, "welcome-file-list" );
+ Vector wF=new Vector();
+ if( n0!=null ) {
+ for( Node mapN=getChild( webN, "welcome-file" );
+ mapN != null; mapN = getNext( mapN ) ) {
+ wF.addElement( getContent(mapN));
+ }
+ }
+ // XXX Add index.html, index.jsp
+ return wF;
+ }
+
+ void generate(MappingGenerator gen ) throws IOException {
+ gen.generateStart();
log.info("Generating mappings for servlets " );
for( Node mapN=getChild( webN, "servlet-mapping" );
mapN != null; mapN = getNext( mapN ) ) {
@@ -202,7 +226,7 @@
String serv=getChildContent( mapN, "servlet-name");
String url=getChildContent( mapN, "url-pattern");
- gen.generateServletMapping( out, serv, url );
+ gen.generateServletMapping( serv, url );
}
log.info("Generating mappings for filters " );
@@ -212,7 +236,7 @@
String filter=getChildContent( mapN, "filter-name");
String url=getChildContent( mapN, "url-pattern");
- gen.generateFilterMapping( out, filter, url );
+ gen.generateFilterMapping( filter, url );
}
@@ -224,32 +248,13 @@
if( errorCode!=null && ! "".equals( errorCode ) ) {
try {
int err=new Integer( errorCode ).intValue();
- gen.generateErrorPage( out, err, location );
+ gen.generateErrorPage( err, location );
} catch( Exception ex ) {
log.error( "Format error " + location, ex);
}
}
}
-
- Node n0=getChild( webN, "welcome-file-list" );
- if( n0!=null ) {
- Vector wF=new Vector();
- for( Node mapN=getChild( webN, "welcome-file" );
- mapN != null; mapN = getNext( mapN ) ) {
- wF.addElement( getContent(mapN));
- }
- gen.generateWelcomeFiles( out, wF );
- }
-
- for( Node mapN=getChild( webN, "mime-mapping" );
- mapN != null; mapN = getNext( mapN ) ) {
- String ext=getChildContent( mapN, "extension" );
- String type=getChildContent( mapN, "mime-type" );
-
- gen.generateMimeMapping( out, ext, type );
- }
-
Node lcN=getChild( webN, "login-config" );
if( lcN!=null ) {
log.info("Generating mapping for login-config " );
@@ -262,7 +267,11 @@
String loginPage= getChildContent( n1, "form-login-page");
String errPage= getChildContent( n1, "form-error-page");
- gen.generateLoginConfig( out, loginPage, errPage, authMeth );
+ if(loginPage != null) {
+ int lpos = loginPage.lastIndexOf("/");
+ String jscurl = loginPage.substring(0,lpos+1) + "j_security_check";
+ gen.generateLoginConfig( jscurl, errPage, authMeth );
+ }
}
log.info("Generating mappings for security constraints " );
@@ -299,15 +308,88 @@
isSSL=true;
}
}
- for( Node rN=getChild(acN, "role-name");
- rN!=null; rN=getNext( rN )) {
- roles.addElement(getContent( rN ));
+
+ gen.generateConstraints( urls, methods, roles, isSSL );
+ }
+ gen.generateEnd();
+ }
+
+ // -------------------- Main and ant wrapper --------------------
+
+ public void execute() {
+ try {
+ if( docBase== null) {
+ log.error("No docbase - please specify the base directory of you web application ( -docBase PATH )");
+ return;
+ }
+ if( cpath== null) {
+ log.error("No context - please specify the mount ( -context PATH )");
+ return;
+ }
+ File docbF=new File(docBase);
+ File wXmlF=new File( docBase, "WEB-INF/web.xml");
+
+ Document wXmlN=readXml(wXmlF);
+ if( wXmlN == null ) return;
+
+ webN = wXmlN.getDocumentElement();
+ if( webN==null ) {
+ log.error("Can't find web-app");
+ return;
}
- gen.generateConstraints( out, urls, methods, roles, isSSL );
+ jkDir=new File( docbF, "WEB-INF/jk2" );
+ jkDir.mkdirs();
+
+ MappingGenerator generator=new GeneratorJk2();
+ generator.setWebXmlReader( this );
+ generate( generator );
+
+ generator=new GeneratorJk1();
+ generator.setWebXmlReader( this );
+ generate( generator );
+
+ generator=new GeneratorApache2();
+ generator.setWebXmlReader( this );
+ generate( generator );
+
+ } catch( Exception ex ) {
+ ex.printStackTrace();
}
}
+
+ public static void main(String args[] ) {
+ try {
+ if( args.length == 1 &&
+ ( "-?".equals(args[0]) || "-h".equals( args[0])) ) {
+ System.out.println("Usage: ");
+ System.out.println(" WebXml2Jk [OPTIONS]");
+ System.out.println();
+ System.out.println(" -docBase DIR The location of the webapp. Required");
+ System.out.println(" -group GROUP Group, if you have multiple tomcats with diffrent content. " );
+ System.out.println(" The default is 'lb', and should be used in most cases");
+ System.out.println(" -host HOSTNAME Canonical hostname - for virtual hosts");
+ System.out.println(" -context /CPATH Context path where the app will be mounted");
+ return;
+ }
+
+ WebXml2Jk w2jk=new WebXml2Jk();
+
+ /* do ant-style property setting */
+ IntrospectionUtils.processArgs( w2jk, args, new String[] {},
+ null, new Hashtable());
+ w2jk.execute();
+ } catch( Exception ex ) {
+ ex.printStackTrace();
+ }
+
+ }
+
+ private static org.apache.commons.logging.Log log=
+ org.apache.commons.logging.LogFactory.getLog( WebXml2Jk.class );
+
+
// -------------------- DOM utils --------------------
/** Get the content of a node
@@ -324,6 +406,7 @@
/** Get the first child
*/
public static Node getChild( Node parent, String name ) {
+ if( parent==null ) return null;
Node first=parent.getFirstChild();
if( first==null ) return null;
for (Node node = first; node != null;
@@ -402,70 +485,5 @@
Document doc = db.parse(xmlF);
return doc;
}
-
- // -------------------- Main and ant wrapper --------------------
-
- public void execute() {
- try {
- if( docBase== null ) {
- System.out.println("No docbase ");
- }
- File docbF=new File(docBase);
- File wXmlF=new File( docBase, "WEB-INF/web.xml");
- Document wXmlN=readXml(wXmlF);
- if( wXmlN == null ) return;
-
- if( file==null ) {
- file=docBase + "WEB-INF/jk2.properties";
- }
- PrintWriter out=new PrintWriter( new FileWriter( file ));
-
- Node webN = wXmlN.getDocumentElement();
- if( webN==null ) {
- System.out.println("Can't find web-app");
- return;
- }
-
- MappingGenerator generator=new GeneratorJk2();
-
- generator.setWebXmlReader( this );
- generate( out, generator, webN );
-
-
- } catch( Exception ex ) {
- ex.printStackTrace();
- }
- }
-
-
- public static void main(String args[] ) {
- try {
- if( args.length == 1 &&
- ( "-?".equals(args[0]) || "-h".equals( args[0])) ) {
- System.out.println("Usage: ");
- System.out.println(" WebXml2Jk [OPTIONS]");
- System.out.println();
- System.out.println(" -docBase DIR The location of the webapp. Required");
- System.out.println(" -group GROUP Group, if you have multiple tomcats with diffrent content. " );
- System.out.println(" The default is 'lb', and should be used in most cases");
- System.out.println(" -host HOSTNAME Canonical hostname - for virtual hosts");
- System.out.println(" -context /CPATH Context path where the app will be mounted");
- return;
- }
-
- WebXml2Jk w2jk=new WebXml2Jk();
-
- /* do ant-style property setting */
- IntrospectionUtils.processArgs( w2jk, args, new String[] {},
- null, new Hashtable());
- w2jk.execute();
- } catch( Exception ex ) {
- ex.printStackTrace();
- }
-
- }
-
- private static org.apache.commons.logging.Log log=
- org.apache.commons.logging.LogFactory.getLog( WebXml2Jk.class );
}
1.1 jakarta-tomcat-connectors/jk/java/org/apache/jk/config/GeneratorApache2.java
Index: GeneratorApache2.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.jk.config;
import java.io.*;
import java.net.*;
import java.util.*;
import java.security.*;
import org.apache.tomcat.util.IntrospectionUtils;
import javax.xml.parsers.*;
/* Yes, it's using DOM */
import org.w3c.dom.*;
import org.xml.sax.*;
/* Naming conventions:
JK_CONF_DIR == serverRoot/work ( XXX /jkConfig ? )
- Each vhost has a sub-dir named after the canonycal name
- For each webapp in a vhost, there is a separate WEBAPP_NAME.jkmap
- In httpd.conf ( or equivalent servers ), in each virtual host you
should "Include JK_CONF_DIR/VHOST/jk_apache.conf". The config
file will contain the Alias declarations and other rules required
for apache operation. Same for other servers.
- WebXml2Jk will be invoked by a config tool or automatically for each
webapp - it'll generate the WEBAPP.jkmap files and config fragments.
WebXml2Jk will _not_ generate anything else but mappings.
It should _not_ try to guess locations or anything else - that's
another components' job.
*/
/**
*
* @author Costin Manolache
*/
public class GeneratorApache2 implements WebXml2Jk.MappingGenerator {
WebXml2Jk wxml;
String vhost;
String cpath;
String worker;
PrintWriter out;
public void setWebXmlReader(WebXml2Jk wxml ) {
this.wxml=wxml;
vhost=wxml.vhost;
cpath=wxml.cpath;
worker=wxml.worker;
}
public void generateStart() throws IOException {
File base=wxml.getJkDir();
File outF=new File(base, "jk2.conf");
out=new PrintWriter( new FileWriter( outF ));
out.println("# Must be included in a virtual host context for " + vhost );
out.println("Alias " + cpath + " \"" + wxml.docBase + "\"");
out.println("<Directory \"" + wxml.docBase + "\" >");
out.println(" Options Indexes FollowSymLinks");
generateMimeMapping( out );
generateWelcomeFiles( out);
// If we use this instead of extension mapping for jsp we can avoid most
// jsp security problems.
out.println(" AddHandler jakarta-servlet2 .jsp");
out.println("</Directory>");
out.println();
out.println("<Location \"" + cpath + "/WEB-INF\" >");
out.println(" AllowOverride None");
out.println(" Deny from all");
out.println("</Location>");
out.println();
out.println("<Location \"" + cpath + "/META-INF\" >");
out.println(" AllowOverride None");
out.println(" Deny from all");
out.println("</Location>");
out.println();
}
private void generateWelcomeFiles( PrintWriter out ) {
Vector wf= wxml.getWellcomeFiles();
out.print(" DirectoryIndex ");
for( int i=0; i<wf.size(); i++ ) {
out.print( " " + (String)wf.elementAt(i));
}
out.println();
}
private void generateMimeMapping( PrintWriter out ) {
Node webN=wxml.getWebXmlNode();
for( Node mapN=WebXml2Jk.getChild( webN, "mime-mapping" );
mapN != null; mapN = WebXml2Jk.getNext( mapN ) ) {
String ext=WebXml2Jk.getChildContent( mapN, "extension" );
String type=WebXml2Jk.getChildContent( mapN, "mime-type" );
out.println(" AddType " + type + " " + ext );
}
}
public void generateEnd() {
out.close();
}
public void generateServletMapping( String servlet, String url ) {
out.println( "<Location \"" + cpath + url + "\" >");
out.println( "SetHandler jakarta-servlet2" );
out.println( "JkSet worker " + worker );
out.println( "JkSet servlet " + servlet);
out.println( "</Location>");
out.println();
}
public void generateFilterMapping( String servlet, String url ) {
out.println( "<Location \"" + cpath + url + "\" >");
out.println( "SetHandler jakarta-servlet2" );
out.println( "JkSet worker " + worker );
out.println( "JkSet servlet " + servlet);
out.println( "</Location>");
out.println();
}
public void generateLoginConfig( String loginPage,
String errPage, String authM ) {
out.println();
}
public void generateErrorPage( int err, String location ) {
}
// XXX Only if BASIC/DIGEST and 'integrated auth'
public void generateConstraints( Vector urls, Vector methods, Vector roles, boolean isSSL ) {
for( int i=0; i<urls.size(); i++ ) {
String url=(String)urls.elementAt(i);
out.println( "<Location \"" + cpath + url + "\" >");
if( methods.size() > 0 ) {
out.print("<Limit ");
for( int j=0; j<methods.size(); j++ ) {
String m=(String)methods.elementAt(j);
out.print( " " + m);
}
out.println( " >" );
}
out.println( "AuthType basic" );
out.print( "Require group " );
for( int j=0; j<roles.size(); j++ ) {
String role=(String)roles.elementAt(j);
out.print( " " + role);
}
out.println();
if( methods.size() > 0 ) {
out.println("</Limit>");
}
out.println( "</Location>");
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>