Hi Colm,

thanks for the assistance and the quick reply. Here is the patch.

Indeed this seems to solve the problem for me or at least it is not observed
within several million transactions.

Thanks,
Chefo

On Fri, Sep 17, 2010 at 7:36 PM, Colm O hEigeartaigh <[email protected]>wrote:

> Hi,
>
> Submit a patch and I'll take a look at it. I wonder if explicitly
> nulling out the document after you're done with it would solve the
> problem?
>
> Colm.
>
> On Fri, Sep 17, 2010 at 2:08 PM, Chefo <[email protected]> wrote:
> > Hi guys,
> > I would like to suggest a tiny extension to the xmlsec java API, namely
> to
> > add a static method like unregisterDocument to
> > org.apache.xml.security.utils.IdResolver to remove adocument from the
> static
> > "docMap" WeakHashMap.
> > The reason behind this is the following: I'm using apache axis2 web
> service
> > implementation with its security module that uses wss4j and respectively
> > xmlsec. When set under stress (800+ signed SOAP transactions) after
> certain
> > period of time (5 - 10 minutes) the system hangs and all working threads
> are
> > in the following state:
> > "HTTP Handler 10.20.32.55" Id=185 in RUNNABLE
> >  at java.util.WeakHashMap.get(WeakHashMap.java:355)
> >  at org.apache.xml.security.utils.IdResolver.registerElementById(Unknown
> > Source)
> >  at org.apache.xml.security.signature.XMLSignature.setId(Unknown Source)
> >  at
> >
> org.apache.ws.security.message.WSSecSignature.prepare(WSSecSignature.java:360)
> >  at
> >
> org.apache.rampart.builder.BindingBuilder.getSignatureBuider(BindingBuilder.java:387)
> >  at
> >
> org.apache.rampart.builder.AsymmetricBindingBuilder.doSignature(AsymmetricBindingBuilder.java:716)
> >  at
> >
> org.apache.rampart.builder.AsymmetricBindingBuilder.doSignBeforeEncrypt(AsymmetricBindingBuilder.java:433)
> >  at
> >
> org.apache.rampart.builder.AsymmetricBindingBuilder.build(AsymmetricBindingBuilder.java:95)
> >  at org.apache.rampart.MessageBuilder.build(MessageBuilder.java:147)
> >  at
> org.apache.rampart.handler.RampartSender.invoke(RampartSender.java:79)
> >  at org.apache.axis2.engine.Phase.invoke(Phase.java:325)
> >  at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:264)
> >  at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:429)
> > ...
> > 100% cpu utilization, almost nothing processed. Sometimes the system
> > recovers a bit and than hangs again. The issue is observed on java 6
> only.
> > My wild guess is that the static weak hash map is filled faster than the
> gc
> > is cleaning it. I guess there is some way to tweak the gc in java 6 and
> get
> > over this but a simple method to remove registered dom document from the
> map
> > after the processing has finished does the job neatly.
> > I will submit a patch if you agree with the proposed extension.
> > Thanks in advance,
> > Chefo
>
Index: src/org/apache/xml/security/utils/IdResolver.java
===================================================================
--- src/org/apache/xml/security/utils/IdResolver.java   (revision 997314)
+++ src/org/apache/xml/security/utils/IdResolver.java   (working copy)
@@ -64,6 +64,7 @@
      * @param element the element to register
      * @param idValue the value of the ID attribute
      */
+    @SuppressWarnings({ "rawtypes", "unchecked" })
     public static void registerElementById(Element element, String idValue) {
         Document doc = element.getOwnerDocument();
         WeakHashMap elementMap;
@@ -76,6 +77,18 @@
         }
         elementMap.put(idValue, new WeakReference(element));
     }
+    
+    /**
+     * Force a removal of a registered document. Any element id associated
+     * with this document will be removed from the weak reference map.
+     * 
+     * @param doc the DOM document that is to be removed from the map.
+     */
+    public static void unregisterDocument(Document doc) {
+        synchronized (docMap) {
+            docMap.remove(doc);
+        }
+    }
 
     /**
      * Method registerElementById
@@ -149,6 +162,7 @@
      * @param id the value of the ID
      * @return the element obtained by the id, or null if it is not found.
      */
+    @SuppressWarnings("rawtypes")
     private static Element getElementByIdType(Document doc, String id) {
         if (log.isDebugEnabled())
            log.debug("getElementByIdType() Search for ID " + id);

Reply via email to