Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 42835 invoked from network); 2 Jan 2008 11:39:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Jan 2008 11:39:25 -0000 Received: (qmail 89682 invoked by uid 500); 2 Jan 2008 11:39:14 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 89633 invoked by uid 500); 2 Jan 2008 11:39:14 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 89622 invoked by uid 99); 2 Jan 2008 11:39:14 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Jan 2008 03:39:14 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Jan 2008 11:38:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3298D1A984F; Wed, 2 Jan 2008 03:38:50 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: cvs@cocoon.apache.org From: reinhard@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080102113850.3298D1A984F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ --> + + + 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. + + + 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.

- * - *

NOTE: 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

*/ 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 servlet: protocol. - * - * @version $Id$ + *

This class implements the servlet: protocol. A servlet URI can + * be relative (actually means absolute in the context of the calling servlet service) or absolute.

+ * + *

An absolute URI has following syntax:

+ *

servlet:[servlet-service-name]+:[path]. Here is an example:
+ * servlet:com.mycompany.mySkin.servlet:/abc.

+ * + *

A relative URI has following syntax:

+ *

servlet:[connection-name]:/[path]. Here is an example:
+ * servlet:mySkin:/abc. + * + * @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.