geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1459120 - in /geronimo/server/branches/2.1/plugins/tomcat: geronimo-tomcat6-builder/src/main/java/org/apache/geronimo/tomcat/deployment/ geronimo-tomcat6-builder/src/main/xsd/ geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/ gero...
Date Thu, 21 Mar 2013 01:27:46 GMT
Author: xuhaihong
Date: Thu Mar 21 01:27:46 2013
New Revision: 1459120

URL: http://svn.apache.org/r1459120
Log:
GERONIMO-6422 Enable usehttponly feature of tomcat in geronimo 2.1.x (Based on the patch from
XieZhi)

Modified:
    geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
    geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6-builder/src/main/xsd/geronimo-tomcat-2.0.1.xsd
    geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
    geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatContext.java
    geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
    geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java

Modified: geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java?rev=1459120&r1=1459119&r2=1459120&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
(original)
+++ geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
Thu Mar 21 01:27:46 2013
@@ -28,6 +28,7 @@ import java.net.URL;
 import java.security.PermissionCollection;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import java.util.jar.JarFile;
@@ -49,8 +50,8 @@ import org.apache.geronimo.gbean.Abstrac
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
-import org.apache.geronimo.gbean.ReferencePatterns;
 import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.geronimo.gbean.ReferencePatterns;
 import org.apache.geronimo.j2ee.deployment.EARContext;
 import org.apache.geronimo.j2ee.deployment.Module;
 import org.apache.geronimo.j2ee.deployment.ModuleBuilder;
@@ -78,6 +79,7 @@ import org.apache.geronimo.tomcat.util.S
 import org.apache.geronimo.web.deployment.GenericToSpecificPlanConverter;
 import org.apache.geronimo.web25.deployment.AbstractWebModuleBuilder;
 import org.apache.geronimo.xbeans.geronimo.j2ee.GerClusteringDocument;
+import org.apache.geronimo.xbeans.geronimo.web.tomcat.TomcatContextType;
 import org.apache.geronimo.xbeans.geronimo.web.tomcat.TomcatWebAppDocument;
 import org.apache.geronimo.xbeans.geronimo.web.tomcat.TomcatWebAppType;
 import org.apache.geronimo.xbeans.geronimo.web.tomcat.config.GerTomcatDocument;
