You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xang-cvs@xml.apache.org by md...@apache.org on 2001/08/07 08:10:15 UTC

cvs commit: xml-xang/java/src/org/apache/xang/net/http/object/impl HTTPObject.java

mdierken    01/08/06 23:10:15

  Modified:    java/src/org/apache/xang/net/http/object/impl
                        HTTPObject.java
  Log:
  Add printError() for a little code cleanup.
  
  Revision  Changes    Path
  1.4       +54 -39    xml-xang/java/src/org/apache/xang/net/http/object/impl/HTTPObject.java
  
  Index: HTTPObject.java
  ===================================================================
  RCS file: /home/cvs/xml-xang/java/src/org/apache/xang/net/http/object/impl/HTTPObject.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HTTPObject.java	2000/04/18 23:05:31	1.3
  +++ HTTPObject.java	2001/08/07 06:10:15	1.4
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -10,7 +10,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -18,7 +18,7 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:  
  + *    if any, must include the following acknowledgment:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowledgment may appear in the software itself,
  @@ -26,7 +26,7 @@
    *
    * 4. The names "Xang" and "Apache Software Foundation" must
    *    not be used to endorse or promote products derived from this
  - *    software without prior written permission. For written 
  + *    software without prior written permission. For written
    *    permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache",
  @@ -79,11 +79,11 @@
       ///////////////////
       // method discovery
       private static Class[] paramSignature;
  -    
  -    static 
  +
  +    static
       {
           java.lang.reflect.Method methods[]=null;
  -           
  +
           // Find the signature of the 'dispatch' method.
           try
           {
  @@ -94,7 +94,7 @@
           {
               System.err.println("HTTPRequestHandler(): EXCEPTION: "+e.getMessage());
           }
  -            
  +
           for (int i=0; i < methods.length; i++)
           {
               if (methods[i].getName().equalsIgnoreCase("dispatch"))
  @@ -104,15 +104,31 @@
               }
           }
       }
  -    
  +
  +	static void printError(IHTTPContext context,Exception e)
  +	{
  +		try {
  +			PrintWriter out=context.getResponse().getWriter();
  +		    out.print("<html><body> ERROR : ");
  +			out.print(e.getMessage());
  +			out.print("<pre>");
  +			e.printStackTrace(out);
  +			out.print("</pre>");
  +			out.print("</body></html>");
  +		}
  +		catch(IOException ioe)
  +		{
  +		}
  +	}
  +
       /**
        * Dynamically dispatch a method onto an object.
        * @see IHTTPObject.dispatch()
  -     * 
  +     *
       **      @param object target object
       **      @param context information about current transaction
       **      @param returnTypes list of acceptable mime types
  -    **      @param parameters list of parameters to the specified method 
  +    **      @param parameters list of parameters to the specified method
       **      @return boolean indicating success
       **/
       public static boolean dispatchToObject(IHTTPObject object,IHTTPContext context,Vector returnTypes,String method,Hashtable parameters)
  @@ -123,7 +139,7 @@
               {
                   System.out.println("paramSig == null");
               }
  -            
  +
               java.lang.reflect.Method meth;
               // find the named method that looks like the 'dispatch' method.
               method=method.toLowerCase();
  @@ -143,13 +159,12 @@
           catch(NoSuchMethodException ne)
           {
               System.out.println("HTTPObject.dispatch(): EXCEPTION: No such method '"+method+"' in "+object.getClass().getName());
  -//            ne.printStackTrace(System.out);
  +		    printError(context,ne);
           }
           catch(java.lang.reflect.InvocationTargetException te)
           {
               System.out.println("HTTPObject.dispatch(): EXCEPTION: Invocation target exception. "+te.getTargetException().getMessage());
               System.out.println("\t\t in method '"+method+"' of "+object.getClass().getName());
  -//            te.printStackTrace(System.out);
   			te.getTargetException().printStackTrace(System.out);
           }
           catch(Exception e)
  @@ -157,7 +172,7 @@
               System.out.println("HTTPObject.dispatch(): EXCEPTION: "+e.getMessage());
               System.out.println("\t\t in method '"+method+"' of "+object.getClass().getName());
           }
  -        
  +
           return false;
       }
   
  @@ -170,12 +185,12 @@
       {
           boolean found=false;
           int i;
  -        
  +
           if (types == null)
           {
               return false;
           }
  -        
  +
           for (i=0; i < types.size(); i++)
           {
               if (((String)types.elementAt(i)).startsWith(type))
  @@ -239,11 +254,11 @@
           }
           return false;
       }
  -    
  +
       /**
        * This requests authentication info from the client by
        * sending an HTTP 401 error with a WWW-Authenticate header.
  -     * 
  +     *
        ** @param context information about the current transaction
        ** @param authType type of authentication format the server wants (e.g Basic)
        ** @param realm the 'realm' of authentication
  @@ -253,7 +268,7 @@
           context.getResponse().setHeader("WWW-Authenticate",authType+" realm=\""+realm+"\"");
           context.getResponse().setStatus(HttpServletResponse.SC_UNAUTHORIZED,"Login required.");
       }
  -    
  +
       /////////////////////////////
       // IHTTPObject implementation
       /**
  @@ -263,7 +278,7 @@
       {
           return dispatchToObject(this,context,returnTypes,method,parameters);
       }
  -    
  +
       // child objects
       /**
       **      @see datachannel.net.http.object.IHTTPObject
  @@ -280,7 +295,7 @@
       {
           // do nothing
       }
  -    
  +
       // HTTP Methods
       /**
        * Utility to help output a simple XML description of the available methods.
  @@ -341,12 +356,12 @@
                   sb.append(" from='"+method.getDeclaringClass().getName()+"'");
               printModifierStrings(sb,method.getModifiers());
               sb.append(">\n");
  -                    
  +
               // return type & attributes
               sb.append("\t<return type='"+retType.getName()+"'");
               printModifierStrings(sb,retType.getModifiers());
               sb.append("/>\n");
  -                    
  +
               // parameters
               for(int j=0; j < parameterTypes.length; j++)
               {
  @@ -361,7 +376,7 @@
       public static void doGetClassMetadata(StringBuffer sb,Class info)
       {
           String className = info.getName();
  -        
  +
           // output 'class' tag & its attributes
           sb.append("<class name='"+className+"' ");
           printModifierStrings(sb,info.getModifiers());
  @@ -373,15 +388,15 @@
       public static String doDiscovery(Class info)
       {
           String htmlOutput=null;
  -        
  +
           try
           {
               StringBuffer sb = new StringBuffer();
               String className = info.getName();
   
  -            doGetClassMetadata(sb,info);            
  +            doGetClassMetadata(sb,info);
               doListMethods(sb,info);
  -            
  +
               sb.append("</class>");
               htmlOutput = sb.toString();
           }
  @@ -390,7 +405,7 @@
               ByteArrayOutputStream baos = new ByteArrayOutputStream();
               PrintStream ps = new PrintStream(baos);
               e.printStackTrace(ps);
  -            
  +
               htmlOutput = "<html><body>Class2Xml.doDiscovery() : EXCEPTION: "+e.getMessage()+"<br/>"+baos.toString()+"</body></html>";
           }
   
  @@ -404,7 +419,7 @@
       {
           Class info;
           String htmlOutput=null;
  -        
  +
           try
           {
               // load java class
  @@ -440,7 +455,7 @@
       {
           doGetClassMetadata(sb,this.getClass());
       }
  -    
  +
       /**
        * Outputs list of methods for the current object
        */
  @@ -455,7 +470,7 @@
       public String doDiscovery()
       {
           String htmlOutput=null;
  -        
  +
           try
           {
               StringBuffer sb = new StringBuffer();
  @@ -463,7 +478,7 @@
               // output 'class' tag & its attributes
               doGetClassMetadata(sb);
               doListMethods(sb);
  -            
  +
               sb.append("</class>");
               htmlOutput = sb.toString();
           }
  @@ -472,13 +487,13 @@
               ByteArrayOutputStream baos = new ByteArrayOutputStream();
               PrintStream ps = new PrintStream(baos);
               e.printStackTrace(ps);
  -            
  +
               htmlOutput = "<html><body>Class2Xml.doDiscovery() : EXCEPTION: "+e.getMessage()+"<br/>"+baos.toString()+"</body></html>";
           }
   
           return htmlOutput;
       }
  -    
  +
       /**
        * List the methods of the command handler.
        * This will output either XML or HTML, based on the Accept header.
  @@ -487,7 +502,7 @@
       {
           String methodList=null;
           PrintWriter pw;
  -        
  +
           try
           {
               methodList = doDiscovery();
  @@ -499,12 +514,12 @@
           catch(Exception e)
           {
           }
  -    
  +
           return true;
       }
       ////////////////
       // Data
  -    
  -    public final static String RCS_STRING = "$Workfile: HTTPObject.java $ " + "$Revision: 1.3 $";
  +
  +    public final static String RCS_STRING = "$Workfile: HTTPObject.java $ " + "$Revision: 1.4 $";
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xang-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xang-cvs-help@xml.apache.org