Return-Path:
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 theservlet:
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.