geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r209099 - in /geronimo/trunk/modules/jetty-builder/src: java/org/apache/geronimo/jetty/deployment/ test-resources/deployables/ test-resources/deployables/war5/ test-resources/deployables/war5/WEB-INF/ test-resources/plans/ test/org/apache/g...
Date Mon, 04 Jul 2005 16:30:01 GMT
Author: ammulder
Date: Mon Jul  4 09:30:00 2005
New Revision: 209099

URL: http://svn.apache.org/viewcvs?rev=209099&view=rev
Log:
Support previous namespace

Added:
    geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/TemporaryPlanAdapter.java
    geronimo/trunk/modules/jetty-builder/src/test-resources/deployables/war5/
    geronimo/trunk/modules/jetty-builder/src/test-resources/deployables/war5/WEB-INF/
    geronimo/trunk/modules/jetty-builder/src/test-resources/deployables/war5/WEB-INF/geronimo-jetty.xml
    geronimo/trunk/modules/jetty-builder/src/test-resources/deployables/war5/WEB-INF/web.xml
    geronimo/trunk/modules/jetty-builder/src/test-resources/deployables/war6.war   (with props)
    geronimo/trunk/modules/jetty-builder/src/test-resources/plans/plan2.xml
Modified:
    geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java
    geronimo/trunk/modules/jetty-builder/src/test/org/apache/geronimo/jetty/deployment/PlanParsingTest.java

Modified: geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java?rev=209099&r1=209098&r2=209099&view=diff
==============================================================================
--- geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java
(original)
+++ geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java
Mon Jul  4 09:30:00 2005
@@ -20,6 +20,7 @@
 import java.io.File;
 import java.io.FileFilter;
 import java.io.IOException;
+import java.io.FileNotFoundException;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -109,6 +110,8 @@
 import org.apache.geronimo.xbeans.j2ee.WelcomeFileListType;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlObject;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.mortbay.http.BasicAuthenticator;
 import org.mortbay.http.ClientCertAuthenticator;
 import org.mortbay.http.DigestAuthenticator;
@@ -119,6 +122,7 @@
  * @version $Rev$ $Date$
  */
 public class JettyModuleBuilder implements ModuleBuilder {
+    private final static Log log = LogFactory.getLog(JettyModuleBuilder.class);
     private final URI defaultParentId;
     private final ObjectName jettyContainerObjectName;
     private final ObjectName defaultServlets;
@@ -266,22 +270,32 @@
             // load the geronimo-web.xml from either the supplied plan or from the earFile
             try {
                 if (plan instanceof XmlObject) {
-                    jettyWebApp = (GerWebAppType) SchemaConversionUtils.getNestedObjectAsType((XmlObject)
plan,
-                            "web-app",
-                            GerWebAppType.type);
+                    XmlObject object = SchemaConversionUtils.getNestedObject((XmlObject)
plan, "web-app");
+                    jettyWebApp = TemporaryPlanAdapter.convertJettyElementToWeb(object);
                 } else {
                     GerWebAppDocument jettyWebAppdoc = null;
                     if (plan != null) {
-                        jettyWebAppdoc = GerWebAppDocument.Factory.parse((File) plan);
+                        XmlObject object = SchemaConversionUtils.parse(((File) plan).toURL());
+                        jettyWebAppdoc = TemporaryPlanAdapter.convertJettyDocumentToWeb(object);
                     } else {
                         URL path = DeploymentUtil.createJarURL(moduleFile, "WEB-INF/geronimo-web.xml");
-                        jettyWebAppdoc = GerWebAppDocument.Factory.parse(path);
+                        try {
+                            jettyWebAppdoc = GerWebAppDocument.Factory.parse(path);
+                        } catch (FileNotFoundException e) {
+                            path = DeploymentUtil.createJarURL(moduleFile, "WEB-INF/geronimo-jetty.xml");
+                            XmlObject object = SchemaConversionUtils.parse(path);
+                            if(object != null) {
+                                log.error("Incorrect deployment plan naming: found geronimo-jetty.xml,
should be geronimo-web.xml");
+                                jettyWebAppdoc = TemporaryPlanAdapter.convertJettyDocumentToWeb(object);
+                            }
+                        }
                     }
                     if (jettyWebAppdoc != null) {
                         jettyWebApp = jettyWebAppdoc.getWebApp();
                     }
                 }
             } catch (IOException e) {
+                log.warn(e);
             }
 
             // if we got one extract and validate it otherwise create a default one
@@ -302,6 +316,7 @@
                 jettyWebApp = createDefaultPlan(path, webApp);
             }
         } catch (XmlException e) {
+            e.printStackTrace();
             throw new DeploymentException("xml problem", e);
         }
         return jettyWebApp;