@@ -99,6 +101,8 @@ import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlOptions;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
 
 /**
  * @version $Rev:385659 $ $Date$
@@ -110,6 +114,7 @@ public class TomcatModuleBuilder extends
     private static final String TOMCAT_NAMESPACE = TomcatWebAppDocument.type.getDocumentElementName().getNamespaceURI();
     private static final String IS_JAVAEE = "IS_JAVAEE";
     private static final Map<String, String> NAMESPACE_UPDATES = new HashMap<String,
String>();
+    private static final Set<String> INGORED_CONTEXT_ATTRIBUTE_NAMES = new HashSet<String>();
     static {
         NAMESPACE_UPDATES.put("http://geronimo.apache.org/xml/ns/web", "http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1");
         NAMESPACE_UPDATES.put("http://geronimo.apache.org/xml/ns/j2ee/web-1.1", "http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1");
@@ -285,7 +290,7 @@ public class TomcatModuleBuilder extends
                     rawPlan = (XmlObject) plan;
                 } else {
                     if (plan != null) {
-                        rawPlan = XmlBeansUtil.parse(((File) plan).toURL(), getClass().getClassLoader());
+                        rawPlan = XmlBeansUtil.parse(((File) plan).toURI().toURL(), getClass().getClassLoader());
                     } else {
                         URL path = DeploymentUtil.createJarURL(moduleFile, "WEB-INF/geronimo-web.xml");
                         try {
@@ -347,6 +352,7 @@ public class TomcatModuleBuilder extends
         configureBasicWebModuleAttributes(webApp, tomcatWebApp, moduleContext, earContext,
webModule, webModuleData);
         try {
             moduleContext.addGBean(webModuleData);
+            Map<String, String> contextAttributes = new HashMap<String, String>();
             Set<String> securityRoles = collectRoleNames(webApp);
             Map<String, PermissionCollection> rolePermissions = new HashMap<String,
PermissionCollection>();
             webModuleData.setAttribute("contextPath", webModule.getContextRoot());
@@ -367,14 +373,15 @@ public class TomcatModuleBuilder extends
                 webModuleData.setAttribute("virtualServer", virtualServer);
             }
             if (tomcatWebApp.isSetCrossContext()) {
-                webModuleData.setAttribute("crossContext", Boolean.TRUE);
+                //webModuleData.setAttribute("crossContext", Boolean.TRUE);
+                contextAttributes.put("crossContext", "true");
             }
             if (tomcatWebApp.isSetWorkDir()) {
                 String workDir = tomcatWebApp.getWorkDir();
-                webModuleData.setAttribute("workDir", workDir);
+                contextAttributes.put("workDir", workDir);
             }
             if (tomcatWebApp.isSetDisableCookies()) {
-                webModuleData.setAttribute("disableCookies", Boolean.TRUE);
+                contextAttributes.put("cookies", "false");
             }
             if (tomcatWebApp.isSetTomcatRealm()) {
                 String tomcatRealm = tomcatWebApp.getTomcatRealm().trim();
@@ -413,10 +420,42 @@ public class TomcatModuleBuilder extends
                 }
             }
 
+
+            //Add context attributes and parameters
+            if (tomcatWebApp.isSetContext()) {
+                TomcatContextType context = tomcatWebApp.getContext();
+                NamedNodeMap namedNodeMap = context.getDomNode().getAttributes();
+                for (int i = 0; i < namedNodeMap.getLength(); i++) {
+                    Node node = namedNodeMap.item(i);
+                    String attributeName = node.getNodeName();
+                    if (INGORED_CONTEXT_ATTRIBUTE_NAMES.contains(attributeName.toLowerCase()))
{
+                        if (log.isWarnEnabled()) {
+                            log.warn("Context attribute " + attributeName + " in the geronimo-web.xml
is ignored, as it is not support or Geronimo has already configured it");
+                        }
+                        continue;
+                    }
+                    if (contextAttributes.containsKey(attributeName)) {
+                        if (log.isWarnEnabled()) {
+                            log.warn("Context attribute " + attributeName
+                                    + " on the context element in geronimo-web.xml is ignored,
as it has been explicitly configured with other elements in the geronimo-web.xml file");
+                        }
+                        continue;
+                    }
+                    contextAttributes.put(node.getNodeName(), node.getNodeValue());
+                }
+
+            }
+            /**
+             * The old geronimo-web.xml also support to configure some context attributes
individually,
+             * let's override them in the contextAttributes
+             */
+
+            webModuleData.setAttribute("contextAttributes", contextAttributes);
+
             //Handle the role permissions and webservices on the servlets.
             ServletType[] servletTypes = webApp.getServletArray();
             Map<String, AbstractName> webServices = new HashMap<String, AbstractName>();
