Skip to main content

[webtier] valve-patch

8 replies [Last post]
Anonymous

Hello,

the patches to enable valves with properties for the projects
"deployment" and "web" are in the attached files "deployment.diff" and
"web.diff". These patches are based on SVN-revision 24578.

I have also written a devtest "valveWithParams" though I do not know
whether it would be ok to send a valveWithParams.tgz as attachment to
this list. Please let me know how to submit this gzipped tar file.

I'm looking forward to getting your comments to these patches. It has
been fun digging into GlassFish's inner workings ;-)

--
Wolfram Rittmeyer

Property changes on: javaee-core
___________________________________________________________________
Added: svn:ignore
+ target

Index: dol/src/main/java/com/sun/enterprise/deployment/runtime/web/SunWebApp.java
===================================================================
--- dol/src/main/java/com/sun/enterprise/deployment/runtime/web/SunWebApp.java (revision 24578)
+++ dol/src/main/java/com/sun/enterprise/deployment/runtime/web/SunWebApp.java (working copy)
@@ -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,50 @@
}
return ret.booleanValue();
}
+
+ // This attribute is an array, possibly empty
+ public void setValve(int index, Valve value)
+ {
+ this.setValue(VALVE, index, value);
+ }
+
+ //
+ 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);
+ }
+
+ //
+ public Valve[] getValve()
+ {
+ return (Valve[])this.getValues(VALVE);
+ }
+
+ // Return the number of properties
+ 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
+ // Returns the index the element had in the list
+ //
+ public int removeValve(Valve value)
+ {
+ return this.removeValue(VALVE, value);
+ }
+
}
Index: dol/src/main/java/com/sun/enterprise/deployment/node/runtime/RuntimeDescriptorFactory.java
===================================================================
--- dol/src/main/java/com/sun/enterprise/deployment/node/runtime/RuntimeDescriptorFactory.java (revision 24578)
+++ dol/src/main/java/com/sun/enterprise/deployment/node/runtime/RuntimeDescriptorFactory.java (working copy)
@@ -108,6 +108,7 @@
//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.
Index: dol/src/main/java/com/sun/enterprise/deployment/node/runtime/web/WebBundleRuntimeNode.java
===================================================================
--- dol/src/main/java/com/sun/enterprise/deployment/node/runtime/web/WebBundleRuntimeNode.java (revision 24578)
+++ dol/src/main/java/com/sun/enterprise/deployment/node/runtime/web/WebBundleRuntimeNode.java (working copy)
@@ -131,6 +131,9 @@
MessageDestinationRuntimeNode.class);
registerElementHandler(new XMLElement(WebServicesTagNames.WEB_SERVICE),
WebServiceRuntimeNode.class);
+ registerElementHandler(new XMLElement(RuntimeTagNames.VALVE),
+ ValveNode.class);
+
}

/**
@@ -296,6 +299,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 +507,12 @@
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);

Index: dol/src/main/java/com/sun/enterprise/deployment/xml/RuntimeTagNames.java
===================================================================
--- dol/src/main/java/com/sun/enterprise/deployment/xml/RuntimeTagNames.java (revision 24578)
+++ dol/src/main/java/com/sun/enterprise/deployment/xml/RuntimeTagNames.java (working copy)
@@ -286,6 +286,9 @@
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";
+ public final static String CLASSNAME = "classname";

// Java Web Start-support related
public final static String JAVA_WEB_START_ACCESS = "java-web-start-access";
Index: dtds/src/main/resources/glassfish/lib/dtds/sun-web-app_2_5-0.dtd
===================================================================
--- dtds/src/main/resources/glassfish/lib/dtds/sun-web-app_2_5-0.dtd (revision 24578)
+++ dtds/src/main/resources/glassfish/lib/dtds/sun-web-app_2_5-0.dtd (working copy)
@@ -16,7 +16,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*)>

@@ -320,6 +320,9 @@
-->

+
+

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

WebModule</code< properties.
      */
     protected void configureCatalinaProperties(){
@@ -935,7 +954,71 @@
         }    
     }   
    