Added: geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/TemporaryPlanAdapter.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/TemporaryPlanAdapter.java?rev=209099&view=auto
==============================================================================
--- geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/TemporaryPlanAdapter.java
(added)
+++ geronimo/trunk/modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/TemporaryPlanAdapter.java
Mon Jul  4 09:30:00 2005
@@ -0,0 +1,89 @@
+package org.apache.geronimo.jetty.deployment;
+
+import java.io.IOException;
+import javax.xml.namespace.QName;
+import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlException;
+import org.apache.geronimo.xbeans.geronimo.web.GerWebAppDocument;
+import org.apache.geronimo.xbeans.geronimo.web.GerWebAppType;
+import org.apache.geronimo.schema.SchemaConversionUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @version $Revision: 1.0$
+ */
+public class TemporaryPlanAdapter {
+    private final static Log log = LogFactory.getLog(TemporaryPlanAdapter.class);
+    private final static String CORRECT_NAMESPACE = "http://geronimo.apache.org/xml/ns/web";
+    private final static String WRONG_NAMESPACE = "http://geronimo.apache.org/xml/ns/web/jetty";
+
+    public static GerWebAppDocument convertJettyDocumentToWeb(XmlObject source) {
+        XmlCursor cursor = source.newCursor();
+        while(!cursor.isStart()) {
+            cursor.toNextToken();
+        }
+
+        if(WRONG_NAMESPACE.equals(cursor.getName().getNamespaceURI())) {
+            log.error("WAR includes a file using the old geronimo-jetty.xml format (including
namespace http://geronimo.apache.org/xml/ns/web/jetty).  This is no longer supported.  Please
change to the new geronimo-web.xml format.  The main difference is that it uses the namespace
http://geronimo.apache.org/xml/ns/web");
+            swapNamespace(cursor, CORRECT_NAMESPACE, WRONG_NAMESPACE);
+        }
+
+        XmlObject result = source.changeType(GerWebAppDocument.type);
+        if (result != null) {
+//            SchemaConversionUtils.validateDD(result);
+            return (GerWebAppDocument) result;
+        }
+//        SchemaConversionUtils.validateDD(source);
+        return (GerWebAppDocument) source;
+    }
+
+    public static GerWebAppType convertJettyElementToWeb(XmlObject source) {
+        XmlCursor cursor = source.newCursor();
+        while(!cursor.isStart()) {
+            cursor.toNextToken();
+        }
+
+        if(WRONG_NAMESPACE.equals(cursor.getName().getNamespaceURI())) {
+            log.error("EAR includes WAR deployment content using the old geronimo-jetty.xml
format (including namespace http://geronimo.apache.org/xml/ns/web/jetty).  This is no longer
supported.  Please change to the new geronimo-web.xml format.  The main difference is that
it uses the namespace http://geronimo.apache.org/xml/ns/web");
+            swapNamespace(cursor, CORRECT_NAMESPACE, WRONG_NAMESPACE);
+        }
+
+        XmlObject result = source.changeType(GerWebAppType.type);
+        if (result != null) {
+            return (GerWebAppType) result;
+        }
+        return (GerWebAppType) source;
+    }
+
+    /**
+     * @return true if the schema was correct to begin with
+     */
+    public static boolean swapNamespace(XmlCursor cursor, String correct, String wrong) {
+        while (cursor.hasNextToken()) {
+            if (cursor.isStart()) {
+                String current = cursor.getName().getNamespaceURI();
+                if (correct.equals(current)) {
+                    //already has correct schema, exit
+                    return true;
+                } else if(wrong.equals(current)) {
+                    cursor.setName(new QName(correct, cursor.getName().getLocalPart()));
+                }
+            }
+            cursor.toNextToken();
+        }
+        return false;
+    }
+
+    public static void main(String[] args) {
+        try {
+            convertJettyDocumentToWeb(SchemaConversionUtils.parse(new java.io.File("/home/ammulder/cvs/geronimo/modules/jetty-builder/src/test-resources/deployables/war1/WEB-INF/geronimo-web.xml").toURL()));
+            convertJettyDocumentToWeb(SchemaConversionUtils.parse(new java.io.File("/home/ammulder/cvs/geronimo/modules/jetty-builder/src/test-resources/deployables/war3/WEB-INF/geronimo-web.xml").toURL()));
+        } catch (XmlException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+}

Added: geronimo/trunk/modules/jetty-builder/src/test-resources/deployables/war5/WEB-INF/geronimo-jetty.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty-builder/src/test-resources/deployables/war5/WEB-INF/geronimo-jetty.xml?rev=209099&view=auto
==============================================================================
--- geronimo/trunk/modules/jetty-builder/src/test-resources/deployables/war5/WEB-INF/geronimo-jetty.xml
(added)
+++ geronimo/trunk/modules/jetty-builder/src/test-resources/deployables/war5/WEB-INF/geronimo-jetty.xml
Mon Jul  4 09:30:00 2005
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+-->
+
+<web-app
+    xmlns="http://geronimo.apache.org/xml/ns/web/jetty"
+    xmlns:sec="http://geronimo.apache.org/xml/ns/security"
+    configId="org/apache/geronimo/test">
+
+    <context-root>/test</context-root>
+    <context-priority-classloader>false</context-priority-classloader>
+    <security-realm-name>demo-properties-realm</security-realm-name>
+    <sec:security>
+        <sec:default-principal realm-name="demo-properties-realm">
+            <sec:principal class="org.apache.geronimo.security.realm.providers.PropertiesFileUserPrincipal"
name="izumi"/>
+        </sec:default-principal>
+    </sec:security>
+    <resource-ref>
+        <ref-name>jdbc/DB1</ref-name>
+        <target-name>DefaultDatabase</target-name>
+    </resource-ref>
+</web-app>

Added: geronimo/trunk/modules/jetty-builder/src/test-resources/deployables/war5/WEB-INF/web.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty-builder/src/test-resources/deployables/war5/WEB-INF/web.xml?rev=209099&view=auto
==============================================================================
--- geronimo/trunk/modules/jetty-builder/src/test-resources/deployables/war5/WEB-INF/web.xml
(added)
+++ geronimo/trunk/modules/jetty-builder/src/test-resources/deployables/war5/WEB-INF/web.xml
Mon Jul  4 09:30:00 2005
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+-->
+  
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+    <description>Test Web Deployment</description>
+    <resource-env-ref>
+        <resource-env-ref-name>fake-resource-env-ref</resource-env-ref-name>
+        <resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
+    </resource-env-ref>
+    <resource-ref>
+        <res-ref-name>fake-resource-ref</res-ref-name>
+        <res-type>javax.sql.DataSource</res-type>
+        <res-auth>Container</res-auth>
+        <res-sharing-scope>Shareable</res-sharing-scope>
+    </resource-ref>
+
+    <security-constraint>
+        <web-resource-collection>
+            <web-resource-name>Admin Role</web-resource-name>
+            <url-pattern>/protected/*</url-pattern>
+        </web-resource-collection>
+        <auth-constraint>
+            <role-name>content-administrator</role-name>
+        </auth-constraint>
+    </security-constraint>
+
+    <security-constraint>
+        <web-resource-collection>
+            <web-resource-name>NO ACCESS</web-resource-name>
+            <url-pattern>/auth/logon.html</url-pattern>
+        </web-resource-collection>
+        <auth-constraint/>
+    </security-constraint>
+
+    <login-config>
+        <auth-method>FORM</auth-method>
+        <realm-name>Test JAAS Realm</realm-name>
+        <form-login-config>
+            <form-login-page>/auth/logon.html?param=test</form-login-page>
+            <form-error-page>/auth/logonError.html?param=test</form-error-page>
+        </form-login-config>
+    </login-config>
+
+    <security-role>
+        <role-name>content-administrator</role-name>
+    </security-role>
+
+    <ejb-ref>
+        <ejb-ref-name>fake-ejb-ref</ejb-ref-name>
+        <ejb-ref-type>Entity</ejb-ref-type>
+        <home>some.package.FakeHome</home>
+        <remote>some.package.Fake</remote>
+    </ejb-ref>
+    <ejb-ref>
+        <ejb-ref-name>another-ejb-ref</ejb-ref-name>
+        <ejb-ref-type>Entity</ejb-ref-type>
+        <home>some.package.FakeHome</home>
+        <remote>some.package.Fake</remote>
+    </ejb-ref>
+    <ejb-local-ref>
+        <ejb-ref-name>fake-ejb-local-ref</ejb-ref-name>
+        <ejb-ref-type>Entity</ejb-ref-type>
+        <local-home>some.package.FakeLocalHome</local-home>
+        <local>some.package.FakeLocal</local>
+    </ejb-local-ref>
+    <ejb-local-ref>
+        <ejb-ref-name>another-ejb-local-ref</ejb-ref-name>
+        <ejb-ref-type>Entity</ejb-ref-type>
+        <local-home>some.package.FakeLocalHome</local-home>
+        <local>some.package.FakeLocal</local>
+    </ejb-local-ref>
+
+</web-app>
\ No newline at end of file

Added: geronimo/trunk/modules/jetty-builder/src/test-resources/deployables/war6.war
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty-builder/src/test-resources/deployables/war6.war?rev=209099&view=auto
==============================================================================
Binary file - no diff available.

Propchange: geronimo/trunk/modules/jetty-builder/src/test-resources/deployables/war6.war
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: geronimo/trunk/modules/jetty-builder/src/test-resources/plans/plan2.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty-builder/src/test-resources/plans/plan2.xml?rev=209099&view=auto
==============================================================================
--- geronimo/trunk/modules/jetty-builder/src/test-resources/plans/plan2.xml (added)
+++ geronimo/trunk/modules/jetty-builder/src/test-resources/plans/plan2.xml Mon Jul  4 09:30:00
2005
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://geronimo.apache.org/xml/ns/web/jetty"
+    configId="goodservlet"
+    parentId="org/apache/geronimo/DefaultDatabase">
+    <context-priority-classloader>false</context-priority-classloader>
+    <security-realm-name>public-properties-realm</security-realm-name>
+    <security default-role="UNASSIGNED" doas-current-caller="true">
+        <default-principal realm-name="public-properties-realm">
+            <principal class="org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal"
name="guest"/>
+        </default-principal>
+
+        <role-mappings>
+            <role role-name="UNASSIGNED">
+                <realm realm-name="public-properties-realm">
+                    <principal class="org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal"
name="guest" designated-run-as="true"/>
+                </realm>
+            </role>
+
+            <role role-name="LOW">
+                <realm realm-name="public-properties-realm">
+                    <principal class="org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal"
name="acct" designated-run-as="true"/>
+                </realm>
+                <distinguished-name name="CN=Duke, OU=Java Software, O=Sun Microsystems\,
Inc., L=Palo Alto, ST=CA, C=US"/>
+            </role>
+
+            <role role-name="MEDIUM">
+                <realm realm-name="public-properties-realm">
+                    <principal class="org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal"
name="it"/>
+                    <principal class="org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal"
name="george" designated-run-as="true"/>
+                </realm>
+            </role>
+
+            <role role-name="HIGH">
+                <realm realm-name="public-properties-realm">
+                    <principal class="org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal"
name="mgmt" designated-run-as="true"/>
+                </realm>
+                <realm realm-name="black-properties-realm">
+                    <principal class="org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal"
name="dain"/>
+                    <principal class="org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal"
name="david"/>
+                </realm>
+            </role>
+        </role-mappings>
+    </security>
+    <resource-ref>
+        <ref-name>jdbc/DB1</ref-name>
+        <target-name>DefaultDatabase</target-name>
+    </resource-ref>
+</web-app>

Modified: geronimo/trunk/modules/jetty-builder/src/test/org/apache/geronimo/jetty/deployment/PlanParsingTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty-builder/src/test/org/apache/geronimo/jetty/deployment/PlanParsingTest.java?rev=209099&r1=209098&r2=209099&view=diff
==============================================================================
--- geronimo/trunk/modules/jetty-builder/src/test/org/apache/geronimo/jetty/deployment/PlanParsingTest.java
(original)
+++ geronimo/trunk/modules/jetty-builder/src/test/org/apache/geronimo/jetty/deployment/PlanParsingTest.java
Mon Jul  4 09:30:00 2005
@@ -1,6 +1,7 @@
 package org.apache.geronimo.jetty.deployment;
 
 import java.io.File;
+import java.util.jar.JarFile;
 import javax.management.ObjectName;
 
 import junit.framework.TestCase;
@@ -10,6 +11,7 @@
 import org.apache.geronimo.xbeans.geronimo.web.GerWebAppType;
 import org.apache.geronimo.xbeans.geronimo.naming.GerResourceRefType;
 import org.apache.geronimo.j2ee.deployment.WebServiceBuilder;
+import org.apache.geronimo.deployment.util.UnpackedJarFile;
 
 /**
  */
@@ -20,10 +22,37 @@
     private JettyModuleBuilder builder = new JettyModuleBuilder(null, new Integer(1800),
null, jettyContainerObjectName, null, null, null, pojoWebServiceTemplate, webServiceBuilder,
null, null);
     private File basedir = new File(System.getProperty("basedir", "."));
 
-    public void testResourceRef() throws Exception {
+    public void testContents() throws Exception {
         File resourcePlan = new File(basedir, "src/test-resources/plans/plan1.xml");
         assertTrue(resourcePlan.exists());
         GerWebAppType jettyWebApp = builder.getJettyWebApp(resourcePlan, null, true, null,
null);
+        assertEquals(1, jettyWebApp.getResourceRefArray().length);
+        assertEquals(4, jettyWebApp.getSecurity().getRoleMappings().getRoleArray().length);
+    }
+
+    public void testOldFormat() throws Exception {
+        File resourcePlan = new File(basedir, "src/test-resources/plans/plan2.xml");
+        assertTrue(resourcePlan.exists());
+        GerWebAppType jettyWebApp = builder.getJettyWebApp(resourcePlan, null, true, null,
null);
+        assertEquals(1, jettyWebApp.getResourceRefArray().length);
+        assertEquals(4, jettyWebApp.getSecurity().getRoleMappings().getRoleArray().length);
+    }
+
+    public void testOldFormatExploded() throws Exception {
+        File war = new File(basedir, "src/test-resources/deployables/war5");
+        assertTrue(war.exists());
+        UnpackedJarFile moduleFile = new UnpackedJarFile(war);
+        GerWebAppType jettyWebApp = builder.getJettyWebApp(null, moduleFile, true, null,
null);
+        moduleFile.close();
+        assertEquals(1, jettyWebApp.getResourceRefArray().length);
+    }
+
+    public void testOldFormatPackaged() throws Exception {
+        File war = new File(basedir, "src/test-resources/deployables/war6.war");
+        assertTrue(war.exists());
+        JarFile moduleFile = new JarFile(war);
+        GerWebAppType jettyWebApp = builder.getJettyWebApp(null, moduleFile, true, null,
null);
+        moduleFile.close();
         assertEquals(1, jettyWebApp.getResourceRefArray().length);
     }
 



Mime
View raw message