webtier@glassfish.java.net

Re: [webtier] revised valve-patch

From: Jan Luehe <Jan.Luehe_at_Sun.COM>
Date: Fri, 13 Feb 2009 10:59:17 -0800

Hi Wolfram,

> Your patch looks just perfect!
>
> I was able to apply your diffs just fine.
>
> I have sent the DOL related changes to the deployment lead (Hong
> Zhang), so she gets a chance to review them also before I commit them
> on your behalf.

You got the green light from Hong as well. :)
This was her comment:

    The changes look really good, I am actually a little surprised to see
    that he made all the necessary changes in one round. :-)

I've filed a new issue that is specific to valve support in sun-web.xml,
see:

  https://glassfish.dev.java.net/issues/show_bug.cgi?id=7177
  ("Add valve configuration support to sun-web.xml")

and cross-linked it with the domain.xml related issue that you had
originally filed, see:

  https://glassfish.dev.java.net/issues/show_bug.cgi?id=4006

I just committed your changes under IT 7177 (see commit notification below),
and reassigned the issue to docs, so that the new and improved configuration
approach can be documented, and the old one deprecated.

Again, congrats on your patch! Very nice work!

Jan


-------- Original Message --------
Subject: svn commit: r24777 - trunk/v3:
deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime
deployment/dol/src/main/java/com/sun/enterpr...
Date: Fri, 13 Feb 2009 18:42:20 +0000
From: jluehe_at_dev.java.net
Reply-To: commits_at_glassfish-svn.dev.java.net
To: commits_at_glassfish-svn.dev.java.net



Author: jluehe
Date: 2009-02-13 18:42:18+0000
New Revision: 24777

Added:
   trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/web/ValveNode.java
   trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/runtime/web/Valve.java
Modified:
   trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/RuntimeDescriptorFactory.java
   trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/web/WebBundleRuntimeNode.java
   trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/runtime/web/SunWebApp.java
   trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/xml/DTDRegistry.java
   trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/xml/RuntimeTagNames.java
   trunk/v3/deployment/dtds/src/main/resources/glassfish/lib/dtds/sun-web-app_3_0-0.dtd
   trunk/v3/web/war-util/src/main/resources/com/sun/logging/enterprise/system/container/web/LogStrings.properties
   trunk/v3/web/web-glue/src/main/java/com/sun/enterprise/web/WebModule.java

Log:
Fix for https://glassfish.dev.java.net/issues/show_bug.cgi?id=7177 ("Add valve configuration support to sun-web.xml")

Patch provided by: writtmeyer

Reviewed by: jluehe, hzhang_jn

Tests run: QL

Modified: trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/RuntimeDescriptorFactory.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/RuntimeDescriptorFactory.java?view=diff&rev=24777&p1=trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/RuntimeDescriptorFactory.java&p2=trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/RuntimeDescriptorFactory.java&r1=24776&r2=24777
==============================================================================
--- trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/RuntimeDescriptorFactory.java (original)
+++ trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/RuntimeDescriptorFactory.java 2009-02-13 18:42:18+0000
@@ -108,7 +108,9 @@
         //common
         register(new XMLElement(RuntimeTagNames.PRINCIPAL_NAME), PrincipalNameDescriptor.class);
         register(new XMLElement(RuntimeTagNames.SECURITY_ROLE_MAPPING), SecurityRoleMapping.class);
