axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James M Snell" <jasn...@us.ibm.com>
Subject RE: cvs commit: xml-axis/java/test/encoding TestDeser.java TestHr efs.java TestSer.java TestString.java
Date Wed, 23 May 2001 19:00:26 GMT
Agreed.  Boot the incremental parse out of 1.0. 

- James Snell
     Software Engineer, Emerging Technologies, IBM
     jasnell@us.ibm.com (online)
     jsnell@lemoorenet.com (offline)

Please respond to axis-dev@xml.apache.org 
To:     "'axis-dev@xml.apache.org'" <axis-dev@xml.apache.org>
cc: 
Subject:        RE: cvs commit: xml-axis/java/test/encoding TestDeser.java TestHr efs.java

TestSer.java TestString.java



As it stands right now, we are not doing any incremental parsing, and
haven't been for a while.  The capability is still in there, but we use 
the
regular SAXAdapter instead of the ThreadedSAXAdapter by default.

So we're using SAX, but parsing the whole message.

If we do want to do the incremental stuff, we should either a) decide that
threads are OK, and obtain them from "outside" (potentially an app-server
thread pool), or b) decide on a pull parsing model, and forget about JAXP.
The latter will involve including some pull parser with the Axis
distribution.  I suppose there's some middle ground where a config 
parameter
can switch on/off the incremental parsing (and therefore the use of the 
pull
parser)....

I'm personally leaning towards treating the incremental/pull parsing model
as a fairly low-priority item for 1.0.  There's a lot of other stuff that 
we
need to finish that seems much more important, and there are also other 
ways
to get similar functionality (for instance, we might tee the input stream 
to
the SAX parser and also to a stub which lets us pick it up as an 
InputStream
at any point).

What do you think?

--Glen

