Author: veithen
Date: Sat Jan 28 18:27:31 2012
New Revision: 1237134

URL: http://svn.apache.org/viewvc?rev=1237134&view=rev
Log:
AXIS-2863: Prevent the Oracle SAX parser (oracle.xml.parser.v2) from keeping a 
reference to DeserializationContext after the parser is released (actually 
until the parser is reused).

Added:
    
axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/utils/DefaultErrorHandler.java
   (with props)
Modified:
    
axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/encoding/DeserializationContext.java
    
axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/encoding/DeserializerImpl.java

Modified: 
axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/encoding/DeserializationContext.java
URL: 
http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/encoding/DeserializationContext.java?rev=1237134&r1=1237133&r2=1237134&view=diff
==============================================================================
--- 
axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/encoding/DeserializationContext.java
 (original)
+++ 
axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/encoding/DeserializationContext.java
 Sat Jan 28 18:27:31 2012
@@ -25,6 +25,8 @@ import org.apache.axis.constants.Use;
 import org.apache.axis.attachments.Attachments;
 import org.apache.axis.description.TypeDesc;
 import org.apache.axis.soap.SOAPConstants;
+import org.apache.axis.utils.DefaultEntityResolver;
+import org.apache.axis.utils.DefaultErrorHandler;
 import org.apache.axis.utils.NSStack;
 import org.apache.axis.utils.XMLUtils;
 import org.apache.axis.utils.JavaUtils;
@@ -42,12 +44,14 @@ import org.apache.axis.message.EnvelopeH
 import org.apache.axis.message.NullAttributes;
 import org.apache.commons.logging.Log;
 import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.DTDHandler;
 import org.xml.sax.SAXException;
 import org.xml.sax.Locator;
 import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
 import org.xml.sax.ext.LexicalHandler;
 import org.xml.sax.helpers.AttributesImpl;
-import org.xml.sax.helpers.DefaultHandler;
 
 import javax.xml.namespace.QName;
 import javax.xml.parsers.SAXParser;
@@ -62,8 +66,8 @@ import java.lang.reflect.Method;
  * an AXIS compliant DeserializationContext must extend the 
org.xml.sax.helpers.DefaultHandler.
  */
 
-public class DeserializationContext extends DefaultHandler
-        implements javax.xml.rpc.encoding.DeserializationContext, 
LexicalHandler {
+public class DeserializationContext implements ContentHandler, DTDHandler,
+        javax.xml.rpc.encoding.DeserializationContext, LexicalHandler {
     protected static Log log =
             LogFactory.getLog(DeserializationContext.class.getName());
 
@@ -223,12 +227,24 @@ public class DeserializationContext exte
         if (inputSource != null) {
             SAXParser parser = XMLUtils.getSAXParser();
             try {
-                
parser.setProperty("http://xml.org/sax/properties/lexical-handler";, this);
-                parser.parse(inputSource, this);
+                // We only set the DeserializationContext as ContentHandler 
and DTDHandler, but
+                // we use singletons for the EntityResolver and ErrorHandler. 
This reduces the risk
+                // that the SAX parser internally keeps a reference to the 
DeserializationContext
+                // after we release the parser. E.g. Oracle's SAX parser 
(oracle.xml.parser.v2) keeps a
+                // reference to the EntityResolver, although we reset the 
EntityResolver in
+                // XMLUtils#releaseSAXParser. That reference is only cleared 
when the parser is reused.
+                XMLReader reader = parser.getXMLReader();
+                reader.setContentHandler(this);
+                reader.setEntityResolver(DefaultEntityResolver.INSTANCE);
+                reader.setErrorHandler(DefaultErrorHandler.INSTANCE);
+                reader.setDTDHandler(this);
+                
+                
reader.setProperty("http://xml.org/sax/properties/lexical-handler";, this);
+                reader.parse(inputSource);
 
                 try {
                     // cleanup - so that the parser can be reused.
-                    
parser.setProperty("http://xml.org/sax/properties/lexical-handler";, 
nullLexicalHandler);
+                    
reader.setProperty("http://xml.org/sax/properties/lexical-handler";, 
nullLexicalHandler);
                 } catch (Exception e){
                     // Ignore.
                 }
@@ -1164,6 +1180,15 @@ public class DeserializationContext exte
         */
     }
 
+    public void notationDecl(String name, String publicId, String systemId) 
throws SAXException {
+        // Do nothing; we never get here
+    }
+
+    public void unparsedEntityDecl(String name, String publicId, String 
systemId,
+            String notationName) throws SAXException {
+        // Do nothing; we never get here
+    }
+
     public void endDTD()
             throws SAXException
     {
@@ -1208,12 +1233,6 @@ public class DeserializationContext exte
             recorder.comment(ch, start, length);
     }
 
-    public InputSource resolveEntity(String publicId, String systemId)
-    {
-        return XMLUtils.getEmptyInputSource();
-    }
-
-
     /** We only need one instance of this dummy handler to set into the 
parsers. */
     private static final NullLexicalHandler nullLexicalHandler = new 
NullLexicalHandler();
 

Modified: 
axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/encoding/DeserializerImpl.java
URL: 
http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/encoding/DeserializerImpl.java?rev=1237134&r1=1237133&r2=1237134&view=diff
==============================================================================
--- 
axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/encoding/DeserializerImpl.java
 (original)
+++ 
axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/encoding/DeserializerImpl.java
 Sat Jan 28 18:27:31 2012
@@ -29,7 +29,6 @@ import org.apache.axis.soap.SOAPConstant
 import org.apache.commons.logging.Log;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
 
 import javax.xml.namespace.QName;
 import java.io.StringWriter;
@@ -366,7 +365,7 @@ public class DeserializerImpl extends SO
 
                 SAX2EventRecorder r = context.getRecorder();
                 context.setRecorder(null);
-                ((MessageElement)ref).publishToHandler((DefaultHandler) 
context);
+                ((MessageElement)ref).publishToHandler(context);
                 context.setRecorder(r);
             } else {
 

Added: 
axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/utils/DefaultErrorHandler.java
URL: 
http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/utils/DefaultErrorHandler.java?rev=1237134&view=auto
==============================================================================
--- 
axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/utils/DefaultErrorHandler.java
 (added)
+++ 
axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/utils/DefaultErrorHandler.java
 Sat Jan 28 18:27:31 2012
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis.utils;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Default {@link ErrorHandler} implementation. The implementation is 
identical to
+ * {@link DefaultHandler}, i.e. {@link 
ErrorHandler#fatalError(SAXParseException)} throws the
+ * exception passed as parameter, while the other methods do nothing.
+ * 
+ * @author Andreas Veithen
+ */
+public class DefaultErrorHandler implements ErrorHandler {
+    /**
+     * The singleton instance.
+     */
+    public static final DefaultErrorHandler INSTANCE = new 
DefaultErrorHandler();
+    
+    private DefaultErrorHandler() {}
+
+    public void warning(SAXParseException exception) throws SAXException {
+    }
+
+    public void error(SAXParseException exception) throws SAXException {
+    }
+
+    public void fatalError(SAXParseException exception) throws SAXException {
+        throw exception;
+    }
+}

Propchange: 
axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/utils/DefaultErrorHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to