cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gkossakow...@apache.org
Subject svn commit: r685509 - /cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java
Date Wed, 13 Aug 2008 10:56:49 GMT
Author: gkossakowski
Date: Wed Aug 13 03:56:48 2008
New Revision: 685509

URL: http://svn.apache.org/viewvc?rev=685509&view=rev
Log:
Implemented exists() method so it tries to return more meaningful value.

Also, use exists() method in getInputStream, if it does not exist then SourceNotFound exception
should be thrown.

Modified:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java?rev=685509&r1=685508&r2=685509&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java
Wed Aug 13 03:56:48 2008
@@ -37,6 +37,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceException;
+import org.apache.excalibur.source.SourceNotFoundException;
 import org.apache.excalibur.source.SourceValidity;
 import org.apache.excalibur.source.impl.AbstractSource;
 import org.apache.excalibur.store.Store;
@@ -77,6 +78,11 @@
     public InputStream getInputStream() throws IOException, SourceException {
         try {
             connect();
+            
+            if (!exists())
+                throw new SourceNotFoundException("Location " + this.getURI() + " cannot
be found."
+                       + "The servlet returned " + servletConnection.getResponseCode() +
" response code.");
+            
             // FIXME: This is not the most elegant solution
             if (servletConnection.getResponseCode() != HttpServletResponse.SC_OK) {
                 //most probably, servlet returned 304 (not modified) and we need to perform
second request to get data
@@ -203,7 +209,15 @@
      * @see org.apache.excalibur.source.Source#exists()
      */
     public boolean exists() {
-        return true;
+        try {
+            connect();
+            int rc = servletConnection.getResponseCode();
+            return rc == HttpServletResponse.SC_OK || rc == HttpServletResponse.SC_FOUND
|| rc == HttpServletResponse.SC_NOT_MODIFIED;
+        } catch (Exception e) {
+            if (logger.isDebugEnabled())
+                logger.debug("Exception occured while making servlet request", e);
+            return false;
+        }
     }
 
     /**



Mime
View raw message