-            Class baseServletClass;
+            Class<?> baseServletClass;
             try {
                 baseServletClass = webClassLoader.loadClass(Servlet.class.getName());
             } catch (ClassNotFoundException e) {
@@ -429,7 +468,7 @@ public class TomcatModuleBuilder extends
                 if (servletType.isSetServletClass()) {
                     String servletName = servletType.getServletName().getStringValue().trim();
                     String servletClassName = servletType.getServletClass().getStringValue().trim();
-                    Class servletClass;
+                    Class<?> servletClass;
                     try {
                         servletClass = webClassLoader.loadClass(servletClassName);
                     } catch (ClassNotFoundException e) {

Modified: geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6-builder/src/main/xsd/geronimo-tomcat-2.0.1.xsd
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6-builder/src/main/xsd/geronimo-tomcat-2.0.1.xsd?rev=1459120&r1=1459119&r2=1459120&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6-builder/src/main/xsd/geronimo-tomcat-2.0.1.xsd
(original)
+++ geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6-builder/src/main/xsd/geronimo-tomcat-2.0.1.xsd
Thu Mar 21 01:27:46 2013
@@ -176,6 +176,15 @@
                     </xs:documentation>
                 </xs:annotation>
             </xs:element>
+            <xs:element name="context" type="tomcat:contextType" minOccurs="0">
+                <xs:annotation>
+                    <xs:documentation>
+                        The context element provides the same function as used in
+                        Tomcat, it supports context level attributes and context
+                        parameters.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:element>
             <xs:element name="valve-chain" type="xs:string" minOccurs="0">
                 <xs:annotation>
                     <xs:documentation>
@@ -271,5 +280,16 @@
     </xs:complexType>
 
     <xs:complexType name="emptyType" />
-
+    <xs:complexType name="contextType">        
+        <xs:sequence>
+            <xs:element name="parameter" type="tomcat:parameterType" minOccurs="0" maxOccurs="unbounded"/>
+        </xs:sequence>
+        <xs:anyAttribute processContents="skip"/>
+    </xs:complexType>
+    
+    <xs:complexType name="parameterType">        
+        <xs:attribute name="name" type="xs:string" />
+        <xs:attribute name="value" type="xs:string" />
+        <xs:attribute name="override" type="xs:boolean" default="false"/>
+    </xs:complexType>
 </xs:schema>

Modified: geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java?rev=1459120&r1=1459119&r2=1459120&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
(original)
+++ geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
Thu Mar 21 01:27:46 2013
@@ -56,6 +56,8 @@ import org.apache.geronimo.webservices.P
 import org.apache.geronimo.webservices.WebServiceContainer;
 import org.apache.geronimo.webservices.WebServiceContainerInvoker;
 
+import org.apache.tomcat.util.IntrospectionUtils;
+
 
 /**
  * @version $Rev$ $Date$
@@ -189,13 +191,20 @@ public class GeronimoStandardContext ext
         pipelineInitialized = true;
         this.webServiceMap = ctx.getWebServices();
 
-        this.setCrossContext(ctx.isCrossContext());
-
-        this.setWorkDir(ctx.getWorkDir());
+        Map<String, String> contextAttributes = ctx.getContextAttributes();
 
-        super.setAllowLinking(allowLinking);
+        if (!ctx.getContextAttributes().containsKey("allowLinking")) {
+            contextAttributes.put("allowLinking", String.valueOf(allowLinking));
+        }
 
-        this.setCookies(!ctx.isDisableCookies());
+        //Set context attributes via reflection
+        for (Map.Entry<String, String> entry : contextAttributes.entrySet()) {
+            if (!IntrospectionUtils.setProperty(this, entry.getKey(), entry.getValue()))
{
+                if (logger.isWarnEnabled()) {
+                    logger.warn("Fail to configure attribute " + entry.getKey() + " with
value " + entry.getValue() + ", please check whether the attribute exists or is typo correctly");
+                }
+            }
+        }
 
         //Set the Dispatch listener
         this.addInstanceListener("org.apache.geronimo.tomcat.listener.DispatchListener");

Modified: geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatContext.java?rev=1459120&r1=1459119&r2=1459120&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatContext.java
(original)
+++ geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatContext.java
Thu Mar 21 01:27:46 2013
@@ -70,6 +70,8 @@ public interface TomcatContext {
     
     List getLifecycleListenerChain();
 
+    Map<String, String> getContextAttributes();
+
     CatalinaCluster getCluster();
 
     Manager getManager();

Modified: geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java?rev=1459120&r1=1459119&r2=1459120&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
(original)
+++ geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
Thu Mar 21 01:27:46 2013
@@ -90,9 +90,6 @@ public class TomcatWebAppContext impleme
     private final List listenerChain;
     private final CatalinaCluster catalinaCluster;
     private final Manager manager;
-    private final boolean crossContext;
-    private final String workDir;
-    private final boolean disableCookies;
     private final UserTransaction userTransaction;
     private final javax.naming.Context componentContext;
     private final Kernel kernel;
@@ -108,7 +105,7 @@ public class TomcatWebAppContext impleme
     private final URL configurationBaseURL;
     private final Holder holder;
     private final RuntimeCustomizer contextCustomizer;
-
+    private Map<String,String> contextAttributes;
     // JSR 77
     private final String j2EEServer;
     private final String j2EEApplication;
@@ -139,12 +136,10 @@ public class TomcatWebAppContext impleme
             LifecycleListenerGBean lifecycleListenerChain,
             CatalinaClusterGBean cluster,
             ObjectRetriever managerRetriever,
-            boolean crossContext,
-            String workDir,
-            boolean disableCookies,
             Map webServices,
             Holder holder,
             RuntimeCustomizer contextCustomizer,
+            Map<String,String> contextAttributes,
             J2EEServer server,
             J2EEApplication application,
             Kernel kernel)
@@ -196,6 +191,7 @@ public class TomcatWebAppContext impleme
 
         this.holder = holder == null? new Holder(): holder;
         this.contextCustomizer = contextCustomizer;
+        this.contextAttributes = contextAttributes;
 
         if (tomcatRealm != null){
             realm = (Realm)tomcatRealm.getInternalObject();
@@ -246,12 +242,6 @@ public class TomcatWebAppContext impleme
             this.manager = null;
         }
 
-        this.crossContext = crossContext;
-        
-        this.workDir = workDir;
-
-        this.disableCookies = disableCookies;
-
         this.webServices = createWebServices(webServices, kernel);
 
         this.classLoader = classLoader;
@@ -359,7 +349,8 @@ public class TomcatWebAppContext impleme
     }
 
     public boolean isDisableCookies() {
-        return disableCookies;
+        String cookies = contextAttributes.get("cookies");
+        return cookies == null ? false : !Boolean.parseBoolean(cookies);
     }
 
     public Context getContext() {
@@ -420,11 +411,12 @@ public class TomcatWebAppContext impleme
     }
 
     public boolean isCrossContext() {
-        return crossContext;
+        String crossContext = contextAttributes.get("crossContext");
+        return crossContext == null ? false : Boolean.parseBoolean(crossContext);
     }
 
     public String getWorkDir() {
-        return workDir;
+        return contextAttributes.get("workDir");
     }
     
     public Map getWebServices(){
@@ -506,6 +498,10 @@ public class TomcatWebAppContext impleme
         reset = true;
     }
 
+    public Map<String, String> getContextAttributes() {
+        return contextAttributes;
+    }
+
     public void doStart() throws Exception {
 
         // See the note of TomcatContainer::addContext
@@ -575,12 +571,10 @@ public class TomcatWebAppContext impleme
         infoBuilder.addReference("LifecycleListenerChain", LifecycleListenerGBean.class,
LifecycleListenerGBean.J2EE_TYPE);
         infoBuilder.addReference("Cluster", CatalinaClusterGBean.class, CatalinaClusterGBean.J2EE_TYPE);
         infoBuilder.addReference(GBEAN_REF_MANAGER_RETRIEVER, ObjectRetriever.class);
-        infoBuilder.addAttribute("crossContext", boolean.class, true);
-        infoBuilder.addAttribute("workDir", String.class, true);
-        infoBuilder.addAttribute("disableCookies", boolean.class, true);
         infoBuilder.addAttribute("webServices", Map.class, true);
         infoBuilder.addAttribute("holder", Holder.class, true);
         infoBuilder.addReference("ContextCustomizer", RuntimeCustomizer.class, NameFactory.GERONIMO_SERVICE);
+        infoBuilder.addAttribute("contextAttributes", Map.class, true);
         infoBuilder.addReference("J2EEServer", J2EEServer.class);
         infoBuilder.addReference("J2EEApplication", J2EEApplication.class);
         infoBuilder.addAttribute("kernel", Kernel.class, false);
@@ -607,12 +601,10 @@ public class TomcatWebAppContext impleme
                 "LifecycleListenerChain",
                 "Cluster",
                 GBEAN_REF_MANAGER_RETRIEVER,
-                "crossContext",
-                "workDir",
-                "disableCookies",
                 "webServices",
                 "holder",
                 "ContextCustomizer",
+                "contextAttributes",
                 "J2EEServer",
                 "J2EEApplication",
                 "kernel"

Modified: geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java?rev=1459120&r1=1459119&r2=1459120&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
(original)
+++ geronimo/server/branches/2.1/plugins/tomcat/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
Thu Mar 21 01:27:46 2013
@@ -89,12 +89,10 @@ public abstract class AbstractWebModuleT
                 null,
                 null,
                 null,
-                false,
-                null,
-                false,
                 null,
                 null,
                 null,
+                new HashMap<String, String>(),
                 null,
                 null,
                 null);



Mime
View raw message