+    /**
+     * Add a <code>Valve
to a VirtualServer pipeline.
+ * @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.CLASSNAME);
+ if (valveName == null) {
+ logger.log(Level.WARNING, rb.getString("pewebcontainer.noNameForValve"));
+ return;
+ }
+ if (className == null) {
+ String msg = rb.getString("pewebcontainer.noClassnameForValve");
+ msg = MessageFormat.format(msg, new Object[] {valveName});
+ logger.log(Level.WARNING, msg);
+ return;
+ }
+ Object valve = loadInstance(className);
+ if (valve == null) {
+ 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("pewebcontainer.specifiedMethodMissing");
+ msg = MessageFormat.format(msg, new Object[] { propName,
+ valveName});
+ logger.log(Level.SEVERE, msg, ex);
+ } catch (Throwable t) {
+ String msg = rb.getString("pewebcontainer.valveSetterCausedException");
+ msg = MessageFormat.format(msg, new Object[] { propName,
+ valveName});
+ logger.log(Level.SEVERE, msg, t);
+ }
+ }
+ else {
+ String msg = rb.getString("pewebcontainer.noNameForProperty");
+ msg = MessageFormat.format(msg, new Object[] {valveName});
+ logger.log(Level.WARNING, msg);
+ return;
+ }
+ }
+ }
+ 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 " + className +
+ " not an instance of Valve or GlassFishValve");
+ }
+ }

+
+
/**
* Add a Catalina listener to a ContractProvider
* @param listenerName the fully qualified class name of the listener.
@@ -971,6 +1054,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: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
w.rittmeyer@jsptutorial.org

Oops. The classes com.sun.enterprise.deployment.node.runtime.web.ValveNode and com.sun.enterprise.deployment.runtime.web.Valve are missing (deployment). I will add them this evening (MEZ).

Sorry!

--
Wolfram Rittmeyer

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Wolfram Rittmeyer

w.rittmeyer@jsptutorial.org wrote:
> Oops. The classes com.sun.enterprise.deployment.node.runtime.web.ValveNode and com.sun.enterprise.deployment.runtime.web.Valve are missing (deployment). I will add them this evening (MEZ).
>

And finally these two classes ;-)

--
Wolfram Rittmeyer

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.CLASSNAME)) {
descriptor.setAttributeValue(Valve.CLASSNAME, value);
return true;
}
return false;
}

/**
* write the descriptor class to a DOM tree and return 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.CLASSNAME, (String) descriptor.getAttributeValue(Valve.CLASSNAME));

return valve;
}
}
package com.sun.enterprise.deployment.runtime.web;

public class Valve extends WebPropertyContainer {

static public final String CLASSNAME = "ClassName";

}
---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Jan Luehe

On 02/04/09 09:56, Wolfram Rittmeyer wrote:
> w.rittmeyer@jsptutorial.org wrote:
>> Oops. The classes
>> com.sun.enterprise.deployment.node.runtime.web.ValveNode and
>> com.sun.enterprise.deployment.runtime.web.Valve are missing
>> (deployment). I will add them this evening (MEZ).
>>
>
> And finally these two classes ;-)

Hi Wolfram,

congrats on your first web related GlassFish patch!

I've looked through your diffs and found no issues.
Great work!

I have a few minor comments which I am going to mail to you
tomorrow.

I'm glad you found digging through the GlassFish "inner workings"
a fun experience!

Thanks again for producing this patch!

Jan

>
> --
> Wolfram Rittmeyer
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net

[att1.html]

Jan Luehe

Hallo Wolfram,

On 02/04/09 20:33, Jan Luehe wrote:
> On 02/04/09 09:56, Wolfram Rittmeyer wrote:
>> w.rittmeyer@jsptutorial.org wrote:
>>> Oops. The classes
>>> com.sun.enterprise.deployment.node.runtime.web.ValveNode and
>>> com.sun.enterprise.deployment.runtime.web.Valve are missing
>>> (deployment). I will add them this evening (MEZ).
>>>
>>
>> And finally these two classes ;-)
>
> Hi Wolfram,
>
> congrats on your first web related GlassFish patch!
>
> I've looked through your diffs and found no issues.
> Great work!
>
> I have a few minor comments which I am going to mail to you
> tomorrow.

Please see attachments for my comments (each marked with "-> WOLFRAM").
Let me know what you think, and if you would like to incorporate them
into an
updated version of your patch.

Thanks also for providing a unit test case! To answer your question on
how to transfer it to us, why not attach it to the issue you filed:

https://glassfish.dev.java.net/issues/show_bug.cgi?id=4006
("Add more flexible configuration possibilies for Valves")

I could then pick it up from there.

Thanks!

Jan

[att1.html]
[web.diff]
[deployment.diff]
---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Wolfram Rittmeyer

Jan Luehe wrote:
> Hallo Wolfram,
>
(...)
>
> Please see attachments for my comments (each marked with "-> WOLFRAM").
> Let me know what you think, and if you would like to incorporate them
> into an
> updated version of your patch.
>

Hi Jan,

thanks for your detailed comments. Of course I would like to incorparate
them and provide an updated patch. Thanks to your detailed comments I
should be able to incorporate them shortly after the weekend. This
weekend I'm in Brussels at the FOSDEM - so I probably won't have much
time for this ;-)

> Thanks also for providing a unit test case! To answer your question on
> how to transfer it to us, why not attach it to the issue you filed:
>
> https://glassfish.dev.java.net/issues/show_bug.cgi?id=4006
> ("Add more flexible configuration possibilies for Valves")
>
> I could then pick it up from there.
>

I will do so, as soon as I have submitted the changed patch.

Thanks,

Wolfram

> Thanks!
>
> Jan
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Jan Luehe

On 02/05/09 13:47, Wolfram Rittmeyer wrote:
> Jan Luehe wrote:
>> Hallo Wolfram,
>>
> (...)
>>
>> Please see attachments for my comments (each marked with "-> WOLFRAM").
>> Let me know what you think, and if you would like to incorporate them
>> into an
>> updated version of your patch.
>>
>
> Hi Jan,
>
> thanks for your detailed comments. Of course I would like to
> incorparate them and provide an updated patch. Thanks to your detailed
> comments I should be able to incorporate them shortly after the
> weekend. This weekend I'm in Brussels at the FOSDEM - so I probably
> won't have much time for this ;-)
>
>> Thanks also for providing a unit test case! To answer your question on
>> how to transfer it to us, why not attach it to the issue you filed:
>>
>> https://glassfish.dev.java.net/issues/show_bug.cgi?id=4006
>> ("Add more flexible configuration possibilies for Valves")
>>
>> I could then pick it up from there.
>>
>
> I will do so, as soon as I have submitted the changed patch.

Sounds great, Wolfram!

I also realized that we should probably upgrade the version of the
sun-web.xml
DTD.

Traditionally, we've kept its version in sync with that of web.xml.

Therefore, I would suggest that we add support for to
sun-web-app_3_0-0.dtd instead of sun-web-app_2_5-0.dtd.

I will see what's involved in making this change and will let you know.

Looking forward to your updated diffs.

Thanks,

Jan

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Wolfram Rittmeyer

Jan Luehe wrote:
>
> I also realized that we should probably upgrade the version of the
> sun-web.xml
> DTD.
>
> Traditionally, we've kept its version in sync with that of web.xml.
>
> Therefore, I would suggest that we add support for to
> sun-web-app_3_0-0.dtd instead of sun-web-app_2_5-0.dtd.
>
> I will see what's involved in making this change and will let you know.
>

Hi Jan,

any news with regard to the DTD?

And while we're at it: Any word about the "writeDescriptor"-method in
WebBundleRuntimeNode? I think I have everything covered there. But I
still am curious if this method ever gets called - and if so, under what
circumstances.

Thanks,

--
Wolfram Rittmeyer

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Jan Luehe

Hi Wolfram,

On 02/10/09 11:38, Wolfram Rittmeyer wrote:
> Jan Luehe wrote:
>>
>> I also realized that we should probably upgrade the version of the
>> sun-web.xml
>> DTD.
>>
>> Traditionally, we've kept its version in sync with that of web.xml.
>>
>> Therefore, I would suggest that we add support for to
>> sun-web-app_3_0-0.dtd instead of sun-web-app_2_5-0.dtd.
>>
>> I will see what's involved in making this change and will let you know.
>>
>
> Hi Jan,
>
> any news with regard to the DTD?
>

I've created:

deployment/dtds/src/main/resources/glassfish/lib/dtds/sun-web-app_3_0-0.dtd

which right now is an exact copy of sun-web-app_2_5-0.dtd.

> And while we're at it: Any word about the "writeDescriptor"-method in
> WebBundleRuntimeNode? I think I have everything covered there. But I
> still am curious if this method ever gets called - and if so, under
> what circumstances.

Same here. :)

I've found that this method does not get called when I deploy a WAR that
contains a sun-web.xml,
restart the domain, and undeploy. I'm not sure under what other
circumstances it might get called,
or if it ever gets called. I'm not too familiar with that part of the
code. I would think that it is safe to
commit your changes to this file, even if they may never be triggered.
In the meantime, I'll do some
more digging around.

Thanks,

Jan

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net