cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r608087 - in /cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src: changes/ main/java/org/apache/cocoon/servletservice/components/ main/java/org/apache/cocoon/servletservice/postable/
Date Wed, 02 Jan 2008 11:38:48 GMT
Author: reinhard
Date: Wed Jan  2 03:38:37 2008
New Revision: 608087

URL: http://svn.apache.org/viewvc?rev=608087&view=rev
Log:
COCOON-2154
Enable absolute servlet URIs. By implementing this I also refactored ServletConnection. It
should also fix COCOON-2044 because relative servlet URIs are *internally* translated to absolute
URIs.

Modified:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/changes/changes.xml
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSourceFactory.java
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/postable/PostableSource.java

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/changes/changes.xml?rev=608087&r1=608086&r2=608087&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/changes/changes.xml
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/changes/changes.xml
Wed Jan  2 03:38:37 2008
@@ -25,6 +25,15 @@
   -->
 <document>
   <body>
+    <release version="1.0.0" date="2008-00-00" description="unreleased">
+      <action dev="reinhard" type="add">
+        The ServletSource supports absolute connections. An example for an absolute servlet
source
+        URI is "servlet:com.mycompany.test+:/test". This URI points to the servlet "com.mycompany.test"
which
+        is marked by the "+" character postfix. This also means that the "+" character at
the end of connection
+        names is not allowed.
+      </action>
+    </release>
+    <release version="1.0.0-RC1" date="2007-10-29" description="released"/>
     <release version="1.0.0-M1" date="2007-02-15" description="released">
       <action dev="reinhard" type="add">
         Initial creation.

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=608087&r1=608086&r2=608087&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 Jan  2 03:38:37 2008
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,12 +19,18 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.cocoon.CascadingIOException;
-import org.apache.cocoon.servletservice.ServletConnection;
+import org.apache.cocoon.servletservice.AbsoluteServletConnection;
+import org.apache.cocoon.servletservice.Absolutizable;
+import org.apache.cocoon.servletservice.CallStackHelper;
+import org.apache.cocoon.servletservice.IServletConnection;
 import org.apache.cocoon.servletservice.postable.PostableSource;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -35,9 +41,10 @@
 import org.apache.excalibur.store.Store;
 
 /**
- * Implementation of a {@link Source} that gets its content by invoking the Servlet.
+ * Implementation of a {@link Source} that gets its content by invoking a servlet service.
  *
  * @version $Id$
+ * @since 1.0.0
  */
 public class ServletSource extends AbstractSource
                            implements PostableSource {
@@ -49,30 +56,23 @@
      * This store is required because in {@link #getValidity()} we need value
      * of Last-Modified header of previous response in order to perform conditional
      * GET.</p>
-     *
-     * <p><strong>NOTE:</strong> Caching of servlet: source is broken in
some cases. See thread
-     * http://news.gmane.org/find-root.php?group=gmane.text.xml.cocoon.devel&article=72801</p>
      */
     private Store store;
 
     private String location;
-    private ServletConnection servletConnection;
+
+    private IServletConnection servletConnection;
+
     private boolean connected;
 
 
     public ServletSource(String location, Store store) throws IOException {
-        // the systemId (returned by getURI()) is by default null
-        // using the block uri is a little bit questionable as it only is valid
-        // whithin the current block, not globally
         this.store = store;
-        setSystemId(location);
         this.location = location;
-        this.servletConnection = new ServletConnection(location);
+        this.servletConnection = createServletConnection(location);
+        this.setSystemId(this.servletConnection.getURI().toASCIIString());
     }
 
-    /* (non-Javadoc)
-     * @see org.apache.excalibur.source.impl.AbstractSource#getInputStream()
-     */
     public InputStream getInputStream() throws IOException, SourceException {
         try {
             connect();
@@ -87,7 +87,7 @@
                 //       and, as a result, GET request instead of POST.
                 //
 
-                servletConnection = new ServletConnection(location);
+                servletConnection = createServletConnection(location);
                 servletConnection.connect();
             }
 
@@ -97,9 +97,51 @@
         }
     }
 
-    /* (non-Javadoc)
-     * @see org.apache.excalibur.source.impl.AbstractSource#getValidity()
+    /**
+     * Factory method that creates either a {@link ServletConnection}.
+     *
+     * @param The URI as {@link String} pointing to the servlet.
+     * @return An {@link IServletConnection} pointing to the referenced servlet.
+     * @throws MalformedURLException if there is a problem with the location URI.
      */
+    private IServletConnection createServletConnection(String location) throws MalformedURLException
{
+        URI locationUri = null;
+        try {
+            locationUri = new URI(location);
+            if (!locationUri.isAbsolute()) {
+                throw new MalformedURLException("Only absolute URIs are allowed for the block
protocol. "
+                                + locationUri.toString());
+            }
+
+            // get the referenced servlet and find out if it is an absolute or
+            // relative connection
+            locationUri = new URI(locationUri.getRawSchemeSpecificPart());
+
+            final String servletReference = locationUri.getScheme();
+            final Absolutizable absolutizable = (Absolutizable) CallStackHelper.getCurrentServletContext();
+            final String servletName;
+
+            // find out the type of the reference and create a service name
+            if (servletReference == null) {
+                // self-reference
+                servletName = absolutizable.getServiceName();
+            } else if (servletReference.endsWith(AbsoluteServletConnection.ABSOLUTE_SERVLET_SOURCE_POSTFIX))
{
+                // absolute reference
+                servletName = servletReference.substring(0, servletReference.length() - 1);
+            } else {
+                // relative reference
+                servletName = absolutizable.getServiceName(servletReference);
+            }
+            return new AbsoluteServletConnection(servletName, locationUri.getRawPath(), locationUri.getRawQuery());
+
+        } catch (URISyntaxException e) {
+            MalformedURLException malformedURLException = new MalformedURLException("Invalid
URI syntax. "
+                            + e.getMessage());
+            malformedURLException.initCause(e);
+            throw malformedURLException;
+        }
+    }
+
     public SourceValidity getValidity() {
         try {
             connect();
@@ -111,9 +153,6 @@
         }
     }
 
-    /* (non-Javadoc)
-     * @see org.apache.excalibur.source.impl.AbstractSource#getLastModified()
-     */
     public long getLastModified() {
         try {
             connect();
@@ -126,9 +165,8 @@
     }
 
     /**
-     * The mime-type of the content described by this object.
-     * If the source is not able to determine the mime-type by itself
-     * this can be null.
+     * The mime-type of the content described by this object. If the source is
+     * not able to determine the mime-type by itself this can be null.
      */
     public String getMimeType() {
         try {
@@ -150,6 +188,12 @@
         return true;
     }
 
+    /**
+     * Return an {@link OutputStream} to post to. The returned stream must be closed by
+     * the calling code.
+     *
+     * @return {@link OutputStream} to post to
+     */
     public OutputStream getOutputStream() throws IOException {
         return servletConnection.getOutputStream();
     }
@@ -209,27 +253,16 @@
 
     private static final class ServletValidity implements SourceValidity {
 
-        /**
-         *
-         */
-        private static final long serialVersionUID = 1793646888814956538L;
-
         private int responseCode;
 
         public ServletValidity(int responseCode) {
             setResponseCode(responseCode);
         }
 
-        /* (non-Javadoc)
-         * @see SourceValidity#isValid()
-         */
         public int isValid() {
             return SourceValidity.UNKNOWN;
         }
 
-        /* (non-Javadoc)
-         * @see SourceValidity#isValid(SourceValidity)
-         */
         public int isValid(SourceValidity newValidity) {
             if (newValidity instanceof ServletValidity) {
                 ServletValidity newServletValidity = (ServletValidity) newValidity;

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSourceFactory.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/ServletSourceFactory.java?rev=608087&r1=608086&r2=608087&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSourceFactory.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSourceFactory.java
Wed Jan  2 03:38:37 2008
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,20 +29,30 @@
 import org.apache.excalibur.store.Store;
 
 /**
- * This class implements the <code>servlet:</code> protocol.
- * 
- * @version $Id$
+ * <p>This class implements the <code>servlet:</code> protocol. A servlet
URI can
+ * be relative (actually means absolute in the context of the calling servlet service) or
absolute.</p>
+ *
+ * <p>An absolute URI has following syntax:</p>
+ * <p><code>servlet:[servlet-service-name]+:[path]</code>. Here is an example:<br/>
+ * <code>servlet:com.mycompany.mySkin.servlet:/abc</code>.</p>
+ *
+ * <p>A relative URI has following syntax:</p>
+ * <p><code>servlet:[connection-name]:/[path]</code>. Here is an example:<br/>
+ * <code>servlet:mySkin:/abc</code>.
+ *
+ * @version $Id: ServletSourceFactory.java 577520 2007-09-20 03:06:12Z
+ *          vgritsenko $
+ * @since 1.0.0
  */
-public final class ServletSourceFactory implements SourceFactory,
-                                                   URIAbsolutizer {
+public final class ServletSourceFactory implements SourceFactory, URIAbsolutizer {
 
     /** By default we use the logger for this class. */
     private Log logger = LogFactory.getLog(getClass());
-    
+
     /**
      * Store that will be used by {@link ServletSource}.
      */
-    private Store store; 
+    private Store store;
 
     private Log getLogger() {
         return this.logger;
@@ -56,14 +66,7 @@
         this.store = store;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.excalibur.source.SourceFactory#getSource(java.lang.String,
-     *      java.util.Map)
-     */
-    public Source getSource(String location, Map parameters)
-    throws MalformedURLException, IOException {
+    public Source getSource(String location, Map parameters) throws MalformedURLException,
IOException {
         if (getLogger().isDebugEnabled()) {
             getLogger().debug("Creating source object for " + location);
         }
@@ -71,11 +74,6 @@
         return new ServletSource(location, store);
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.excalibur.source.SourceFactory#release(org.apache.excalibur.source.Source)
-     */
     public void release(Source source) {
         if (source != null) {
             if (getLogger().isDebugEnabled()) {
@@ -84,13 +82,8 @@
         }
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.excalibur.source.URIAbsolutizer#absolutize(java.lang.String,
-     *      java.lang.String)
-     */
     public String absolutize(String baseURI, String location) {
         return SourceUtil.absolutize(baseURI, location, true);
     }
+
 }

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/postable/PostableSource.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/postable/PostableSource.java?rev=608087&r1=608086&r2=608087&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/postable/PostableSource.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/postable/PostableSource.java
Wed Jan  2 03:38:37 2008
@@ -21,8 +21,15 @@
 
 import org.apache.excalibur.source.Source;
 
+/**
+ * Addition to the {@link Source} that enables passing data to the called
+ * source. This data is passed by writing it into an {@link OutputStream}.
+ *
+ * @version $Id$
+ * @since 1.0.0
+ */
 public interface PostableSource extends Source {
-	/**
+    /**
      * Return an {@link OutputStream} to post to.
      *
      * The returned stream must be closed by the calling code.



Mime
View raw message