- }
+ register(new XMLElement(RuntimeTagNames.VALVE), Valve.class);
+ }
+
     /**
      * register a new descriptor class handling a particular XPATH in the DTD.
      *

Added: trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/web/ValveNode.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/web/ValveNode.java?view=auto&rev=24777
==============================================================================
--- (empty file)
+++ trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/web/ValveNode.java 2009-02-13 18:42:18+0000
@@ -0,0 +1,102 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License"). You
+ * may not use this file except in compliance with the License. You can obtain
+ * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [year]
+ * [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license." If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above. However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+
+package com.sun.enterprise.deployment.node.runtime.web;
+
+import com.sun.enterprise.deployment.node.XMLElement;
+import com.sun.enterprise.deployment.runtime.web.Valve;
+import com.sun.enterprise.deployment.runtime.web.WebProperty;
+import com.sun.enterprise.deployment.xml.RuntimeTagNames;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Node representing a valve tag.
+ */
+public class ValveNode extends WebRuntimeNode {
+
+ public ValveNode() {
+ registerElementHandler(new XMLElement(RuntimeTagNames.PROPERTY),
+ WebPropertyNode.class, "addWebProperty");
+ }
+
+ @Override
+ protected boolean setAttributeValue(XMLElement elementName,
+ XMLElement attributeName,
+ String value) {
+ Valve descriptor = (Valve) getRuntimeDescriptor();
+ if (descriptor == null) {
+ throw new RuntimeException("Trying to set values on a null descriptor");
+ }
+ if (attributeName.getQName().equals(RuntimeTagNames.NAME)) {
+ descriptor.setAttributeValue(Valve.NAME, value);
+ return true;
+ } else if (attributeName.getQName().equals(RuntimeTagNames.CLASS_NAME)) {
+ descriptor.setAttributeValue(Valve.CLASS_NAME, value);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Writes the descriptor class to a DOM tree and returns it
+ *
+ * @param parent node for the DOM tree
+ * @param node name
+ * @param the descriptor to write
+ * @return the DOM tree top node
+ */
+ public Node writeDescriptor(Node parent, String nodeName,
+ Valve descriptor) {
+
+ Element valve = (Element) super.writeDescriptor(
+ parent, nodeName, descriptor);
+
+ WebPropertyNode wpn = new WebPropertyNode();
+
+ // sub-element property*
+ wpn.writeDescriptor(valve, RuntimeTagNames.PROPERTY,
+ descriptor.getWebProperty());
+
+ // attributes classname and name
+ setAttribute(valve, RuntimeTagNames.NAME,
+ (String) descriptor.getAttributeValue(Valve.NAME));
+ setAttribute(valve, RuntimeTagNames.CLASS_NAME,
+ (String) descriptor.getAttributeValue(Valve.CLASS_NAME));
+
+ return valve;
+ }
+}

Modified: trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/web/WebBundleRuntimeNode.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/web/WebBundleRuntimeNode.java?view=diff&rev=24777&p1=trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/web/WebBundleRuntimeNode.java&p2=trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/web/WebBundleRuntimeNode.java&r1=24776&r2=24777
==============================================================================
--- trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/web/WebBundleRuntimeNode.java (original)
+++ trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/runtime/web/WebBundleRuntimeNode.java 2009-02-13 18:42:18+0000
@@ -131,6 +131,9 @@
                                 MessageDestinationRuntimeNode.class);
         registerElementHandler(new XMLElement(WebServicesTagNames.WEB_SERVICE),
                                      WebServiceRuntimeNode.class);
+ registerElementHandler(new XMLElement(RuntimeTagNames.VALVE),
+ ValveNode.class);
+
     }
     
     /**
@@ -144,15 +147,15 @@
      * @return the DOCTYPE that should be written to the XML file
      */
     public String getDocType() {
- return DTDRegistry.SUN_WEBAPP_250_DTD_PUBLIC_ID;
+ return DTDRegistry.SUN_WEBAPP_300_DTD_PUBLIC_ID;
     }
     
     /**
      * @return the SystemID of the XML file
      */
     public String getSystemID() {
- return DTDRegistry.SUN_WEBAPP_250_DTD_SYSTEM_ID;
- }
+ return DTDRegistry.SUN_WEBAPP_300_DTD_SYSTEM_ID;
+ }
 
     /**
      * @return NULL for all runtime nodes.
@@ -173,6 +176,7 @@
        publicIDToDTD.put(DTDRegistry.SUN_WEBAPP_240_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_240_DTD_SYSTEM_ID);
        publicIDToDTD.put(DTDRegistry.SUN_WEBAPP_241_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_241_DTD_SYSTEM_ID);
        publicIDToDTD.put(DTDRegistry.SUN_WEBAPP_250_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_250_DTD_SYSTEM_ID);
+ publicIDToDTD.put(DTDRegistry.SUN_WEBAPP_300_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_300_DTD_SYSTEM_ID);
        if (!restrictDTDDeclarations()) {
           publicIDToDTD.put(DTDRegistry.SUN_WEBAPP_240beta_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_240beta_DTD_SYSTEM_ID);
        }
@@ -296,6 +300,9 @@
         } else if (newDescriptor instanceof WebProperty) {
             descriptor.getSunDescriptor().addWebProperty(
                 (WebProperty)newDescriptor);
+ } else if (newDescriptor instanceof Valve) {
+ descriptor.getSunDescriptor().addValve(
+ (Valve)newDescriptor);
         }
         else super.addDescriptor(descriptor);
     }
@@ -501,6 +508,13 @@
             props.writeDescriptor(web, RuntimeTagNames.PROPERTY, sunWebApp.getWebProperty());
         }
         
+ // valve*
+ if (sunWebApp.getValve()!=null) {
+ ValveNode valve = new ValveNode();
+ valve.writeDescriptor(web, RuntimeTagNames.VALVE,
+ sunWebApp.getValve());
+ }
+
         // message-destination*
         RuntimeDescriptorNode.writeMessageDestinationInfo(web, bundleDescriptor);
 

Modified: trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/runtime/web/SunWebApp.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/runtime/web/SunWebApp.java?view=diff&rev=24777&p1=trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/runtime/web/SunWebApp.java&p2=trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/runtime/web/SunWebApp.java&r1=24776&r2=24777
==============================================================================
--- trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/runtime/web/SunWebApp.java (original)
+++ trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/runtime/web/SunWebApp.java 2009-02-13 18:42:18+0000
@@ -62,7 +62,7 @@
     public static final String IDEMPOTENT_URL_PATTERN = "IdempotentUrlPattern";
     public static final String ERROR_URL = "ErrorUrl";
     public static final String HTTPSERVLET_SECURITY_PROVIDER = "HttpServletSecurityProvider";
-
+ public static final String VALVE = "Valve";
     
     public SunWebApp()
     {
@@ -424,4 +424,40 @@
         }
         return ret.booleanValue();
     }
+
+ // This attribute is a valve to be added at the specified index
+ public void setValve(int index, Valve value) {
+ this.setValue(VALVE, index, value);
+ }
+
+ // The return value is the valve at the specified index
+ public Valve getValve(int index) {
+ return (Valve)this.getValue(VALVE, index);
+ }
+
+ // This attribute is an array, possibly empty
+ public void setValve(Valve[] value) {
+ this.setValue(VALVE, value);
+ }
+
+ // This return value is an array, possibly empty
+ public Valve[] getValve() {
+ return (Valve[])this.getValues(VALVE);
+ }
+
+ // Return the number of valves
+ public int sizeValve() {
+ return this.size(VALVE);
+ }
+
+ // Add a new element returning its index in the list
+ public int addValve(Valve value) {
+ return this.addValue(VALVE, value);
+ }
+
+ // Remove an element using its reference
+ public int removeValve(Valve value) {
+ return this.removeValue(VALVE, value);
+ }
+
 }

Added: trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/runtime/web/Valve.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/runtime/web/Valve.java?view=auto&rev=24777
==============================================================================
--- (empty file)
+++ trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/runtime/web/Valve.java 2009-02-13 18:42:18+0000
@@ -0,0 +1,44 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License"). You
+ * may not use this file except in compliance with the License. You can obtain
+ * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [year]
+ * [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license." If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above. However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+
+package com.sun.enterprise.deployment.runtime.web;
+
+public class Valve extends WebPropertyContainer {
+
+ static public final String CLASS_NAME = "ClassName";
+
+}
+

Modified: trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/xml/DTDRegistry.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/xml/DTDRegistry.java?view=diff&rev=24777&p1=trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/xml/DTDRegistry.java&p2=trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/xml/DTDRegistry.java&r1=24776&r2=24777
==============================================================================
--- trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/xml/DTDRegistry.java (original)
+++ trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/xml/DTDRegistry.java 2009-02-13 18:42:18+0000
@@ -223,6 +223,10 @@
     public static final String SUN_WEBAPP_250_DTD_SYSTEM_ID =
         "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd";
     
+ public static final String SUN_WEBAPP_300_DTD_PUBLIC_ID =
+ "-//Sun Microsystems, Inc.//DTD GlassFish v3 Servlet 3.0//EN";
+ public static final String SUN_WEBAPP_300_DTD_SYSTEM_ID =
+ "http://www.sun.com/software/appserver/dtds/sun-web-app_3_0-0.dtd";
     
     /**
      * Application Client Container: Sun ONE App Server specific dtd info.

Modified: trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/xml/RuntimeTagNames.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/xml/RuntimeTagNames.java?view=diff&rev=24777&p1=trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/xml/RuntimeTagNames.java&p2=trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/xml/RuntimeTagNames.java&r1=24776&r2=24777
==============================================================================
--- trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/xml/RuntimeTagNames.java (original)
+++ trunk/v3/deployment/dol/src/main/java/com/sun/enterprise/deployment/xml/RuntimeTagNames.java 2009-02-13 18:42:18+0000
@@ -286,6 +286,8 @@
     public static final String JAVA_METHOD = "java-method";
     public final static String METHOD_PARAMS = "method-params";
     public final static String METHOD_PARAM = "method-param";
+
+ public final static String VALVE = "valve";
     
     // Java Web Start-support related
     public final static String JAVA_WEB_START_ACCESS = "java-web-start-access";

Modified: trunk/v3/deployment/dtds/src/main/resources/glassfish/lib/dtds/sun-web-app_3_0-0.dtd
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/deployment/dtds/src/main/resources/glassfish/lib/dtds/sun-web-app_3_0-0.dtd?view=diff&rev=24777&p1=trunk/v3/deployment/dtds/src/main/resources/glassfish/lib/dtds/sun-web-app_3_0-0.dtd&p2=trunk/v3/deployment/dtds/src/main/resources/glassfish/lib/dtds/sun-web-app_3_0-0.dtd&r1=24776&r2=24777
==============================================================================
--- trunk/v3/deployment/dtds/src/main/resources/glassfish/lib/dtds/sun-web-app_3_0-0.dtd (original)
+++ trunk/v3/deployment/dtds/src/main/resources/glassfish/lib/dtds/sun-web-app_3_0-0.dtd 2009-02-13 18:42:18+0000
@@ -17,7 +17,7 @@
                        ejb-ref*, resource-ref*, resource-env-ref*, service-ref*,
                        message-destination-ref*, cache?, class-loader?,
                        jsp-config?, locale-charset-info?, parameter-encoding?,
- property*, message-destination*, webservice-description*)>
+ property*, valve*, message-destination*, webservice-description*)>
 <!ATTLIST sun-web-app error-url CDATA ""
                       httpservlet-security-provider CDATA #IMPLIED>
 
@@ -321,6 +321,9 @@
 -->
 <!ELEMENT value (#PCDATA)>
 
+<!ELEMENT valve (description?, property*)>
+<!ATTLIST valve name CDATA #REQUIRED
+ class-name CDATA #REQUIRED>
 
 <!--
                                           W E B S E R V I C E S

Modified: trunk/v3/web/war-util/src/main/resources/com/sun/logging/enterprise/system/container/web/LogStrings.properties
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/web/war-util/src/main/resources/com/sun/logging/enterprise/system/container/web/LogStrings.properties?view=diff&rev=24777&p1=trunk/v3/web/war-util/src/main/resources/com/sun/logging/enterprise/system/container/web/LogStrings.properties&p2=trunk/v3/web/war-util/src/main/resources/com/sun/logging/enterprise/system/container/web/LogStrings.properties&r1=24776&r2=24777
==============================================================================
--- trunk/v3/web/war-util/src/main/resources/com/sun/logging/enterprise/system/container/web/LogStrings.properties (original)
+++ trunk/v3/web/war-util/src/main/resources/com/sun/logging/enterprise/system/container/web/LogStrings.properties 2009-02-13 18:42:18+0000
@@ -221,6 +221,12 @@
 webmodule.alternateDocBase.illegalUrlPattern=WEB0504: URL pattern {0} for alternate docbase is invalid
 webmodule.alternateDocBase.crlfInUrlPattern=WEB0505: URL pattern {0} for alternate docbase contains CR or LF or both
 webmodule.noservercontext=WEB0506: No ServerContext in WebModule [{0}]
+webmodule.valve.specifiedMethodMissing=No method [{0}(java.lang.String)] defined on valve [{1}] of web module [{2}]
+webmodule.valve.setterCausedException=Exception during execution of method [{0}] on valve [{1}] of web module [{2}]
+webmodule.valve.missingName=Web module [{0}] has a valve without any name
+webmodule.valve.missingClassname=Valve [{0}] of web module [{1}] has no class name
+webmodule.valve.missingPropertyName=Valve [{0}] of web module [{1}] has a property without any name
+webmodule.valve.classNameNoValve=Object of type {0} not an instance of Valve or GlassFishValve
 
 webModuleContextConfig.webModuleDisabled=WEB0600: WebModule [{0}] failed to deploy and has been disabled
 webModuleContextConfig.missingDefaultWeb.xml=WEB0601: Missing default web.xml, using application web.xml only

Modified: trunk/v3/web/web-glue/src/main/java/com/sun/enterprise/web/WebModule.java
Url: https://glassfish-svn.dev.java.net/source/browse/glassfish-svn/trunk/v3/web/web-glue/src/main/java/com/sun/enterprise/web/WebModule.java?view=diff&rev=24777&p1=trunk/v3/web/web-glue/src/main/java/com/sun/enterprise/web/WebModule.java&p2=trunk/v3/web/web-glue/src/main/java/com/sun/enterprise/web/WebModule.java&r1=24776&r2=24777
==============================================================================
--- trunk/v3/web/web-glue/src/main/java/com/sun/enterprise/web/WebModule.java (original)
+++ trunk/v3/web/web-glue/src/main/java/com/sun/enterprise/web/WebModule.java 2009-02-13 18:42:18+0000
@@ -85,6 +85,8 @@
 import com.sun.enterprise.web.session.PersistenceType;
 import com.sun.enterprise.web.session.SessionCookieConfig;
 import com.sun.logging.LogDomains;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import org.apache.catalina.Container;
 import org.apache.catalina.ContainerListener;
 import org.apache.catalina.InstanceListener;
@@ -468,10 +470,9 @@
         // Configure catalina listeners and valves. This can only happen
         // after this web module has been started, in order to be able to
         // load the specified listener and valve classes.
+ configureValves();
         configureCatalinaProperties();
-
         webModuleStartedEvent();
-
         hasStarted = true;
     }
 
@@ -871,6 +872,20 @@
     }
     
    
+
+ /**
+ * Configure the <code>WebModule</code> valves.
+ */
+ protected void configureValves(){
+ if (iasBean.getValve() != null && iasBean.sizeValve() > 0) {
+ com.sun.enterprise.deployment.runtime.web.Valve[] valves = iasBean.getValve();
+ for (com.sun.enterprise.deployment.runtime.web.Valve valve: valves) {
+ addValve(valve);
+ }
+ }
+
+ }
+
     /**
      * Configure the <code>WebModule</code< properties.
      */
