You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by gd...@apache.org on 2001/08/08 20:49:00 UTC

cvs commit: xml-axis/java/src/org/apache/axis/utils Debug.java

gdaniels    01/08/08 11:49:00

  Modified:    java/docs user-guide.html
               java/samples/userguide/example4 LogHandler.java
               java/src/org/apache/axis AxisEngine.java AxisFault.java
                        Constants.java
               java/src/org/apache/axis/encoding SerializationContext.java
               java/src/org/apache/axis/message MessageElement.java
                        SOAPFaultElement.java
               java/src/org/apache/axis/utils Debug.java
  Added:       java/samples/userguide/example4 Client.java Service.java
                        deploy.xml
  Log:
  * Make AxisFault put the stack trace correctly into a <stacktrace>
    element inside <details>.
  
  * Move serializing DOM elements into the SerializationContext itself,
    so it's more useful from outside MessageElement.
  
  * Don't set the Debug level from the properties file value if it's already
    been specified on the command line.
  
  * Add constant QNames for the fault elements so we don't create them
    every time
  
  * Flesh out example 4 for the user's guide
  
  * More user's guide edits (almost there!)
  
  Revision  Changes    Path
  1.8       +51 -45    xml-axis/java/docs/user-guide.html
  
  Index: user-guide.html
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/docs/user-guide.html,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- user-guide.html	2001/08/07 20:05:19	1.7
  +++ user-guide.html	2001/08/08 18:48:59	1.8
  @@ -29,10 +29,6 @@
     <A href="#DeploymentReference">Deployment Reference</a><br>
     <A href="#Glossary">Glossary</a></p>
   <h2><a name="Introduction"></a>Introduction</h2>
  -<ul>
  -  <li>Bugzilla link</li>
  -  <li>ServiceDescription desc.</li>
  -</ul>
   <p>Welcome to Axis! This is the <b>alpha 1</b> version, our first publically annouced 
     milestone. Please note that this is a work in progress, and although the basic 
     functionality is there, there are still a lot of unfinished areas and rough 
  @@ -51,26 +47,26 @@
     manner. This system is the result of months of continued discussion and coding 
     effort in this direction. Some of the key Axis features include the following:</p>
   <ul>
  -  <li> Speed. Axis uses SAX (event-based) parsing to acheive 
  -  significantly greater speed than earlier versions of Apache SOAP. 
  -  <li>Flexibility. The Axis architecture gives the 
  -  developer complete freedom to insert extensions into the engine for custom 
  -  header processing, system management, or anything else you can imagine. 
  -  <li>Component-oriented deployment. You can easily define 
  -  reusable networks of Handlers to implement common patterns of processing for 
  -  your applications, or to distribute to partners. 
  -  <li>Transport framework. We have a clean and simple 
  -  abstraction for designing transports (i.e. senders and listeners for SOAP over 
  -  various protocols such as SMTP, FTP, message-oriented middleware, etc), and 
  -  the core of the engine is completely transport-independent. 
  -  <li>...</li>
  +  <li> Speed. Axis uses SAX (event-based) parsing to acheive significantly greater 
  +    speed than earlier versions of Apache SOAP. 
  +  <li>Flexibility. The Axis architecture gives the developer complete freedom 
  +    to insert extensions into the engine for custom header processing, system 
  +    management, or anything else you can imagine. 
  +  <li>Component-oriented deployment. You can easily define reusable networks of 
  +    Handlers to implement common patterns of processing for your applications, 
  +    or to distribute to partners. 
  +  <li>Transport framework. We have a clean and simple abstraction for designing 
  +    transports (i.e. senders and listeners for SOAP over various protocols such 
  +    as SMTP, FTP, message-oriented middleware, etc), and the core of the engine 
  +    is completely transport-independent. 
   </ul>
   <p>We hope you enjoy using Axis, and please note that this is an open-source effort 
     - if you feel the code could use some new features or fixes, please get involved 
     and lend a hand! The Axis developer community would welcome your participation.</p>
  -<p><b>Let us know what you think!</b> Please send feedback about the package to 
  -  "<A href="mailto:axis-dev@xml.apache.org">axis-dev@xml.apache.org</a>" 
  -</p>
  +<h4><b>Let us know what you think!</b></h4>
  +<p>Please send feedback about the package to "<A href="mailto:axis-dev@xml.apache.org">axis-dev@xml.apache.org</a>". 
  +  Also, Axis is regsitered in <a href="http://nagoya.apache.org/bugzilla">bugzilla</a>, 
  +  the Apache bug tracking and feature-request database.</p>
   <h3>What is SOAP?</h3>
   <p>SOAP is an XML<i>-</i>based communitcation protocol and encoding format for 
     inter-application communication. Originally conceived by Microsoft and Userland 
  @@ -104,10 +100,11 @@
   <h3>What's missing?</h3>
   <ul>
     <li>Support for the SOAP with Attachments specification 
  -  <li>Supprt for multi-dimensional and &quot;sparse&quot; arrays
  +  <li>Supprt for multi-dimensional and &quot;sparse&quot; arrays 
     <li>A final deployment descriptor syntax (WSDD)</li>
  -  <li>...</li>
  +  <li>WSDL tooling</li>
   </ul>
  +<p>All of these items are on the list for the final release.</p>
   <h2><a name="Installation"></a>Installing Axis and Using this Guide</h2>
   <p>See the <a href="install.html">Axis Installation Guide</a> for instructions 
     on installing Axis as a webapp on your J2EE server. </p>
  @@ -231,7 +228,7 @@
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
     &lt;SOAP-ENV:Body&gt;
       &lt;ns1:echoStringResponse xmlns:ns1="http://soapinterop.org/"&gt;
  -      &lt;result&gt;Hello!&lt;/result&gt;
  +      &lt;result&gt;Hello, I'm a string!&lt;/result&gt;
       &lt;/ns1:echoStringResponse&gt;
     &lt;/SOAP-ENV:Body&gt;
   &lt;/SOAP-ENV:Envelope&gt;</div></pre>
  @@ -242,7 +239,7 @@
     side in Axis:</p>
   <div class="example">
     <pre>  ServiceDescription sd = new ServiceDescription(&quot;name&quot;, true);
  -  sd.setOutputType(new QName(Constants.SCHEMA_URI, &quot;string&quot;));
  +  sd.setOutputType(new QName(Constants.URI_2001_SCHEMA_XSD, &quot;string&quot;));
     client.setServiceDescription(sd);</pre>
   </div>
   <p>The ServiceDescription constructor takes a name (can be anything) and a boolean 
  @@ -250,7 +247,8 @@
     it is, so we use &quot;true&quot;. Then we call &quot;setOutputType()&quot;, 
     which tells the ServiceDescription that if the return element is not typed, 
     act as if the return value has an xsi:type attribute set to the QName which 
  -  we supply.</p>
  +  we supply. (you can see an example of this in action in the interop echo-test 
  +  client - samples/echo/TestClient.java)</p>
   <p>OK - so now you know the basics of accessing SOAP services as a client. But 
     how do you publish your own services?</p>
   <h2><a name="PublishingServices"></a>Publishing Web Services with Axis</h2>
  @@ -359,10 +357,10 @@
    &lt;/handler&gt;
   
    &lt;!-- define the service, using the log handler we just defined --&gt;
  - &lt;service name="MyService" <b>request="track"</b> pivot="RPCDispatcher"&gt;
  -  &lt;option name="className" value="samples.log.Service"/&gt;
  + &lt;service name="LogTestService" <b>request="track"</b> pivot="RPCDispatcher"&gt;
  +  &lt;option name="className" value="samples.userguide.example4.Service"/&gt;
     &lt;option name="methodName" value="*"/&gt;
  -&lt;/service&gt;
  + &lt;/service&gt;
   &lt;/admin:deploy&gt;</pre>
   <p>The first section defines a Handler called "track" which is implemented 
     by the class "samples.log.LogHandler". We give this Handler an option 
  @@ -502,23 +500,31 @@
   <h2>Pre-Configured Axis Components Reference</h2>
   <h3>On the server:</h3>
   <dl> 
  -  <dt><b>LogHandler</b>
  -  <dd>The LogHandler will simply log a message to a logger 
  -  when it gets invoked. 
  -  <dt>
  -  <dt><b>EchoHandler</b>
  -  <dd>The EchoHandler copies the request message into the 
  -  response message. 
  -  <dt>
  -  <dt><b>RPCDispatcher</b>
  -  <dd>The RPCDispatcher is the pivot point for all RPC 
  -  services. It accepts the following options: 
  -  <dt>
  -  <dt><b>MsgDispatcher</b>
  -  <dd>The MsgDispatcher is the pivot point for all 
  -  messaging services. It accepts the following options: 
  -  <dt>
  -  <dt><b>LocalResponder</b>
  +  <dt><b>LogHandler</b> 
  +  <dd>The LogHandler will simply log a message to a logger when it gets invoked. 
  +  <dt> 
  +  <dt><b>EchoHandler</b> 
  +  <dd>The EchoHandler copies the request message into the response message. 
  +  <dt> 
  +  <dt><b>RPCDispatcher</b> 
  +  <dd>The RPCDispatcher is the pivot point for all RPC services. It accepts the 
  +    following options: <br>
  +    <b><i>className</i></b> = the class of the backend object to invoke<br>
  +    <b><i>methodName</i></b> = a space-separated list of methods which are exported 
  +    as web services. The special value &quot;*&quot; matches all public methods 
  +    in the class.
  +  <dt> 
  +  <dt><b>MsgDispatcher</b> 
  +  <dd>The MsgDispatcher is the pivot point for all messaging services. It accepts 
  +    the following options: <br>
  +  <dd><b><i>className</i></b> = the class of the backend object to invoke<br>
  +    <b><i>methodName</i></b> = a space-separated list of methods which are exported 
  +    as web services. The special value &quot;*&quot; matches all public methods 
  +    in the class. 
  +  <dt> 
  +  <dt><b></b> 
  +  <dt> 
  +  <dt><b>LocalResponder</b> 
     <dd>The LocalResponder is a Handler whose job in life is to serialize the response 
       message coming back from a local invocation into a String. It is by default 
       on the server's local transport response chain, and it ensures that serializing 
  
  
  
  1.2       +8 -1      xml-axis/java/samples/userguide/example4/LogHandler.java
  
  Index: LogHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/samples/userguide/example4/LogHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LogHandler.java	2001/08/03 14:26:46	1.1
  +++ LogHandler.java	2001/08/08 18:48:59	1.2
  @@ -12,13 +12,20 @@
            */
           try {
               Handler serviceHandler = msgContext.getServiceHandler();
  -            String filename = (String)serviceHandler.getOption("filename");
  +            String filename = (String)getOption("filename");
  +            if ((filename == null) || (filename.equals("")))
  +                throw new AxisFault("Server.NoLogFile",
  +                                 "No log file configured for the LogHandler!",
  +                                    null, null);
               FileOutputStream fos = new FileOutputStream(filename, true);
               
               PrintWriter writer = new PrintWriter(fos);
               
               Integer numAccesses =
                                (Integer)serviceHandler.getOption("accesses");
  +            if (numAccesses == null)
  +                numAccesses = new Integer(0);
  +            
               numAccesses = new Integer(numAccesses.intValue() + 1);
               
               Date date = new Date();
  
  
  
  1.1                  xml-axis/java/samples/userguide/example4/Client.java
  
  Index: Client.java
  ===================================================================
  package samples.userguide.example4;
  
  import org.apache.axis.client.ServiceClient;
  import org.apache.axis.utils.Debug;
  import org.apache.axis.utils.Options;
  
  public class Client
  {
      public static void main(String [] args)
      {
          try {
              Options options = new Options(args);
              
              Debug.setDebugLevel(options.isFlagSet('d'));
              
              String endpointURL = options.getURL();
              
              ServiceClient client = new ServiceClient(endpointURL);
              
              client.invoke("LogTestService", "testMethod", new Object [] {});
          } catch (Exception e) {
              System.err.println(e.toString());
          }
      }
  }
  
  
  
  1.1                  xml-axis/java/samples/userguide/example4/Service.java
  
  Index: Service.java
  ===================================================================
  package samples.userguide.example4;
  
  public class Service
  {
      public String testMethod()
      {
          return "Hi, you've reached the testMethod.";
      }
  }
  
  
  
  1.1                  xml-axis/java/samples/userguide/example4/deploy.xml
  
  Index: deploy.xml
  ===================================================================
  <admin:deploy xmlns:admin="AdminService">
   <!-- define the logging handler configuration -->
   <handler name="track" class="samples.userguide.example4.LogHandler">
    <option name="filename" value="MyService.log"/>
   </handler>
  
   <!-- define the service, using the log handler we just defined -->
   <service name="LogTestService" request="track" pivot="RPCDispatcher">
    <option name="className" value="samples.userguide.example4.Service"/>
    <option name="methodName" value="*"/>
   </service>
  </admin:deploy>
  
  
  
  1.28      +6 -2      xml-axis/java/src/org/apache/axis/AxisEngine.java
  
  Index: AxisEngine.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/AxisEngine.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- AxisEngine.java	2001/07/30 02:29:28	1.27
  +++ AxisEngine.java	2001/08/08 18:48:59	1.28
  @@ -158,8 +158,12 @@
               e.printStackTrace();
           }
           
  -        String propVal = props.getProperty(PROP_DEBUG_LEVEL, "0");
  -        Debug.setDebugLevel(Integer.parseInt(propVal));
  +        String propVal;
  +        
  +        if (!Debug.isLevelSet()) {
  +            propVal = props.getProperty(PROP_DEBUG_LEVEL, "0");
  +            Debug.setDebugLevel(Integer.parseInt(propVal));
  +        }
           
           propVal = props.getProperty(PROP_DEBUG_FILE);
           Debug.setToFile(propVal != null);
  
  
  
  1.25      +8 -6      xml-axis/java/src/org/apache/axis/AxisFault.java
  
  Index: AxisFault.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/AxisFault.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- AxisFault.java	2001/08/07 20:05:19	1.24
  +++ AxisFault.java	2001/08/08 18:48:59	1.25
  @@ -100,13 +100,15 @@
           setFaultString( e.toString() );
           
           // need to set details if we were in the body at the time!!
  -        ByteArrayOutputStream stream = new ByteArrayOutputStream();
  -        PrintStream           ps = new PrintStream( stream );
  -        e.printStackTrace(ps);
  -        ps.close();
  +        StringWriter writer = new StringWriter();
  +        PrintWriter printWriter = new PrintWriter(writer);
  +        e.printStackTrace(printWriter);
  +        printWriter.close();
           
  -        Element elem = XMLUtils.newDocument().createElement("details");
  -        elem.setNodeValue(ps.toString());
  +        Document doc = XMLUtils.newDocument();
  +        Element elem = doc.createElement("stackTrace");
  +        Node textNode = doc.createTextNode(writer.getBuffer().toString());
  +        elem.appendChild(textNode);
           
           Element [] details = new Element [] { elem };
           setFaultDetails( details );
  
  
  
  1.29      +12 -0     xml-axis/java/src/org/apache/axis/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/Constants.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- Constants.java	2001/07/30 13:24:27	1.28
  +++ Constants.java	2001/08/08 18:48:59	1.29
  @@ -56,6 +56,7 @@
   package org.apache.axis;
   
   import org.apache.axis.utils.QFault;
  +import org.apache.axis.utils.QName;
   
   public class Constants {
       // Some common Constants that should be used in local handler options
  @@ -160,6 +161,17 @@
                                     new QFault(URI_SOAP_ENV, "MustUnderstand");
   
   
  +    // QNames
  +    //////////////////////////////////////////////////////////////////////////
  +    public static final QName QNAME_FAULTCODE = 
  +                                         new QName(URI_SOAP_ENV, "faultcode");
  +    public static final QName QNAME_FAULTSTRING = 
  +                                       new QName(URI_SOAP_ENV, "faultstring");
  +    public static final QName QNAME_FAULTACTOR = 
  +                                        new QName(URI_SOAP_ENV, "faultactor");
  +    public static final QName QNAME_FAULTDETAILS =
  +                                         new QName(URI_SOAP_ENV, "details");
  +    
       // Misc Strings
       //////////////////////////////////////////////////////////////////////////
       public static final String URI_DEBUG = "http://xml.apache.org/axis/debug";
  
  
  
  1.29      +38 -0     xml-axis/java/src/org/apache/axis/encoding/SerializationContext.java
  
  Index: SerializationContext.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/SerializationContext.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- SerializationContext.java	2001/08/04 19:01:33	1.28
  +++ SerializationContext.java	2001/08/08 18:48:59	1.29
  @@ -59,6 +59,8 @@
   import java.util.*;
   import org.xml.sax.*;
   import org.xml.sax.helpers.AttributesImpl;
  +import org.w3c.dom.*;
  +
   import org.apache.axis.AxisEngine;
   import org.apache.axis.Constants;
   import org.apache.axis.message.*;
  @@ -405,4 +407,40 @@
       {
           writeString(XMLUtils.xmlEncodeString(string));
       }
  +
  +    /** Output a DOM representation to a SerializationContext
  +     */
  +    public void writeDOMElement(Element el)
  +        throws IOException
  +    {
  +        AttributesImpl attributes = null;
  +        NamedNodeMap attrMap = el.getAttributes();
  +        
  +        if (attrMap.getLength() > 0) {
  +            attributes = new AttributesImpl();
  +            for (int i = 0; i < attrMap.getLength(); i++) {
  +              Attr attr = (Attr)attrMap.item(i);
  +                            
  +              attributes.addAttribute("", attr.getName(), attr.getName(),
  +                                      "CDATA", attr.getValue());
  +            }
  +        }
  +        
  +        QName qName = new QName(el.getNamespaceURI(), el.getTagName());
  +        
  +        startElement(qName, attributes);
  +        
  +        NodeList children = el.getChildNodes();
  +        for (int i = 0; i < children.getLength(); i++) {
  +            Node child = children.item(i);
  +            if (child instanceof Element) {
  +                writeDOMElement((Element)child);
  +            } else if (child instanceof Text) {
  +                writeString(((Text)child).getData());
  +            }
  +        }
  +        
  +        endElement();
  +    }
  +    
   }
  
  
  
  1.39      +1 -36     xml-axis/java/src/org/apache/axis/message/MessageElement.java
  
  Index: MessageElement.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/MessageElement.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- MessageElement.java	2001/07/31 19:46:33	1.38
  +++ MessageElement.java	2001/08/08 18:48:59	1.39
  @@ -315,7 +315,7 @@
       protected void outputImpl(SerializationContext context) throws Exception
       {
           if (elementRep != null) {
  -            outputElement(elementRep, context);
  +            context.writeDOMElement(elementRep);
               return;
           }
           
  @@ -323,41 +323,6 @@
               context.registerPrefixForURI(prefix, namespaceURI);
           
           context.startElement(new QName(namespaceURI, name), attributes);
  -        context.endElement();
  -    }
  -    
  -    /** Output a DOM representation to a SerializationContext
  -     */
  -    protected void outputElement(Element el, SerializationContext context)
  -        throws IOException
  -    {
  -        AttributesImpl attributes = null;
  -        NamedNodeMap attrMap = el.getAttributes();
  -        
  -        if (attrMap.getLength() > 0) {
  -            attributes = new AttributesImpl();
  -            for (int i = 0; i < attrMap.getLength(); i++) {
  -              Attr attr = (Attr)attrMap.item(i);
  -                            
  -              attributes.addAttribute("", attr.getName(), attr.getName(),
  -                                      "CDATA", attr.getValue());
  -            }
  -        }
  -        
  -        QName qName = new QName(el.getNamespaceURI(), el.getTagName());
  -        
  -        context.startElement(qName, attributes);
  -        
  -        NodeList children = el.getChildNodes();
  -        for (int i = 0; i < children.getLength(); i++) {
  -            Node child = children.item(i);
  -            if (child instanceof Element) {
  -                outputElement((Element)child, context);
  -            } else if (child instanceof Text) {
  -                context.writeString(((Text)child).getData());
  -            }
  -        }
  -        
           context.endElement();
       }
       
  
  
  
  1.13      +8 -10     xml-axis/java/src/org/apache/axis/message/SOAPFaultElement.java
  
  Index: SOAPFaultElement.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/SOAPFaultElement.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SOAPFaultElement.java	2001/07/16 18:02:02	1.12
  +++ SOAPFaultElement.java	2001/08/08 18:48:59	1.13
  @@ -98,32 +98,30 @@
               // Do this BEFORE starting the element, so the prefix gets
               // registered if needed.
               String faultCode = context.qName2String(fault.getFaultCode());
  -            context.startElement(new QName(Constants.URI_SOAP_ENV,
  -                                           "faultcode"),
  -                                 null);
  +            context.startElement(Constants.QNAME_FAULTCODE, null);
               context.writeSafeString(faultCode);
               context.endElement();
           }
           
           if (fault.getFaultString() != null) {
  -            context.startElement(new QName(Constants.URI_SOAP_ENV,
  -                                           "faultstring"),
  -                                 null);
  +            context.startElement(Constants.QNAME_FAULTSTRING, null);
               context.writeSafeString(fault.getFaultString());
               context.endElement();
           }
           
           if (fault.getFaultActor() != null) {
  -            context.startElement(new QName(Constants.URI_SOAP_ENV,
  -                                           "faultactor"),
  -                                 null);
  +            context.startElement(Constants.QNAME_FAULTACTOR, null);
               context.writeSafeString(fault.getFaultActor());
               context.endElement();
           }
           
           Element[] faultDetails = fault.getFaultDetails();
           if (faultDetails != null) {
  -            //*** TBD ***
  +            context.startElement(Constants.QNAME_FAULTDETAILS, null);
  +            for (int i = 0; i < faultDetails.length; i++) {
  +                context.writeDOMElement(faultDetails[i]);
  +            }
  +            context.endElement();
           }
           
           context.endElement();
  
  
  
  1.8       +7 -0      xml-axis/java/src/org/apache/axis/utils/Debug.java
  
  Index: Debug.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/Debug.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Debug.java	2001/07/12 15:04:55	1.7
  +++ Debug.java	2001/08/08 18:49:00	1.8
  @@ -71,9 +71,16 @@
       private static int     debugLevel = 0 ;
       private static boolean toScreen   = true ;
       private static boolean toFile     = false ;
  +    private static boolean levelSet   = false;
   
  +    public static boolean isLevelSet()
  +    {
  +        return levelSet;
  +    }
  +    
       public static void setDebugLevel( int dl ) {
           debugLevel = dl ;
  +        levelSet = true;
       }
   
       public static int getDebugLevel() {