> -----Original Message-----
> From: James M Snell [mailto:jasnell@us.ibm.com]
> Sent: Wednesday, May 23, 2001 1:01 PM
> To: axis-dev@xml.apache.org
> Subject: Re: cvs commit: xml-axis/java/test/encoding TestDeser.java
> TestHrefs.java TestSer.java TestString.java
>
>
> Glen,
>
> Ok, next question:  using JAXP, how do we do the incremental
> parse without
> using a separate thread?  We need to figure out the multiple
> thread issue
> before we can hope to deploy this in most Web Application Server
> environments.
>
> - James Snell
>      Software Engineer, Emerging Technologies, IBM
>      jasnell@us.ibm.com (online)
>      jsnell@lemoorenet.com (offline)
>
> Please respond to axis-dev@xml.apache.org
> To:     xml-axis-cvs@apache.org
> cc:
> Subject:        cvs commit: xml-axis/java/test/encoding
> TestDeser.java TestHrefs.java
> TestSer.java TestString.java
>
>
>
> gdaniels    01/05/23 09:15:46
>
>   Modified:    java/samples/encoding TestSer.java
>                java/src/org/apache/axis Message.java
>                java/src/org/apache/axis/message SAXAdapter.java
>                         ThreadedSAXAdapter.java
>                java/src/org/apache/axis/utils XMLUtils.java
>                java/test/encoding TestDeser.java TestHrefs.java
>                         TestSer.java TestString.java
>   Log:
>   JAXP!
>
>   Remove all Xerces dependencies, and start using JAXP.  JAXP version
>   1.1 is required (for SAX-2 support).
>
>   The main changes are in XMLUtils, SAXAdapter, and
> ThreadedSAXAdapter.
>   The external interface to the SAXAdapters no longer takes a
> parser, so
>   it's easier to use them.
>
>   XMLUtils now does all of its XML serialization using JAXP
> Transformers,
> which
>   I'm assuming is the right way to do it - any JAXP experts out there?
>
>   Revision  Changes    Path
>   1.7       +1 -2      xml-axis/java/samples/encoding/TestSer.java
>
>   Index: TestSer.java
>   ===================================================================
>   RCS file: /home/cvs/xml-axis/java/samples/encoding/TestSer.java,v
>   retrieving revision 1.6
>   retrieving revision 1.7
>   diff -u -r1.6 -r1.7
>   --- TestSer.java      2001/05/22 18:42:27     1.6
>   +++ TestSer.java      2001/05/23 16:14:50     1.7
>   @@ -5,7 +5,6 @@
>    import org.apache.axis.encoding.*;
>    import org.apache.axis.utils.QName;
>    import org.xml.sax.InputSource;
>   -import org.apache.xerces.parsers.SAXParser;
>    import java.io.*;
>    import java.util.*;
>
>   @@ -67,7 +66,7 @@
>                TypeMappingRegistry reg =
> msgContext.getTypeMappingRegistry();
>                reg.addDeserializerFactory(dataQName, Data.class,
> DataSer.getFactory());
>
>   -            SAXAdapter adapter = new SAXAdapter(new
> SAXParser(), new
> InputSource(reader), msgContext);
>   +            SAXAdapter adapter = new SAXAdapter(new
> InputSource(reader), msgContext);
>                SOAPEnvelope env = adapter.getEnvelope();
>                env.setMessageType(ServiceDescription.REQUEST);
>
>
>
>
>   1.32      +1 -5      xml-axis/java/src/org/apache/axis/Message.java
>
>   Index: Message.java
>   ===================================================================
>   RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/Message.java,v
>   retrieving revision 1.31
>   retrieving revision 1.32
>   diff -u -r1.31 -r1.32
>   --- Message.java      2001/05/06 15:57:20     1.31
>   +++ Message.java      2001/05/23 16:14:59     1.32
>   @@ -329,13 +329,9 @@
>          is = new InputSource(new StringReader(getAsString()));
>        }
>
>   -    // ThreadedSAXAdapter parser =
>   -    //    new ThreadedSAXAdapter(new
> org.apache.xerces.parsers.SAXParser(), is);
>        if (msgContext == null)
>            msgContext = new MessageContext();
>   -    SAXAdapter parser =
>   -        new SAXAdapter(new
> org.apache.xerces.parsers.SAXParser(), is,
>   -                       msgContext);
>   +    SAXAdapter parser = new SAXAdapter(is, msgContext);
>        SOAPEnvelope env = parser.getEnvelope();
>        env.setMessageType(messageType);
>
>
>
>
>   1.4       +8 -7
> xml-axis/java/src/org/apache/axis/message/SAXAdapter.java
>
>   Index: SAXAdapter.java
>   ===================================================================
>   RCS file:
> /home/cvs/xml-axis/java/src/org/apache/axis/message/SAXAdapter.java,v
>   retrieving revision 1.3
>   retrieving revision 1.4
>   diff -u -r1.3 -r1.4
>   --- SAXAdapter.java   2001/05/05 16:48:33     1.3
>   +++ SAXAdapter.java   2001/05/23 16:15:06     1.4
>   @@ -1,7 +1,10 @@
>    package org.apache.axis.message;
>
>   -import org.xml.sax.*;
>   +import org.xml.sax.InputSource;
>   +import org.xml.sax.SAXException;
>    import org.apache.axis.MessageContext;
>   +import org.apache.axis.utils.XMLUtils;
>   +import javax.xml.parsers.*;
>
>    /** This class is an adapter for the Axis SAX-event system
>     * which uses a SAX parser to parse on its own thread,
> synchronizing
>   @@ -12,16 +15,14 @@
>    public class SAXAdapter extends SOAPSAXHandler
>    {
>        private static final boolean DEBUG_LOG = false;
>   -    private XMLReader _parser;
>   +    private SAXParser _parser;
>        InputSource inputSource;
>
>   -    public SAXAdapter(XMLReader parser, InputSource inputSource,
>   +    public SAXAdapter(InputSource inputSource,
>                          MessageContext msgContext)
>        {
>            super(msgContext);
>   -        _parser = new org.apache.xerces.parsers.SAXParser();
>   -        _parser.setContentHandler(this);
>   -
>   +        _parser = XMLUtils.getSAXParser();
>            this.inputSource = inputSource;
>        }
>
>   @@ -31,7 +32,7 @@
>        public void parse()
>        {
>          try {
>   -        _parser.parse(inputSource);
>   +        _parser.parse(inputSource, this);
>          } catch (Exception e) {
>            e.printStackTrace();
>          }
>
>
>
>   1.4       +6 -8
> xml-axis/java/src/org/apache/axis/message/ThreadedSAXAdapter.java
>
>   Index: ThreadedSAXAdapter.java
>   ===================================================================
>   RCS file:
> /home/cvs/xml-axis/java/src/org/apache/axis/message/ThreadedSA
> XAdapter.java,v
>   retrieving revision 1.3
>   retrieving revision 1.4
>   diff -u -r1.3 -r1.4
>   --- ThreadedSAXAdapter.java   2001/05/05 16:48:33     1.3
>   +++ ThreadedSAXAdapter.java   2001/05/23 16:15:10     1.4
>   @@ -2,6 +2,8 @@
>
>    import org.xml.sax.*;
>    import org.apache.axis.MessageContext;
>   +import org.apache.axis.utils.XMLUtils;
>   +import javax.xml.parsers.SAXParser;
>
>    /** This class is an adapter for the Axis SAX-event system
>     * which uses a SAX parser to parse on its own thread,
> synchronizing
>   @@ -15,7 +17,7 @@
>
>        private Object _semaphore = new Object();
>
>   -    private XMLReader _parser;
>   +    private SAXParser _parser;
>        InputSource inputSource;
>
>        private Thread parseThread = null;
>   @@ -29,7 +31,7 @@
>            public void run()
>            {
>                try {
>   -                _parser.parse(inputSource);
>   +                _parser.parse(inputSource,
> ThreadedSAXAdapter.this);
>                } catch (Exception e) {
>                    e.printStackTrace();
>                }
>   @@ -46,15 +48,11 @@
>            }
>        }
>
>   -    public ThreadedSAXAdapter(XMLReader parser, InputSource
> inputSource,
>   +    public ThreadedSAXAdapter(InputSource inputSource,
>                                  MessageContext msgContext)
>        {
>            super(msgContext);
>   -        _parser = new org.apache.xerces.parsers.SAXParser();
>   -        _parser.setContentHandler(this);
>   -        //elementHandler = new SAXOutputter(new
> PrintWriter(System.out));
>   -        //_parser.setContentHandler(new SAXOutputter(new
> PrintWriter(System.out)));
>   -
>   +        _parser = XMLUtils.getSAXParser();
>            this.inputSource = inputSource;
>        }
>
>
>
>
>   1.7       +81 -36
> xml-axis/java/src/org/apache/axis/utils/XMLUtils.java
>
>   Index: XMLUtils.java
>   ===================================================================
>   RCS file:
> /home/cvs/xml-axis/java/src/org/apache/axis/utils/XMLUtils.java,v
>   retrieving revision 1.6
>   retrieving revision 1.7
>   diff -u -r1.6 -r1.7
>   --- XMLUtils.java     2001/05/22 21:27:13     1.6
>   +++ XMLUtils.java     2001/05/23 16:15:19     1.7
>   @@ -58,13 +58,43 @@
>    import java.io.* ;
>    import org.w3c.dom.* ;
>    import javax.xml.parsers.* ;
>   -import org.apache.xml.serialize.* ;
>   +import javax.xml.transform.*;
>   +import javax.xml.transform.dom.*;
>   +import javax.xml.transform.stream.*;
>    import org.xml.sax.* ;
>    import org.apache.axis.Constants;
>
>    public class XMLUtils {
>      private static DocumentBuilder        db  ;
>      private static DocumentBuilderFactory dbf = init();
>   +  private static SAXParserFactory       saxFactory;
>   +
>   +  static {
>   +    // Initialize SAX Parser factory defaults
>   +    initSAXFactory(null, true, false);
>   +  }
>   +
>   +  /** Initialize the SAX parser factory.
>   +   *
>   +   * @param factoryClassName The class name of the desired
> SAXParserFactory
>   +   *                         implementation.  Will be
> assigned to the
> system
>   +   *                         property
> <b>javax.xml.parsers.SAXParserFactory</b>.
>   +   * @param namespaceAware true if we want a
> namespace-aware parser
> (which we do)
>   +   * @param validating true if we want a validating parser
>   +   *
>   +   */
>   +  public static void initSAXFactory(String factoryClassName,
>   +                                     boolean namespaceAware,
>   +                                     boolean validating)
>   +  {
>   +      if (factoryClassName != null) {
>   +        System.setProperty("javax.xml.parsers.SAXParserFactory",
>   +                           factoryClassName);
>   +      }
>   +      saxFactory = SAXParserFactory.newInstance();
>   +      saxFactory.setNamespaceAware(namespaceAware);
>   +      saxFactory.setValidating(validating);
>   +  }
>
>      public static DocumentBuilderFactory init() {
>        Document               doc = null ;
>   @@ -79,6 +109,24 @@
>        }
>        return( dbf );
>      }
>   +
>   +  /** Get a SAX parser instance from the JAXP factory.
>   +   *
>   +   * @return a SAXParser instance.
>   +   */
>   +  public static SAXParser getSAXParser() {
>   +    // Might want to cache the parser (on a per-thread basis, as I
> don't think
>   +    // SAX parsers are thread-safe)...
>   +    try {
>   +      return saxFactory.newSAXParser();
>   +    } catch (ParserConfigurationException e) {
>   +      e.printStackTrace();
>   +      return null;
>   +    } catch (SAXException se) {
>   +      se.printStackTrace();
>   +      return null;
>   +    }
>   +  }
>
>      public static Document newDocument() {
>        return( db.newDocument() );
>   @@ -114,44 +162,41 @@
>        }
>      }
>
>   +  /** Obtain a JAXP Transformer.
>   +   *
>   +   * (I'm assuming that using the transformer API is the accepted
> JAXP-style
>   +   *  way to do XML serialization)
>   +   *
>   +   * @return a JAXP Transformer
>   +   */
>   +  public static Transformer getTransformer()
>   +  {
>   +      try {
>   +          TransformerFactory factory =
> TransformerFactory.newInstance();
>   +          return factory.newTransformer();
>   +      } catch (TransformerConfigurationException e) {
>   +          e.printStackTrace();
>   +          return null;
>   +      }
>   +  }
>   +
>      public static String DocumentToString(Document doc) {
>   -    try {
>   -      StringWriter sw     = new StringWriter();
>   -      OutputFormat format = new OutputFormat();
>   -      format.setPreserveSpace(true);
>   -      XMLSerializer  xs = new XMLSerializer( sw, format );
>   -      xs.serialize( (Document) doc );
>   -      sw.close();
>   -      return(sw.toString() );
>   -    }
>   -    catch( Exception e ) {
>   -      e.printStackTrace();
>   -    }
>   -    return( null );
>   +      return ElementToString(doc.getDocumentElement());
>      }
>
>      public static void DocumentToStream(Document doc,
> OutputStream out) {
>   -    try {
>   -      OutputFormat format = new OutputFormat();
>   -      format.setPreserveSpace(true);
>   -      XMLSerializer  xs = new XMLSerializer( out, format );
>   -      xs.serialize( (Document) doc );
>   -    }
>   -    catch( Exception e ) {
>   -      e.printStackTrace();
>   -    }
>   +      ElementToStream(doc.getDocumentElement(), out);
>      }
>
>      public static String ElementToString(Element element) {
>          try {
>   -          StringWriter sw = new StringWriter();
>   -          OutputFormat format = new OutputFormat();
>   -          format.setPreserveSpace(true);
>   -          format.setOmitXMLDeclaration(true);
>   -          XMLSerializer xs = new XMLSerializer(sw, format);
>   -          xs.serialize((Element)element);
>   -          sw.close();
>   -          return(sw.toString() );
>   +        StringWriter sw = new StringWriter();
>   +        DOMSource source = new DOMSource(element);
>   +        StreamResult result = new StreamResult(sw);
>   +        Transformer transformer = getTransformer();
>   +        transformer.transform(source, result);
>   +        sw.close();
>   +        return sw.toString();
>          }
>          catch( Exception e) {
>              e.printStackTrace();
>   @@ -161,14 +206,14 @@
>
>      public static void ElementToStream(Element element,
> OutputStream out)
> {
>        try {
>   -      OutputFormat format = new OutputFormat();
>   -      format.setPreserveSpace(true);
>   -      XMLSerializer  xs = new XMLSerializer( out, format );
>   -      xs.serialize((Element)element);
>   +      Transformer transformer = getTransformer();
>   +      DOMSource source = new DOMSource(element);
>   +      StreamResult result = new StreamResult(out);
>   +      transformer.transform(source, result);
>        }
>        catch( Exception e ) {
>          e.printStackTrace();
>   -    }
>   +    }
>      }
>
>      public static String getInnerXMLString(Element element) {
>
>
>
>   1.7       +0 -1      xml-axis/java/test/encoding/TestDeser.java
>
>   Index: TestDeser.java
>   ===================================================================
>   RCS file: /home/cvs/xml-axis/java/test/encoding/TestDeser.java,v
>   retrieving revision 1.6
>   retrieving revision 1.7
>   diff -u -r1.6 -r1.7
>   --- TestDeser.java    2001/05/20 22:14:06     1.6
>   +++ TestDeser.java    2001/05/23 16:15:27     1.7
>   @@ -8,7 +8,6 @@
>    import org.apache.axis.encoding.*;
>    import org.apache.axis.utils.QName;
>    import org.xml.sax.InputSource;
>   -import org.apache.xerces.parsers.SAXParser;
>    import java.io.*;
>    import java.util.*;
>
>
>
>
>   1.4       +0 -1      xml-axis/java/test/encoding/TestHrefs.java
>
>   Index: TestHrefs.java
>   ===================================================================
>   RCS file: /home/cvs/xml-axis/java/test/encoding/TestHrefs.java,v
>   retrieving revision 1.3
>   retrieving revision 1.4
>   diff -u -r1.3 -r1.4
>   --- TestHrefs.java    2001/05/21 21:03:51     1.3
>   +++ TestHrefs.java    2001/05/23 16:15:29     1.4
>   @@ -7,7 +7,6 @@
>    import org.apache.axis.encoding.*;
>    import org.apache.axis.utils.QName;
>    import org.xml.sax.InputSource;
>   -import org.apache.xerces.parsers.SAXParser;
>    import java.io.*;
>    import java.util.*;
>
>
>
>
>   1.4       +1 -2      xml-axis/java/test/encoding/TestSer.java
>
>   Index: TestSer.java
>   ===================================================================
>   RCS file: /home/cvs/xml-axis/java/test/encoding/TestSer.java,v
>   retrieving revision 1.3
>   retrieving revision 1.4
>   diff -u -r1.3 -r1.4
>   --- TestSer.java      2001/05/05 16:48:33     1.3
>   +++ TestSer.java      2001/05/23 16:15:32     1.4
>   @@ -5,7 +5,6 @@
>    import org.apache.axis.encoding.*;
>    import org.apache.axis.utils.QName;
>    import org.xml.sax.InputSource;
>   -import org.apache.xerces.parsers.SAXParser;
>    import java.io.*;
>    import java.util.*;
>
>   @@ -48,7 +47,7 @@
>
>            StringReader reader = new StringReader(msgString);
>
>   -        SAXAdapter adapter = new SAXAdapter(new SAXParser(), new
> InputSource(reader), msgContext);
>   +        SAXAdapter adapter = new SAXAdapter(new
> InputSource(reader),
> msgContext);
>            reg = adapter.getContext().getTypeMappingRegistry();
>            reg.addDeserializerFactory(dataQName, Data.class,
> DataSer.getFactory());
>
>
>
>
>   1.3       +1 -2      xml-axis/java/test/encoding/TestString.java
>
>   Index: TestString.java
>   ===================================================================
>   RCS file: /home/cvs/xml-axis/java/test/encoding/TestString.java,v
>   retrieving revision 1.2
>   retrieving revision 1.3
>   diff -u -r1.2 -r1.3
>   --- TestString.java   2001/05/05 16:48:33     1.2
>   +++ TestString.java   2001/05/23 16:15:34     1.3
>   @@ -5,7 +5,6 @@
>    import org.apache.axis.encoding.*;
>    import org.apache.axis.utils.QName;
>    import org.xml.sax.InputSource;
>   -import org.apache.xerces.parsers.SAXParser;
>    import java.io.*;
>    import java.util.*;
>
>   @@ -38,7 +37,7 @@
>
>            StringReader reader = new StringReader(msgString);
>
>   -        SAXAdapter adapter = new SAXAdapter(new SAXParser(), new
> InputSource(reader), msgContext);
>   +        SAXAdapter adapter = new SAXAdapter(new
> InputSource(reader),
> msgContext);
>            SOAPEnvelope env = adapter.getEnvelope();
>            RPCElement rpcElem = (RPCElement)env.getFirstBody();
>            RPCParam output = rpcElem.getParam("testParam");
>
>
>
>
> 



Mime
View raw message