@@ -921,22 +936,99 @@
     
 
     /**
- * Add a <code>Valve</code> to a <code>VirtualServer</code> pipeline.
- * @param valveName the fully qualified class name of the Valve.
+ * Instantiates a <tt>Valve</tt> from the given <tt>className</tt>
+ * and adds it to the <tt>Pipeline</tt> of this WebModule.
+ *
+ * @param className the fully qualified class name of the <tt>Valve</tt>
      */
- protected void addValve(String valveName) {
- Object valve = loadInstance(valveName);
+ protected void addValve(String className) {
+ Object valve = loadInstance(className);
         if (valve instanceof Valve) {
             super.addValve((Valve) valve);
         } else if (valve instanceof GlassFishValve) {
             super.addValve((GlassFishValve) valve);
         } else {
- logger.log(Level.WARNING,
- "Object of type classname " + valveName +
- " not an instance of Valve or GlassFishValve");
+ logger.log(Level.WARNING, "webmodule.valve.classNameNoValve",
+ className);
         }
     }
     
+ /**
+ * Constructs a <tt>Valve</tt> from the given <tt>valveDescriptor</tt>
+ * and adds it to the <tt>Pipeline</tt> of this WebModule.
+ * @param valveDescriptor the object containing the information to
+ * create the valve.
+ */
+ protected void addValve(com.sun.enterprise.deployment.runtime.web.Valve valveDescriptor) {
+ String valveName = valveDescriptor.getAttributeValue(
+ com.sun.enterprise.deployment.runtime.web.Valve.NAME);
+ String className = valveDescriptor.getAttributeValue(
+ com.sun.enterprise.deployment.runtime.web.Valve.CLASS_NAME);
+ if (valveName == null) {
+ logger.log(Level.WARNING, "webmodule.valve.missingName",
+ getName());
+ return;
+ }
+ if (className == null) {
+ logger.log(Level.WARNING, "webmodule.valve.missingClassname",
+ new Object[]{valveName, getName()});
+ return;
+ }
+ Object valve = loadInstance(className);
+ if (valve == null) {
+ return;
+ }
+ if (!(valve instanceof GlassFishValve) &&
+ !(valve instanceof Valve)) {
+ logger.log(Level.WARNING, "webmodule.valve.classNameNoValve",
+ className);
+ return;
+ }
+ WebProperty[] props = valveDescriptor.getWebProperty();
+ if (props != null && props.length > 0) {
+ for (WebProperty property: props) {
+ String propName = getSetterName(
+ property.getAttributeValue(WebProperty.NAME));
+ if (propName != null && propName.length() != 0) {
+ String value = property.getAttributeValue(
+ WebProperty.VALUE);
+ try {
+ Method method = valve.getClass().getMethod(
+ propName, String.class);
+ method.invoke(valve, value);
+ } catch (NoSuchMethodException ex) {
+ String msg = rb.getString(
+ "webmodule.valve.specifiedMethodMissing");
+ msg = MessageFormat.format(msg,
+ new Object[] { propName, valveName, getName()});
+ logger.log(Level.SEVERE, msg, ex);
+ } catch (Throwable t) {
+ String msg = rb.getString(
+ "webmodule.valve.setterCausedException");
+ msg = MessageFormat.format(msg,
+ new Object[] { propName, valveName, getName()});
+ logger.log(Level.SEVERE, msg, t);
+ }
+ }
+ else {
+ String msg = rb.getString(
+ "webmodule.valve.missingPropertyName");
+ msg = MessageFormat.format(msg, new Object[] {valveName});
+ logger.log(Level.WARNING,
+ "webmodule.valve.missingPropertyName",
+ new Object[]{valveName, getName()});
+ return;
+ }
+ }
+ }
+ if (valve instanceof Valve) {
+ super.addValve((Valve) valve);
+ } else if (valve instanceof GlassFishValve) {
+ super.addValve((GlassFishValve) valve);
+ }
+ }
+
+
     
     /**
      * Add a Catalina listener to a <code>ContractProvider</code>
@@ -973,6 +1065,19 @@
         return null;
     }
 
+
+ private String getSetterName(String propName) {
+ if (propName != null) {
+ if (propName.length() > 1) {
+ propName = "set" + Character.toUpperCase(propName.charAt(0)) +
+ propName.substring(1);
+ }
+ else {
+ propName = "set" + Character.toUpperCase(propName.charAt(0));
+ }
+ }
+ return propName;
+ }
     
     public com.sun.enterprise.config.serverbeans.WebModule getBean() {
         return bean;

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe_at_glassfish-svn.dev.java.net
For additional commands, e-mail: commits-help_at_glassfish-svn.dev.java.net