You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/02/16 18:13:26 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/servlets DefaultErrorPage.java

costin      00/02/16 09:13:26

  Modified:    src/share/org/apache/tomcat/context WebXmlReader.java
               src/share/org/apache/tomcat/core ContextManager.java
                        RequestDispatcherImpl.java Response.java
                        ResponseImpl.java ServletWrapper.java
               src/share/org/apache/tomcat/service/http
                        HttpResponseAdapter.java
               src/share/org/apache/tomcat/servlets DefaultErrorPage.java
  Log:
  - removed "broken pipe" stack trace - we do log the event and the URI, but
  no stack trace.
  
  - BUG: fixed included response - headers and status read-only in include
  
  - BUG: error reporting for included response, mention the fact we are in
  an included, and also report the page with problems.
  
  Revision  Changes    Path
  1.11      +5 -1      jakarta-tomcat/src/share/org/apache/tomcat/context/WebXmlReader.java
  
  Index: WebXmlReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/WebXmlReader.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- WebXmlReader.java	2000/02/16 05:44:33	1.10
  +++ WebXmlReader.java	2000/02/16 17:13:21	1.11
  @@ -42,7 +42,11 @@
   
       void processFile( Context ctx, String file) {
   	try {
  -	    File f=new File(file);	
  +	    File f=new File(file);
  +	    if( ! f.exists() ) {
  +		ctx.log( "File not found, using defaults " + file );
  +		return;
  +	    }
   	    if( ctx.getDebug() > 0 ) ctx.log("Reading " + file );
   	    XmlMapper xh=new XmlMapper();
   	    if( ctx.getDebug() > 5 ) xh.setDebug( 2 );
  
  
  
  1.46      +2 -0      jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java
  
  Index: ContextManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- ContextManager.java	2000/02/16 05:44:34	1.45
  +++ ContextManager.java	2000/02/16 17:13:22	1.46
  @@ -525,6 +525,8 @@
   	    
   	} catch (Exception e) {
   	    if(e instanceof IOException && "Broken pipe".equals(e.getMessage()) ) {
  +		log("Broken pipe " + rrequest.getRequestURI());
  +		return;
   	    }
   	    // XXX
   	    // this isn't what we want, we want to log the problem somehow
  
  
  
  1.17      +9 -3      jakarta-tomcat/src/share/org/apache/tomcat/core/RequestDispatcherImpl.java
  
  Index: RequestDispatcherImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestDispatcherImpl.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- RequestDispatcherImpl.java	2000/02/03 23:41:29	1.16
  +++ RequestDispatcherImpl.java	2000/02/16 17:13:22	1.17
  @@ -124,6 +124,7 @@
       {
   	Request realRequest = ((HttpServletRequestFacade)request).getRealRequest();
           Response realResponse = ((HttpServletResponseFacade)response).getRealResponse();
  +
   	// according to specs
   	if (realResponse.isStarted()) 
   	    throw new IllegalStateException(sm.getString("rdi.forward.ise"));
  @@ -172,6 +173,10 @@
   	// Implement the spec that "no changes in response, only write"
   	// can also be done by setting the response to 0.9 mode ( as Apache does!)
   	//	IncludedResponse iResponse = new IncludedResponse(realResponse);
  +	boolean old_included=realResponse.isIncluded();
  +	if( ! old_included ) {
  +	    realResponse.setIncluded( true );
  +	}
   
   	// Here the spec is very special, pay attention
   
  @@ -245,9 +250,6 @@
   
   	addQueryString( realRequest, queryString );
   
  -// 	System.out.println("Lookup : " + subRequest );
  -// 	System.out.println();
  -// 	System.out.println("Req: " + realRequest);
    	// now it's really strange: we call the wrapper on the subrequest
   	// for the realRequest ( since the real request will still have the
   	// original handler/wrapper )
  @@ -267,6 +269,10 @@
   				 old_path_info);
   	replaceAttribute( realRequest, "javax.servlet.include.query_string",
   				 old_query_string);
  +	// revert to the response behavior
  +	if( ! old_included ) {
  +	    realResponse.setIncluded( false );
  +	}
       }
   
   	
  
  
  
  1.15      +12 -0     jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java
  
  Index: Response.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Response.java	2000/02/03 07:11:52	1.14
  +++ Response.java	2000/02/16 17:13:23	1.15
  @@ -115,6 +115,18 @@
   
       public PrintWriter getWriter() throws IOException ;
   
  +    /** True if we are in an included servlet
  +     */
  +    public boolean isIncluded();
  +
  +    /** The response will not set any header or the status line -
  +     *  it can only write to the output stream or flush.
  +     *  This is used to implement RD.include() and can be used for
  +     *  HTTP/0.9
  +     */
  +    public void setIncluded(boolean b);
  +	
  +    
       // -------------------- Buffering --------------------
       
       public int getBufferSize() ;
  
  
  
  1.15      +41 -15    jakarta-tomcat/src/share/org/apache/tomcat/core/ResponseImpl.java
  
  Index: ResponseImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ResponseImpl.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ResponseImpl.java	2000/02/14 04:59:39	1.14
  +++ ResponseImpl.java	2000/02/16 17:13:23	1.15
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ResponseImpl.java,v 1.14 2000/02/14 04:59:39 costin Exp $
  - * $Revision: 1.14 $
  - * $Date: 2000/02/14 04:59:39 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ResponseImpl.java,v 1.15 2000/02/16 17:13:23 costin Exp $
  + * $Revision: 1.15 $
  + * $Date: 2000/02/16 17:13:23 $
    *
    * ====================================================================
    *
  @@ -102,6 +102,8 @@
       protected boolean started = false;
       protected boolean committed = false;
   
  +    boolean notIncluded=true;
  +    
       StringBuffer body=new StringBuffer();
   
       public ResponseImpl() {
  @@ -123,6 +125,24 @@
       }
   
       /* -------------------- */
  +
  +    // Included response behavior
  +    public boolean isIncluded() {
  +	return ! notIncluded;
  +    }
  +
  +    public void setIncluded( boolean incl ) {
  +	notIncluded= ! incl;
  +	if( incl ) {
  +	    // included behavior, no header output,
  +	    // no status change on errors.
  +	    // XXX we can optimize a bit - replace headers with
  +	    // an new Hashtable we can throw away. 
  +	} else {
  +	    // move back to normal behavior.
  +
  +	}
  +    }
       
       public boolean isStarted() {
   	return started;
  @@ -143,7 +163,7 @@
   	out.recycle();
   	started = false;
   	committed = false;
  -
  +	notIncluded=true;
   	// adapter
   	status=-1;
   	body.setLength(0);
  @@ -158,11 +178,14 @@
   	    out.reallyFlush();
   	    out.close();
   	} catch (SocketException e) {
  +	    if(request!=null) request.getContext().log("Socket Exception" + request.getRequestURI());	    	    
   	    return;  // munch
  -	} catch (IOException e) {
  -	    if("Broken pipe".equals(e.getMessage()))
  +	} catch (IOException ex) {
  +	    if( "Broken pipe".equals(ex.getMessage())) {
  +		if(request!=null) request.getContext().log("Broken pipe " + request.getRequestURI());
   		return;
  -	    throw e;
  +	    }
  +	    throw ex;
   	}
       }
   
  @@ -215,11 +238,11 @@
       }
   
       public void setHeader(String name, String value) {
  -	headers.putHeader(name, value);
  +	if( notIncluded ) headers.putHeader(name, value);
       }
   
       public void addHeader(String name, String value) {
  -        headers.addHeader(name, value);
  +        if( notIncluded ) headers.addHeader(name, value);
       }
   
       public int getBufferSize() {
  @@ -265,7 +288,7 @@
           // Clear the cookies and such
   
           // Clear the headers
  -        headers.clear();
  +        if( notIncluded) headers.clear();
       }
   
       public void flushBuffer() throws IOException {
  @@ -286,14 +309,14 @@
   
   	// let CM notify interceptors and give a chance to fix
   	// the headers
  -	if(request.getContext() != null) 
  +	if(request.getContext() != null && notIncluded ) 
   	    request.getContext().getContextManager().doBeforeBody(request, this);
   
   	// No action.. 
       }
   
       public void addCookie(Cookie cookie) {
  -	userCookies.addElement(cookie);
  +	if( notIncluded ) userCookies.addElement(cookie);
       }
   
       public Enumeration getCookies() {
  @@ -301,7 +324,7 @@
       }
   
       public void setSessionId( String id ) {
  -	sessionId=id;
  +	if( notIncluded ) sessionId=id;
       }
   
       public String getSessionId() {
  @@ -313,7 +336,7 @@
       }
   
       public void setLocale(Locale locale) {
  -        if (locale == null) {
  +        if (locale == null || ! notIncluded) {
               return;  // throw an exception?
           }
   
  @@ -355,7 +378,8 @@
       }
   
       public void setContentType(String contentType) {
  -        this.contentType = contentType;
  +        if( ! notIncluded ) return;
  +	this.contentType = contentType;
   	String encoding = RequestUtil.getCharsetFromContentType(contentType);
           if (encoding != null) {
   	    characterEncoding = encoding;
  @@ -368,6 +392,7 @@
       }
       
       public void setContentLength(int contentLength) {
  +        if( ! notIncluded ) return;
   	this.contentLength = contentLength;
   	addHeader("Content-Length", (new Integer(contentLength)).toString());
       }
  @@ -384,6 +409,7 @@
       /** Set the response status 
        */ 
       public void setStatus( int status ) {
  +	if( ! notIncluded ) return;
   	this.status=status;
       }
   
  
  
  
  1.28      +5 -5      jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java
  
  Index: ServletWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- ServletWrapper.java	2000/02/16 05:44:34	1.27
  +++ ServletWrapper.java	2000/02/16 17:13:23	1.28
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v 1.27 2000/02/16 05:44:34 costin Exp $
  - * $Revision: 1.27 $
  - * $Date: 2000/02/16 05:44:34 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v 1.28 2000/02/16 17:13:23 costin Exp $
  + * $Revision: 1.28 $
  + * $Date: 2000/02/16 17:13:23 $
    *
    * ====================================================================
    *
  @@ -158,7 +158,7 @@
           this.path = path;
       }
   
  -    String getServletDescription() {
  +    public String getServletDescription() {
           return this.description;
       }
   
  @@ -251,7 +251,7 @@
       }
   
       // XXX XXX need to go directly to Jsp API 
  -    public void handleJspRequest(final HttpServletRequestFacade request,
  +    void handleJspRequest(final HttpServletRequestFacade request,
   			      final HttpServletResponseFacade response)
   	throws IOException
       {
  
  
  
  1.7       +9 -9      jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java
  
  Index: HttpResponseAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- HttpResponseAdapter.java	2000/02/03 07:11:55	1.6
  +++ HttpResponseAdapter.java	2000/02/16 17:13:24	1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java,v 1.6 2000/02/03 07:11:55 costin Exp $
  - * $Revision: 1.6 $
  - * $Date: 2000/02/03 07:11:55 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java,v 1.7 2000/02/16 17:13:24 costin Exp $
  + * $Revision: 1.7 $
  + * $Date: 2000/02/16 17:13:24 $
    *
    * ====================================================================
    *
  @@ -118,12 +118,12 @@
   		String value=values[i];
   		headersSB.setLength(0);
   		headersSB.append(name).append(": ").append(value).append("\r\n");
  -		try {
  -		    sout.write( headersSB.toString().getBytes(Constants.CharacterEncoding.Default) );
  -		} catch( IOException ex ) {
  -		    ex.printStackTrace();
  -		    //XXX mark the error - should abandon everything 
  -		}
  +		//		try {
  +		sout.write( headersSB.toString().getBytes(Constants.CharacterEncoding.Default) );
  +		//		} catch( IOException ex ) {
  +		//		    ex.printStackTrace();
  +		//XXX mark the error - should abandon everything 
  +		//}
   	    }
   	}
   	sout.write( CRLF, 0, 2 );
  
  
  
  1.3       +8 -1      jakarta-tomcat/src/share/org/apache/tomcat/servlets/DefaultErrorPage.java
  
  Index: DefaultErrorPage.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/servlets/DefaultErrorPage.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultErrorPage.java	2000/02/01 07:37:40	1.2
  +++ DefaultErrorPage.java	2000/02/16 17:13:25	1.3
  @@ -148,7 +148,14 @@
   	response.setContentType("text/html");
   
   	StringBuffer buf = new StringBuffer();
  -	buf.append("<h1>Error: " + sc + "</h1>\r\n");
  +	if( response.isIncluded() ) {
  +	    buf.append("<h1>Included servlet error: " );
  +	}  else {
  +	    buf.append("<h1>Error: ");
  +	    }
  +	buf.append( sc + "</h1>\r\n");
  +	// More info - where it happended"
  +	buf.append("<h2>Location: " + request.getRequestURI() + "</h2>");
   	buf.append(msg + "\r\n");
   
   	if( response.isUsingStream() ) {