You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2008/01/02 12:38:24 UTC
svn commit: r608086 - in
/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src:
changes/ main/java/org/apache/cocoon/callstack/
main/java/org/apache/cocoon/servletservice/
main/java/org/apache/cocoon/servletservice/spring/
Author: reinhard
Date: Wed Jan 2 03:38:10 2008
New Revision: 608086
URL: http://svn.apache.org/viewvc?rev=608086&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.
Added:
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbsoluteServletConnection.java (with props)
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbstractServletConnection.java (with props)
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/IServletConnection.java (with props)
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/RelativeServletConnection.java
- copied, changed from r606689, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java
Removed:
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java
Modified:
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/changes/changes.xml
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallFrame.java
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallScope.java
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/Absolutizable.java
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletDecorator.java
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletNamespaceHandler.java
Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/changes/changes.xml?rev=608086&r1=608085&r2=608086&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/changes/changes.xml (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/changes/changes.xml Wed Jan 2 03:38:10 2008
@@ -17,27 +17,34 @@
specific language governing permissions and limitations
under the License.
-->
-<!--+
- | Find usage details at http://maven.apache.org/plugins/maven-changes-plugin/usage.html
- |
- | @version $Id$
- +-->
+<!--
+ - See http://maven.apache.org/plugins/maven-changes-plugin/usage.html
+ -
+ - $Id$
+-->
<document>
<body>
- <release version="1.0.0-RC1-SNAPSHOT" date="2007-00-00" description="unreleased">
+ <release version="1.0.0" date="2008-00-00" description="unreleased">
+ <action dev="reinhard" type="add">
+ The "+" character is not allowed at the end of connection names anymore. Starting
+ Cocoon will fail hard with a RuntimeException if this rule is broken. See
+ org.apache.cocoon.servletservice.spring.ServletDecorator.
+ </action>
+ <action dev="reinhard" type="add">
+ Add support for absolute ServetConnections.
+ </action>
+ </release>
+ <release version="1.0.0-RC1" date="2007-10-29" description="released">
<action dev="gkossakowski" type="add" issue="COCOON-2038">
Implemented true Object Oriented approach for handling servlet calls.
- This change removes the need for explicit super calls.
+ This change removes the need for explicit super calls.
</action>
<action dev="gkossakowski" type="fix" issue="COCOON-1939">
- Fixed handling of multilevel inheritance that could cause stack overflow.
+ Fixed handling of multilevel inheritance that could cause stack overflow.
</action>
<action dev="gkossakowski" type="fix" issue="COCOON-2121">
- Fixed bug in DispatcherServlet that caused servlet (blocks) mounted at "/" to be handled improperly.
+ Fixed bug in DispatcherServlet that caused servlet (blocks) mounted at "/" to be handled improperly.
</action>
- </release>
- <release version="1.0.0-M2-SNAPSHOT" date="2007-00-00" description="unreleased">
-
</release>
</body>
</document>
Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallFrame.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallFrame.java?rev=608086&r1=608085&r2=608086&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallFrame.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallFrame.java Wed Jan 2 03:38:10 2008
@@ -20,17 +20,17 @@
import java.util.Iterator;
import java.util.Map;
-/**
+/**
* Attributes in the call frame and destruction callbacks that should be
* executed when the call frame is left.
- *
+ *
* @version $Id$
- * @since 2.2
+ * @since 1.0.0
*/
public class CallFrame {
private Map attributes;
private Map destructionCallbacks;
-
+
public boolean hasAttribute(String name) {
return this.attributes != null && this.attributes.containsKey(name);
}
@@ -38,7 +38,7 @@
public Object getAttribute(String name) {
return this.attributes != null ? this.attributes.get(name) : null;
}
-
+
public void setAttribute(String name, Object value) {
if (this.attributes == null) {
this.attributes = new HashMap();
@@ -46,11 +46,11 @@
this.attributes.put(name, value);
}
-
+
public Object removeAttribute(String name) {
return this.attributes != null ? this.attributes.remove(name) : null;
}
-
+
public void registerDestructionCallback(String name, Runnable callback) {
if (this.destructionCallbacks == null) {
this.destructionCallbacks = new HashMap();
@@ -58,7 +58,7 @@
this.destructionCallbacks.put(name, callback);
}
-
+
void executeDestructionCallbacks() {
if (this.destructionCallbacks == null) {
return;
Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallScope.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallScope.java?rev=608086&r1=608085&r2=608086&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallScope.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallScope.java Wed Jan 2 03:38:10 2008
@@ -25,7 +25,7 @@
* an object is in scope when it is in the top frame of the stack.
*
* @version $Id$
- * @since 2.2
+ * @since 1.0.0
*/
public class CallScope implements Scope {
Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbsoluteServletConnection.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbsoluteServletConnection.java?rev=608086&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbsoluteServletConnection.java (added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbsoluteServletConnection.java Wed Jan 2 03:38:10 2008
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.servletservice;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+import org.apache.cocoon.callstack.environment.CallFrameHelper;
+import org.apache.cocoon.servletservice.util.BlockCallHttpServletRequest;
+import org.apache.cocoon.servletservice.util.BlockCallHttpServletResponse;
+import org.springframework.context.ApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+/**
+ * Create a connection to a servlet service. In order to use it, the fully qualified service name
+ * must be available.
+ *
+ * @version $Id$
+ */
+public final class AbsoluteServletConnection extends AbstractServletConnection {
+
+ public static String ABSOLUTE_SERVLET_SOURCE_POSTFIX = "+";
+
+ private Servlet servlet;
+
+ /**
+ * Create an absolute connection to a servlet service.
+ *
+ * @param serviceName The fully qualified service name (= the name of the Spring bean).
+ * @param path The requested path of the service.
+ * @param queryString The query parameters formatted as HTTP request query string.
+ */
+ public AbsoluteServletConnection(String serviceName, String path, String queryString) {
+ if(serviceName == null) {
+ throw new IllegalArgumentException("The serviceName parameter must be passed.");
+ }
+ this.context = CallStackHelper.getBaseServletContext();
+ final ApplicationContext applicationContext = WebApplicationContextUtils
+ .getRequiredWebApplicationContext(this.context);
+ try {
+ this.servlet = (Servlet) applicationContext.getBean(serviceName);
+ } catch(ClassCastException cce) {
+ throw new IllegalArgumentException("The service '" + serviceName + "' is not of type " + Servlet.class.getName() + ".");
+ }
+ if (this.servlet == null) {
+ throw new IllegalArgumentException("The service '" + serviceName + "' does not exist.");
+ }
+
+ URI reqUri = null;
+ try {
+ this.uri = new URI(serviceName, null, path, queryString, null);
+ this.uri = new URI("servlet", this.uri.toASCIIString(), null);
+ reqUri = new URI("servlet", null, path, queryString, null);
+ } catch (URISyntaxException e) {
+ IllegalArgumentException iae = new IllegalArgumentException("Can't create a URI using the passed path '"
+ + path + "' and query string '" + queryString + "' values.");
+ iae.initCause(e);
+ throw iae;
+ }
+ this.request = new BlockCallHttpServletRequest(reqUri, CallFrameHelper.getRequest());
+ this.response = new BlockCallHttpServletResponse();
+ }
+
+ /**
+ * Perform the actual connect that invokes the servlet service.
+ */
+ protected void performConnect() throws ServletException, IOException {
+ try {
+ CallStackHelper.enterServlet(this.context, this.request, this.response);
+ this.servlet.service(this.request, this.response);
+ } finally {
+ CallStackHelper.leaveServlet();
+ }
+ }
+
+}
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbsoluteServletConnection.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbsoluteServletConnection.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbsoluteServletConnection.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/Absolutizable.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/Absolutizable.java?rev=608086&r1=608085&r2=608086&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/Absolutizable.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/Absolutizable.java Wed Jan 2 03:38:10 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.
@@ -20,9 +20,8 @@
import java.net.URISyntaxException;
/**
- * Interface for making the absolute path available from a servlet service relative path.
- * The interface is mainly introduced to make the absoluteizeURI method available when
- * the ServletServiceContext is proxied.
+ * By this interface, a {@link ServletServiceContext} provides absolute information
+ * about a mounted servlet service.
*
* @version $Id$
*/
@@ -37,5 +36,21 @@
* @return absolutized uri
* @throws URISyntaxException
*/
- public URI absolutizeURI(URI uri) throws URISyntaxException;
+ URI absolutizeURI(URI uri) throws URISyntaxException;
+
+ /**
+ * Get the fully qualified servlet service name of a connected service.
+ *
+ * @param connectionName
+ * @return The fully qualified servlet service name of a connected service.
+ */
+ String getServiceName(String connectionName);
+
+ /**
+ * Get the fully qualifed service name.
+ *
+ * @return The fully qualified servlet service name.
+ */
+ String getServiceName();
+
}
Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbstractServletConnection.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbstractServletConnection.java?rev=608086&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbstractServletConnection.java (added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbstractServletConnection.java Wed Jan 2 03:38:10 2008
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.servletservice;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+import org.apache.cocoon.servletservice.util.BlockCallHttpServletRequest;
+import org.apache.cocoon.servletservice.util.BlockCallHttpServletResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @version $Id$
+ */
+public abstract class AbstractServletConnection implements IServletConnection {
+
+ /** By default we use the logger for this class. */
+ protected final Log logger = LogFactory.getLog(this.getClass());
+
+ /** Connection request */
+ protected BlockCallHttpServletRequest request;
+
+ /** Connection response */
+ protected BlockCallHttpServletResponse response;
+
+ /** The current block context */
+ protected ServletContext context;
+
+ /** If already connected */
+ protected boolean connected;
+
+ protected ByteArrayOutputStream requestBody;
+
+ protected InputStream responseBody;
+
+ protected URI uri;
+
+ public void connect() throws IOException, ServletException {
+ // if already connected, do nothing
+ if (this.connected) {
+ return;
+ }
+
+ this.request.setContext(this.context);
+
+ if (this.requestBody != null) {
+ this.request.setMethod("POST");
+ this.request.setInputStream(new ByteArrayInputStream(this.requestBody.toByteArray()));
+ }
+
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ this.response.setOutputStream(os);
+
+ try {
+ performConnect();
+ this.response.flushBuffer();
+ this.responseBody = new ByteArrayInputStream(os.toByteArray());
+ } finally {
+ os.close();
+ }
+
+ this.connected = true;
+ }
+
+ /**
+ * Access the servlet and fill the response object.
+ *
+ * @throws ServletException
+ * @throws IOException
+ */
+ protected abstract void performConnect() throws ServletException, IOException;
+
+ /**
+ * Return an <code>InputStream</code> object to read from the source.
+ *
+ * @throws IOException
+ * @throws ServletException
+ */
+ public InputStream getInputStream() throws IOException, ServletException {
+ this.connect();
+ return this.responseBody;
+ }
+
+ public void setIfModifiedSince(long ifmodifiedsince) {
+ if (this.connected) {
+ throw new IllegalStateException("Already connected");
+ }
+
+ this.request.setDateHeader("If-Modified-Since", ifmodifiedsince);
+ }
+
+ public long getLastModified() {
+ return this.getHeaderFieldDate("Last-Modified", 0);
+ }
+
+ public String getContentType() {
+ return this.getHeaderField("Content-Type");
+ }
+
+ public long getHeaderFieldDate(String name, long Default) {
+ try {
+ return this.response.getDateHeader(name);
+ } catch (Exception e) {
+ // FIXME We should do something about it.
+ }
+
+ return Default;
+ }
+
+ public String getHeaderField(String name) {
+ try {
+ this.connect();
+ } catch (Exception e) {
+ // FIXME We should do something about it.
+ return null;
+ }
+
+ return this.response.getHeader(name);
+ }
+
+ public int getResponseCode() throws IOException {
+ if (!this.connected) {
+ try {
+ this.connect();
+ } catch (ServletException e) {
+ throw new IOException("Could not get response status code");
+ }
+ }
+
+ return this.response.getStatus();
+ }
+
+ /**
+ * Returns an output stream that writes as POST to this connection.
+ *
+ * @return an output stream that writes as POST to this connection.
+ * @throws IllegalStateException -
+ * if already connected
+ */
+ public OutputStream getOutputStream() throws IllegalStateException {
+ if (this.connected) {
+ throw new IllegalStateException("You cannot write to the connection already connected.");
+ }
+
+ if (this.requestBody == null) {
+ this.requestBody = new ByteArrayOutputStream();
+ }
+ return this.requestBody;
+
+ }
+
+ public URI getURI() {
+ return this.uri;
+ }
+
+ /**
+ * A special exception indicating that there is no servlet context available.
+ */
+ protected static class NoServletContextAvailableException extends RuntimeException {
+
+ public NoServletContextAvailableException(String message) {
+ super(message);
+ }
+
+ }
+
+
+}
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbstractServletConnection.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbstractServletConnection.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbstractServletConnection.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java?rev=608086&r1=608085&r2=608086&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java Wed Jan 2 03:38:10 2008
@@ -85,7 +85,7 @@
}
// Create a dynamic proxy class that overwrites the getServletPath and
- // getPathInfo methods to privide reasonable values in the called servlet
+ // getPathInfo methods to provide reasonable values in the called servlet
// the dynamic proxy implements all interfaces of the original request
HttpServletRequest request = (HttpServletRequest) Proxy.newProxyInstance(
req.getClass().getClassLoader(),
Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/IServletConnection.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/IServletConnection.java?rev=608086&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/IServletConnection.java (added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/IServletConnection.java Wed Jan 2 03:38:10 2008
@@ -0,0 +1,101 @@
+package org.apache.cocoon.servletservice;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URLConnection;
+
+import javax.servlet.ServletException;
+
+/**
+ * <p>
+ * Contract to connect to a servlet service. The implementing classes differ from
+ * how they look up the servlet service.
+ * </p>
+ * <p>
+ * This class was designed similar to {@link URLConnection}.
+ * </p>
+ *
+ * @version $Id$
+ */
+public interface IServletConnection {
+
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~ Pre-connect methods ~~~~~~~~~~~~~~~~~~
+
+ /**
+ * Set the last modification date if you want to make use of caching. This
+ * method has to be called before any of the other methods of this interface
+ * is invoked.
+ *
+ * @param ifmodifiedsince
+ * The timestamp of the last known resource.
+ */
+ void setIfModifiedSince(long ifmodifiedsince);
+
+ /**
+ * Get an output stream that writes as POST to this connection.
+ *
+ * @return An output stream that writes as POST to this connection.
+ */
+ OutputStream getOutputStream();
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~ connect method ~~~~~~~~~~~~~~~~~~
+
+ /**
+ * Connect to the servlet service. Establishing a connection means that the
+ * service is executed and the response is available.
+ *
+ * @throws IOException
+ * The connection to the servlet service can't be established.
+ * @throws ServletException
+ * Any other problem when connecting to a servlet service.
+ */
+ void connect() throws IOException, ServletException;
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~ Post-connect methods ~~~~~~~~~~~~~~~~~~
+
+ /**
+ * Read the input stream from the servlet service response.
+ *
+ * @return An input stream on the servlet service response.
+ * @throws IOException
+ * The connection to the servlet service can't be established.
+ * @throws ServletException
+ * Any other problem when connecting to a servlet service.
+ */
+ InputStream getInputStream() throws IOException, ServletException;
+
+ /**
+ *
+ * @return The HTTP status code returned by the servlet service.
+ * @throws IOException
+ */
+ int getResponseCode() throws IOException;
+
+ /**
+ * Get the last modification date of the servlet service.
+ *
+ * @return The last modification date of the servlet service.
+ */
+ long getLastModified();
+
+ /**
+ * Get the mime-type of the servlet-service.
+ *
+ * @return The mime-type of the servlet-service.
+ */
+ String getContentType();
+
+ // ~~~~~~~~~~~~~~~~~~~~~~~~ Idempotent methods ~~~~~~~~~~~~~~~~~~
+
+ /**
+ * Get a URI representing this servlet connection.
+ *
+ * @return a URI representing this servlet connection.
+ */
+ URI getURI();
+
+
+}
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/IServletConnection.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/IServletConnection.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/IServletConnection.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/RelativeServletConnection.java (from r606689, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java)
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/RelativeServletConnection.java?p2=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/RelativeServletConnection.java&p1=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java&r1=606689&r2=608086&rev=608086&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/RelativeServletConnection.java Wed Jan 2 03:38:10 2008
@@ -16,225 +16,90 @@
*/
package org.apache.cocoon.servletservice;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
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 java.net.URLConnection;
import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.apache.cocoon.callstack.environment.CallFrameHelper;
import org.apache.cocoon.servletservice.util.BlockCallHttpServletRequest;
import org.apache.cocoon.servletservice.util.BlockCallHttpServletResponse;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
/**
- * Implementation of a {@link URLConnection} that gets its content by
- * invoking the Block.
- *
- * TODO Plenty of work left to have a meaningfull implementation of all methods
+ * Implementation of a {@link ServletConnection} that gets its content by
+ * invoking the servlet service. It works based on the context of the current
+ * servlet context and its connections.
*
* @version $Id$
*/
-public final class ServletConnection {
+public final class RelativeServletConnection extends AbstractServletConnection {
- /** By default we use the logger for this class. */
- private final Log logger = LogFactory.getLog(getClass());
-
- /** Connection request */
- private BlockCallHttpServletRequest request;
-
- /** Connection response */
- private BlockCallHttpServletResponse response;
-
- /** The name of the called block */
- private String blockName;
-
- /** The current block context */
- private final ServletContext context;
-
- private String systemId;
-
- /** If already connected */
- private boolean connected;
-
- private ByteArrayOutputStream requestBody;
- private InputStream responseBody;
+ private String connectionName;
+ public RelativeServletConnection(String connectionName, String path, String queryString) {
+ // path validation
+ if (path == null) {
+ throw new IllegalArgumentException("Path musn't be null.");
+ }
+ if (!path.startsWith("/")) {
+ throw new IllegalArgumentException(
+ "The path has to start with a slash '/' because it is always absolute within this servlet context.");
+ }
- /**
- * Construct a new object
- */
- public ServletConnection(String url)
- throws MalformedURLException {
+ this.connectionName = connectionName;
- URI blockURI;
+ // setup URI
+ URI reqUri;
try {
- blockURI = parseBlockURI(new URI(url));
+ this.uri = new URI((connectionName != null ? connectionName : "local"), null, path, queryString, null);
+ this.uri = new URI("servlet", this.uri.toASCIIString(), null);
+ reqUri = new URI("servlet", null, path, queryString, null);
} catch (URISyntaxException e) {
- throw new MalformedURLException("Malformed URI in block source " +
- e.getMessage());
+ String message = "Invalid relative servlet service URI created.";
+ this.logger.error(message, e);
+ throw new RuntimeException(message, e);
}
- // Super calls are resolved relative the current context and ordinary
- // calls relative the last non super call in the call chain
- if (ServletServiceContext.SUPER.equals(this.blockName)) {
+ // lookup the servlet context
+ if (ServletServiceContext.SUPER.equals(this.connectionName)) {
+ // Super calls are resolved relative the current context and ordinary
+ // calls relative to the last non super call in the call chain
this.context = CallStackHelper.getCurrentServletContext();
} else {
this.context = CallStackHelper.getBaseServletContext();
}
-
if (this.context == null) {
- throw new MalformedURLException("Must be used in a block context " + url);
+ throw new NoServletContextAvailableException(
+ "A servlet connection can only be used with an available servlet context. [" + this.uri
+ + "]");
}
- this.request = new BlockCallHttpServletRequest(blockURI, CallFrameHelper.getRequest());
+ // prepare request and response objects
+ this.request = new BlockCallHttpServletRequest(reqUri, CallFrameHelper.getRequest());
this.response = new BlockCallHttpServletResponse();
- }
-
- public void connect() throws IOException, ServletException {
- //if already connected, do nothing
- if (connected) {
- return;
- }
-
- if (requestBody != null) {
- request.setMethod("POST");
- request.setInputStream(new ByteArrayInputStream(requestBody.toByteArray()));
- }
-
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- this.response.setOutputStream(os);
- RequestDispatcher dispatcher;
- try {
- if (this.blockName == null) {
- // FIXME Should be called with path + queryString,
- // but the argument is ignored so it doesn't matter
- dispatcher = this.context.getRequestDispatcher(this.systemId);
- } else {
- dispatcher = this.context.getNamedDispatcher(this.blockName);
- }
-
- if (dispatcher == null) {
- throw new ServletException("No dispatcher for " + this.systemId);
- }
- dispatcher.forward(this.request, this.response);
- this.response.flushBuffer();
-
- responseBody = new ByteArrayInputStream(os.toByteArray());
- } finally {
- os.close();
+ if(this.logger.isDebugEnabled()) {
+ this.logger.debug("Resolving relative servlet URI " + this.uri.toASCIIString());
}
-
- connected = true;
}
/**
- * Return an <code>InputStream</code> object to read from the source.
- * @throws IOException
- * @throws ServletException
+ * Perform the actual connect that invokes the servlet service.
*/
- public InputStream getInputStream() throws IOException, ServletException {
- connect();
- return responseBody;
- }
-
- public void setIfModifiedSince(long ifmodifiedsince) {
- if (connected) {
- throw new IllegalStateException("Already connected");
- }
-
- request.setDateHeader("If-Modified-Since", ifmodifiedsince);
- }
-
- public long getLastModified() {
- return getHeaderFieldDate("Last-Modified", 0);
- }
-
- public String getContentType() {
- return getHeaderField("Content-Type");
- }
-
- public long getHeaderFieldDate(String name, long Default) {
- try {
- return response.getDateHeader(name);
- } catch (Exception e) { }
-
- return Default;
- }
-
- public String getHeaderField(String name) {
- try {
- connect();
- } catch (Exception e) {
- return null;
+ protected void performConnect() throws ServletException, IOException {
+ final RequestDispatcher dispatcher;
+ if (this.connectionName == null) {
+ dispatcher = this.context.getRequestDispatcher(null);
+ } else {
+ dispatcher = this.context.getNamedDispatcher(this.connectionName);
}
- return response.getHeader(name);
- }
-
- public int getResponseCode() throws IOException {
- if (!connected) {
- try {
- connect();
- } catch (ServletException e) {
- throw new IOException("Could not get response status code");
- }
+ if (dispatcher == null) {
+ throw new ServletException("No dispatcher for connection" + this.connectionName);
}
-
- return response.getStatus();
+ dispatcher.forward(this.request, this.response);
}
-
- /**
- * Returns an output stream that writes as POST to this connection.
- *
- * @return an output stream that writes as POST to this connection.
- * @throws IllegalStateException - if already connected
- */
- public OutputStream getOutputStream() throws IllegalStateException {
- if (connected) {
- throw new IllegalStateException("You cannot write to the connection already connected.");
- }
- if (requestBody == null) {
- requestBody = new ByteArrayOutputStream();
- }
- return requestBody;
-
- }
-
- // Parse the block protocol.
- private URI parseBlockURI(URI uri) throws URISyntaxException {
- // Can't happen
- if (!uri.isAbsolute()) {
- throw new URISyntaxException(uri.toString(),
- "Only absolute URIs are allowed for the block protocol.");
- }
- String scheme = uri.getScheme();
-
- this.logger.debug("ServletSource: resolving " + uri + " with scheme " +
- uri.getScheme() + " and ssp " + uri.getRawSchemeSpecificPart());
- uri = new URI(uri.getRawSchemeSpecificPart());
- this.logger.debug("ServletSource: resolved to " + uri);
-
- this.blockName = uri.getScheme();
- String path = uri.getPath();
- // All URIs, also relative are resolved and processed from the block manager
- String queryString = uri.getQuery();
-
- // FIXME: This will not be a system global id, as the blockName is block local.
- String ssp = new URI(this.blockName, null, path, queryString, null).toString();
- this.systemId = new URI(scheme, ssp, null).toString();
-
- return new URI(scheme, null, path, queryString, null);
- }
}
Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java?rev=608086&r1=608085&r2=608086&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java Wed Jan 2 03:38:10 2008
@@ -67,6 +67,9 @@
private String contextPath;
private Map properties;
private Map connections;
+ private Map connectionServiceNames;
+
+ private String serviceName;
/*
@@ -75,7 +78,7 @@
* @see javax.servlet.ServletContext#getAttribute(java.lang.String)
*/
/*
- * TODO ineritance of attributes from the parent context is only
+ * TODO inheritance of attributes from the parent context is only
* partly implemented: removeAttribute and getAttributeNames
* doesn't respect inheritance yet.
*/
@@ -156,7 +159,7 @@
this.contextPath);
}
- // prefix the path with the servlet context resolve and resolve in the embeding
+ // prefix the path with the servlet context resolve and resolve in the embedding
// servlet context
return super.getResource(this.contextPath + path);
}
@@ -407,6 +410,14 @@
return new URI(absoluteURI);
}
+ public String getServiceName(String connectionName) {
+ return (String) this.connectionServiceNames.get(connectionName);
+ }
+
+ public String getServiceName() {
+ return this.serviceName;
+ }
+
/**
* Get the context of a servlet service with a given name.
*/
@@ -466,6 +477,20 @@
this.connections = connections;
}
+ /**
+ * @param connections the service names of the connections
+ */
+ public void setConnectionServiceNames(Map connectionServletServiceNames) {
+ this.connectionServiceNames = connectionServletServiceNames;
+ }
+
+ /**
+ * @param serviceName the name of the
+ */
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
protected class NamedDispatcher implements RequestDispatcher {
private String servletServiceName;
@@ -578,6 +603,8 @@
if (_super != null) {
_super.forward(request, wrappedResponse);
} else {
+ wrappedResponse.getWriter().println("Resource not found");
+ wrappedResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
throw se;
}
}
@@ -595,7 +622,7 @@
}
}
- private static class StatusRetrievableWrappedResponse extends HttpServletResponseWrapper {
+ public static class StatusRetrievableWrappedResponse extends HttpServletResponseWrapper {
private int status;
Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletDecorator.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletDecorator.java?rev=608086&r1=608085&r2=608086&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletDecorator.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletDecorator.java Wed Jan 2 03:38:10 2008
@@ -18,9 +18,13 @@
*/
package org.apache.cocoon.servletservice.spring;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
+import org.springframework.beans.factory.config.RuntimeBeanReference;
+import org.springframework.beans.factory.config.TypedStringValue;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
@@ -29,14 +33,20 @@
import org.w3c.dom.Node;
/**
+ * <p>
+ * This {@link BeanDefinitionDecorator} deals with the
+ * <code>http://cocoon.apache.org/schema/servlet</code> namespace which
+ * defines following elements: <code>context</code> : with optional attributes
+ * <code>mountPath</code> and <code>contextPath</code>. With optional sub
+ * elements <code>init-params", "context-params" and "connections".</p>
+ * <p>
+ * The actual creation of the servlet service (= a bean) is done by {@link ServletFactoryBean}.</p>
+ *
* @version $Id$
- * @since 2.2
+ * @since 1.0
*/
public class ServletDecorator implements BeanDefinitionDecorator {
- /* (non-Javadoc)
- * @see org.springframework.beans.factory.xml.BeanDefinitionDecorator#decorate(org.w3c.dom.Node, org.springframework.beans.factory.config.BeanDefinitionHolder, org.springframework.beans.factory.xml.ParserContext)
- */
public BeanDefinitionHolder decorate(Node source, BeanDefinitionHolder holder, ParserContext ctx) {
String embeddedServletBeanName = registerEmbeddedServletBean(holder, ctx);
return createServletFactoryBeanDefinition((Element) source, holder, ctx, embeddedServletBeanName);
@@ -51,10 +61,8 @@
return beanName;
}
- private BeanDefinitionHolder createServletFactoryBeanDefinition(Element source,
- BeanDefinitionHolder holder,
- ParserContext ctx,
- String embeddedServletBeanName) {
+ private BeanDefinitionHolder createServletFactoryBeanDefinition(Element source, BeanDefinitionHolder holder,
+ ParserContext ctx, String embeddedServletBeanName) {
String ns = source.getNamespaceURI();
String mountPath = source.hasAttribute("mount-path") ? source.getAttribute("mount-path") : null;
String contextPath = source.hasAttribute("context-path") ? source.getAttribute("context-path") : null;
@@ -63,11 +71,13 @@
Element contextParamsElem = (Element) source.getElementsByTagNameNS(ns, "context-params").item(0);
Element connectionsElem = (Element) source.getElementsByTagNameNS(ns, "connections").item(0);
- BeanDefinitionBuilder servletFactoryDefBuilder = BeanDefinitionBuilder.rootBeanDefinition(ServletFactoryBean.class);
+ BeanDefinitionBuilder servletFactoryDefBuilder = BeanDefinitionBuilder
+ .rootBeanDefinition(ServletFactoryBean.class);
servletFactoryDefBuilder.setSource(ctx.extractSource(source));
servletFactoryDefBuilder.addPropertyReference("embeddedServlet", embeddedServletBeanName);
servletFactoryDefBuilder.setInitMethodName("init");
servletFactoryDefBuilder.setDestroyMethodName("destroy");
+ servletFactoryDefBuilder.addPropertyValue("serviceName", holder.getBeanName());
if (mountPath != null) {
servletFactoryDefBuilder.addPropertyValue("mountPath", mountPath);
@@ -86,8 +96,29 @@
if (connectionsElem != null) {
Map connections = ctx.getDelegate().parseMapElement(connectionsElem, null);
servletFactoryDefBuilder.addPropertyValue("connections", connections);
+ Map connectionNames = new HashMap();
+ for (Iterator it = connections.keySet().iterator(); it.hasNext();) {
+ TypedStringValue key = (TypedStringValue) it.next();
+ if (key.getValue().endsWith("+")) {
+ throw new InvalidBeanReferenceNameException(
+ "The key of a servlet connection mustn't use '+' as its last character. "
+ + "This is reserved for absolute references in servlet sources.");
+ }
+ RuntimeBeanReference beanNameReference = (RuntimeBeanReference) connections.get(key);
+ connectionNames.put(key.getValue(), beanNameReference.getBeanName());
+ }
+ servletFactoryDefBuilder.addPropertyValue("connectionServiceNames", connectionNames);
}
return new BeanDefinitionHolder(servletFactoryDefBuilder.getBeanDefinition(), holder.getBeanName());
}
+
+ private class InvalidBeanReferenceNameException extends RuntimeException {
+
+ public InvalidBeanReferenceNameException(String message) {
+ super(message);
+ }
+
+ }
+
}
Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java?rev=608086&r1=608085&r2=608086&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java Wed Jan 2 03:38:10 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.
@@ -62,10 +62,11 @@
private Map initParams;
private Map contextParams;
private Map connections;
+ private Map connectionServiceNames;
+ private String serviceName;
private ServletServiceContext servletServiceContext;
-
public ServletFactoryBean() {
}
@@ -78,14 +79,15 @@
this.servletServiceContext.setInitParams(this.initParams);
this.servletServiceContext.setAttributes(this.contextParams);
- this.servletServiceContext.setConnections(connections);
-
- // create a sub container that resolves paths relative to the block
- // context rather than the parent context and make it available in
- // a context attribute
+ this.servletServiceContext.setConnections(this.connections);
+ this.servletServiceContext.setConnectionServiceNames(this.connectionServiceNames);
+ this.servletServiceContext.setServiceName(this.serviceName);
+
+ // create a sub container that resolves paths relative to the servlet
+ // service context rather than the parent context and make it available
+ // in a context attribute
if (this.parentContainer == null) {
- this.parentContainer =
- WebApplicationContextUtils.getRequiredWebApplicationContext(this.servletContext);
+ this.parentContainer = WebApplicationContextUtils.getRequiredWebApplicationContext(this.servletContext);
}
GenericWebApplicationContext container = new GenericWebApplicationContext();
@@ -124,23 +126,14 @@
this.embeddedServlet.destroy();
}
- /* (non-Javadoc)
- * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
- */
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.parentContainer = applicationContext;
}
- /* (non-Javadoc)
- * @see org.springframework.web.context.ServletContextAware#setServletContext(javax.servlet.ServletContext)
- */
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
}
- /* (non-Javadoc)
- * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
- */
public void setBeanName(String beanName) {
this.beanName = beanName;
}
@@ -189,9 +182,17 @@
this.connections = connections;
}
- /* (non-Javadoc)
- * @see org.springframework.beans.factory.FactoryBean#getObject()
+ /**
+ * @param connectionServiceNames
*/
+ public void setConnectionServiceNames(Map connectionServiceNames) {
+ this.connectionServiceNames = connectionServiceNames;
+ }
+
+ public void setServiceName(String name) {
+ this.serviceName = name;
+ }
+
public Object getObject() throws Exception {
ProxyFactory proxyFactory = new ProxyFactory(this.embeddedServlet);
proxyFactory.addAdvice(new ServiceInterceptor());
@@ -201,25 +202,16 @@
return proxyFactory.getProxy();
}
- /* (non-Javadoc)
- * @see org.springframework.beans.factory.FactoryBean#getObjectType()
- */
public Class getObjectType() {
return this.embeddedServlet != null ? this.embeddedServlet.getClass() : null;
}
- /* (non-Javadoc)
- * @see org.springframework.beans.factory.FactoryBean#isSingleton()
- */
public boolean isSingleton() {
return true;
}
private class ServiceInterceptor implements MethodInterceptor {
- /* (non-Javadoc)
- * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
- */
public Object invoke(MethodInvocation invocation) throws Throwable {
if ("service".equals(invocation.getMethod().getName())) {
Object[] arguments = invocation.getArguments();
@@ -231,7 +223,7 @@
return null;
} else if ("init".equals(invocation.getMethod().getName())) {
// The embedded servlet is initialized by this factory bean, ignore other containers
- return null;
+ return null;
} else if ("destroy".equals(invocation.getMethod().getName())) {
// The embedded servlet is destroyed up by this factory bean, ignore other containers
return null;
@@ -255,4 +247,5 @@
super(new MountableMixin(), Mountable.class);
}
}
+
}
Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletNamespaceHandler.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletNamespaceHandler.java?rev=608086&r1=608085&r2=608086&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletNamespaceHandler.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletNamespaceHandler.java Wed Jan 2 03:38:10 2008
@@ -21,21 +21,16 @@
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
/**
- * Spring namespace handler for the cocoon servlet namespace.
- * Currently this namespace defines the following elements
- * (in the namespace "http://cocoon.apache.org/schema/servlet"):
- * "context" : with optional attributes "mountPath" and "contextPath".
- * With optional sub elements "init-params", "context-params" and
- * "connections".
+ * <p>
+ * Spring namespace handler for the Cocoon servlet namespace (<code>http://cocoon.apache.org/schema/servlet</code>).
+ * The {@link ServletDecorator} deals with the implementation details.
*
- * @version $Id$
+ * @version $Id: ServletNamespaceHandler.java 562806 2007-08-05 02:26:41Z
+ * vgritsenko $
* @since 2.2
*/
public class ServletNamespaceHandler extends NamespaceHandlerSupport {
- /* (non-Javadoc)
- * @see org.springframework.beans.factory.xml.NamespaceHandler#init()
- */
public void init() {
registerBeanDefinitionDecorator("context", new ServletDecorator());
}