You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by sh...@apache.org on 2002/04/17 15:51:42 UTC

cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/core ImportSupport.java

shawn       02/04/17 06:51:42

  Modified:    standard/src/org/apache/taglibs/standard/tag/common/core
                        ImportSupport.java
  Log:
  Spec's new error handling for <c:import>.
  
  Revision  Changes    Path
  1.15      +52 -15    jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/core/ImportSupport.java
  
  Index: ImportSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/core/ImportSupport.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ImportSupport.java	30 Mar 2002 21:09:19 -0000	1.14
  +++ ImportSupport.java	17 Apr 2002 13:51:42 -0000	1.15
  @@ -161,8 +161,6 @@
   	    }
   	} catch (IOException ex) {
   	    throw new JspTagException(ex.toString());
  -	} catch (ServletException ex) {
  -	    throw new JspTagException(ex.toString());
   	}
   
   	return EVAL_BODY_INCLUDE;
  @@ -183,8 +181,6 @@
   	    return EVAL_PAGE;
           } catch (IOException ex) {
   	    throw new JspTagException(ex.toString());
  -        } catch (ServletException ex) {
  -	    throw new JspTagException(ex.toString());
           }
       }
   
  @@ -257,8 +253,7 @@
        * somewhat cute...)
        */
   
  -    private String acquireString() throws IOException, JspTagException,
  -	    ServletException {
  +    private String acquireString() throws IOException, JspException {
   	if (isAbsoluteUrl) {
   	    // for absolute URLs, delegate to our peer
   	    BufferedReader r = new BufferedReader(acquireReader());
  @@ -306,27 +301,49 @@
   	    // from this context, get a dispatcher
   	    RequestDispatcher rd =
                   c.getRequestDispatcher(stripSession(targetUrl));
  +	    if (rd == null)
  +		throw new JspTagException(stripSession(targetUrl));
   
   	    // include the resource, using our custom wrapper
   	    ImportResponseWrapper irw = 
   		new ImportResponseWrapper(
   		    (HttpServletResponse) pageContext.getResponse());
  -	    rd.include(pageContext.getRequest(), irw);
  +
  +	    // spec mandates specific error handling form include()
  +	    try {
  +	        rd.include(pageContext.getRequest(), irw);
  +	    } catch (IOException ex) {
  +		throw new JspException(ex);
  +	    } catch (RuntimeException ex) {
  +		throw new JspException(ex);
  +	    } catch (ServletException ex) {
  +		Throwable rc = ex.getRootCause();
  +		if (rc == null)
  +		    throw new JspException(ex);
  +		else
  +		    throw new JspException(rc);
  +	    }
  +
  +	    // disallow inappropriate response codes per JSTL spec
  +	    if (irw.getStatus() < 200 || irw.getStatus() > 299) {
  +		throw new JspTagException(irw.getStatus() + " " +
  +		    stripSession(targetUrl));
  +	    }
   
   	    // recover the response String from our wrapper
   	    return irw.getString();
   	}
       }
   
  -    private Reader acquireReader() throws IOException, ServletException,
  -	    JspTagException {
  +    private Reader acquireReader() throws IOException, JspException {
   	if (!isAbsoluteUrl) {
   	    // for relative URLs, delegate to our peer
   	    return new StringReader(acquireString());
   	} else {
   	    try {
   	        // handle absolute URLs ourselves, using java.net.URL
  -	        URL u = new URL(targetUrl());
  +		String target = targetUrl();
  +	        URL u = new URL(target);
                   URLConnection uc = u.openConnection();
                   InputStream i = uc.getInputStream();
   
  @@ -341,11 +358,20 @@
   		    else
   		        r = new InputStreamReader(i, DEFAULT_ENCODING);
   	        }
  +
  +		// check response code for HTTP URLs before returning, per spec,
  +		// before returning
  +		if (uc instanceof HttpURLConnection) {
  +		    int status = ((HttpURLConnection) uc).getResponseCode();
  +		    if (status != 200)
  +			throw new JspTagException(status + " " + target);
  +		}
  +
   	        return r;
   	    } catch (IOException ex) {
  -		throw new JspTagException(
  -		    Resources.getMessage("IMPORT_IO", targetUrl())
  -		    + " [" + ex + "]");
  +		throw new JspException(ex);
  +	    } catch (RuntimeException ex) {  // because the spec makes us
  +		throw new JspException(ex);
   	    }
   	}
       }
  @@ -396,6 +422,9 @@
   
   	/** 'True if getOutputStream() was called; false otherwise. */
   	private boolean isStreamUsed;
  +
  +	/** The HTTP status set by the target. */
  +	private int status = 200;
   	
   	//************************************************************
   	// Constructor and methods
  @@ -425,12 +454,20 @@
   
   	/** Has no effect. */
   	public void setContentType(String x) {
  -	   // ignore
  +	    // ignore
   	}
   
   	/** Has no effect. */
   	public void setLocale(Locale x) {
  -	   // ignore
  +	    // ignore
  +	}
  +
  +	public void setStatus(int status) {
  +	    this.status = status;
  +	}
  +
  +	public int getStatus() {
  +	    return status;
   	}
   
   	/** 
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>