Uploaded image for project: 'Axis2'
  1. Axis2
  2. AXIS2-1570

Rampart/Axiom is not thread safe

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 1.0
    • None
    • modules
    • None
    • WinXP, Tomcat 4/5, Websphere 5/6

    Description

      The Axiom DOM (distributed with Axis 1.0) implementation seems to have some threading issues.

      The problem manifests itself as a nullpointer exception in org.apache.axiom.om.impl.dom.jaxp.DocumentBuilderFactoryImpl

      If I apply a moderate amount of load on the server so the number of http processor threads start increase the NPE will
      happen all of the time whenever a piece of code tries to create a DocumentBuilder (for instance the WSDL parsing during deployment).
      I can reproduce this problem quite reliably.

      Nullpointer is caused by the originalDocumentBuilderFactory being null
      — snip —
      public DocumentBuilder newDocumentBuilder()
      throws ParserConfigurationException

      { /** * Determine which DocumentBuilder implementation should be returned */ return isDOOMRequired() ? new DocumentBuilderImpl() : originalDocumentBuilderFactory.newDocumentBuilder(); }

      — snip —

      I've tracked the problem to this piece of code in the org.apache.axiom.om.impl.dom.jaxp.DocumentBuilderFactoryImpl

      — snip —
      public static void setDOOMRequired(boolean isDOOMRequired) {
      String systemKey = DocumentBuilderFactory.class.getName();
      if (isDOOMRequired) {
      if (!isDOOMRequired())

      { originalDocumentBuilderFactory = DocumentBuilderFactory.newInstance(); originalDocumentBuilderFactoryClassName = originalDocumentBuilderFactory.getClass().getName(); documentBuilderFactoryTracker.set(Boolean.TRUE); System.setProperty(systemKey, DocumentBuilderFactoryImpl.class.getName()); }

      } else {
      String currentFactoryClassName = DocumentBuilderFactory.newInstance().getClass().getName();
      if (currentFactoryClassName != null && currentFactoryClassName.equals(DocumentBuilderFactoryImpl.class.getName())) {
      System.getProperties().remove(systemKey);
      if (originalDocumentBuilderFactoryClassName != null)

      { System.setProperty(DocumentBuilderFactory.class.getName(), originalDocumentBuilderFactoryClassName); }

      }
      documentBuilderFactoryTracker.set(null);
      originalDocumentBuilderFactory = null;
      }
      }
      — snip —

      Trying to find away to resolve this I realise that the DOOM document builder factory implementation is in fact manipulating a JVM-wide
      system property in a multi-threaded environment which besides the problem I am currently experiencing could lead to all sorts
      of unwanted side-effects.

      As I don't want to allow this to happen I simply commented out the contents of the setDoomRequired() method hoping that Rampart could work
      with my default DOM instead and that I would only suffer some performance loss.

      I was wrong in that assumption as I encountered another problem:

      StAXOMBuilder CHARACTERS: [org.apache.axis2.AxisFault: WSDoAllReceiver: security processing failed; nested exception is:
      org.apache.ws.security.WSSecurityException: Cannot encrypt/decrypt data; nested exception is:
      org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.
      at org.apache.axis2.security.WSDoAllReceiver.processMessage(WSDoAllReceiver.java:183)
      at org.apache.axis2.security.handler.WSDoAllHandler.invoke(WSDoAllHandler.java:82)
      at org.apache.axis2.engine.Phase.invoke(Phase.java:381)
      at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:473)
      at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:445)
      at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:284)
      at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:157)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)

      I compared the source of org.apache.axiom.om.impl.dom.jaxp.DocumentBuilderFactoryImpl in Axis 1.0 release and the latest in SVN
      http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/jaxp/DocumentBuilderFactoryImpl.java?view=markup
      and can see no changes in how this is handled.

      Attachments

        Issue Links

          Activity

            People

              ruchith Ruchith B. Gunaratne
              ander Johan Andersson
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: