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 2009/04/15 12:33:44 UTC
svn commit: r765123 - in /cocoon/cocoon3/trunk: cocoon-docs/src/changes/
cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/
cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/
cocoon-sample/src/main/resources/META-INF/cocoon/spring/
Author: reinhard
Date: Wed Apr 15 10:33:44 2009
New Revision: 765123
URL: http://svn.apache.org/viewvc?rev=765123&view=rev
Log:
COCOON3-32
Check if a REST controller is a proxy. If it is one use the target object to apply the supported annotations.
Added:
cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTControllerAspect1.java (with props)
cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTControllerAspect2.java (with props)
Modified:
cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml
cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java
cocoon/cocoon3/trunk/cocoon-sample/src/main/resources/META-INF/cocoon/spring/cocoon-sample-controller.xml
Modified: cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml?rev=765123&r1=765122&r2=765123&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml Wed Apr 15 10:33:44 2009
@@ -107,11 +107,14 @@
by reference and get an InputStream of a resource.
</action>
- <action dev="reinhard" type="update">
- [cocoon-rest] Introduce the interface org.apache.cocoon.rest.controller.response.StreamingResponse that
- can be used for controller results. The most prominent use case for it is the
- org.apache.cocoon.rest.controller.response.UrlResponse (before it was named 'PageResult' which is a
- misleading name).
+ <action dev="reinhard" type="add">
+ [cocoon-rest] Support for JAX-RS (JSR 311) controllers as an alternative to the Cocoon specific REST support.
+ The implementation is based on Jersey, the JSR311 reference implementation and the Jersey Spring extensions.
+ </action>
+ <action dev="stevendolg" type="update">
+ [cocoon-rest] Changed RestResponse to make it easier to implement specific response implementations.
+ Processing the responses no longer requires the SpringRESTController to actually know anything about
+ the actual implementation. RestResponse requires the implementation of the method execute(outputStream, parameters).
</action>
<action dev="reinhard" type="add">
[cocoon-rest] The ControllerContextHelper provides a static method to directly store a context
@@ -124,6 +127,10 @@
[cocoon-rest] The @Inject annotation supports org.apache.cocoon.configuration.Settings and
javax.servlet.ServletContext injections.
</action>
+ <action dev="stevendolg" type="fix" issue="COCOON3-32">
+ [cocoon-rest] Check if a REST controller is a proxy. If it is one use the target object to apply the supported
+ annotations.
+ </action>
<action dev="reinhard" type="add" issue="COCOON3-7" due-to="Simone Tripodi">
[cocoon-optional] Add a formatting objects serializer using Apache FOP.
Modified: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java?rev=765123&r1=765122&r2=765123&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java (original)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java Wed Apr 15 10:33:44 2009
@@ -47,6 +47,7 @@
import org.apache.cocoon.sitemap.util.ExceptionHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.springframework.aop.framework.Advised;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@@ -109,16 +110,16 @@
private Object getController(String controllerName, Map<String, Object> inputParameters,
Map<String, ? extends Object> configuration) throws Exception {
Object controller = this.applicationContext.getBean(controllerName);
-
+ Object unpackedController = unpackProxy(controller);
Map<Class<? extends Annotation>, List<Field>> annotatedFields = this.annotationCollector
- .getAnnotatedFields(controller.getClass());
+ .getAnnotatedFields(unpackedController.getClass());
// populate the annotated fields
- populateInjectFields(inputParameters, controller, annotatedFields);
- populateRequestFields(inputParameters, controller, annotatedFields);
- populateRequestHeaderFields(inputParameters, controller, annotatedFields);
- populateSitemapParameters(configuration, controller, annotatedFields);
- this.populateBaseURL(configuration, controller, annotatedFields);
+ populateInjectFields(inputParameters, unpackedController, annotatedFields);
+ populateRequestFields(inputParameters, unpackedController, annotatedFields);
+ populateRequestHeaderFields(inputParameters, unpackedController, annotatedFields);
+ populateSitemapParameters(configuration, unpackedController, annotatedFields);
+ this.populateBaseURL(configuration, unpackedController, annotatedFields);
return controller;
}
@@ -142,7 +143,29 @@
+ fieldType.getName() + ")");
}
}
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> T unpackProxy(T proxy) throws Exception {
+ if (proxy instanceof Advised) {
+ Advised advised = (Advised) proxy;
+ return (T) advised.getTargetSource().getTarget();
+ }
+ return proxy;
+ }
+
+ private static boolean isBlank(String str) {
+ int strLen;
+ if (str == null || (strLen = str.length()) == 0) {
+ return true;
+ }
+ for (int i = 0; i < strLen; i++) {
+ if (Character.isWhitespace(str.charAt(i)) == false) {
+ return false;
+ }
+ }
+ return true;
}
private static void populateInjectFields(Map<String, ? extends Object> parameters, Object controller,
@@ -285,17 +308,4 @@
}
}
}
-
- private static boolean isBlank(String str) {
- int strLen;
- if (str == null || (strLen = str.length()) == 0) {
- return true;
- }
- for (int i = 0; i < strLen; i++) {
- if (Character.isWhitespace(str.charAt(i)) == false) {
- return false;
- }
- }
- return true;
- }
}
Added: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTControllerAspect1.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTControllerAspect1.java?rev=765123&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTControllerAspect1.java (added)
+++ cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTControllerAspect1.java Wed Apr 15 10:33:44 2009
@@ -0,0 +1,39 @@
+/*
+ * 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.sample.controller;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+
+@Aspect
+public class DemoRESTControllerAspect1 {
+
+ private final Log logger = LogFactory.getLog(this.getClass());
+
+ @Around("bean(org.apache.cocoon.sample.controller.DemoRESTController)")
+ public Object someTestAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
+ this.logger.info("Going through around advice 1 - start");
+ try {
+ return proceedingJoinPoint.proceed();
+ } finally {
+ this.logger.info("Going through around advice 1 - end");
+ }
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTControllerAspect1.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTControllerAspect1.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTControllerAspect1.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTControllerAspect2.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTControllerAspect2.java?rev=765123&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTControllerAspect2.java (added)
+++ cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTControllerAspect2.java Wed Apr 15 10:33:44 2009
@@ -0,0 +1,39 @@
+/*
+ * 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.sample.controller;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+
+@Aspect
+public class DemoRESTControllerAspect2 {
+
+ private final Log logger = LogFactory.getLog(this.getClass());
+
+ @Around("bean(org.apache.cocoon.sample.controller.DemoRESTController)")
+ public Object someTestAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
+ this.logger.info("Going through around advice 2 - start");
+ try {
+ return proceedingJoinPoint.proceed();
+ } finally {
+ this.logger.info("Going through around advice 2 - end");
+ }
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTControllerAspect2.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTControllerAspect2.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTControllerAspect2.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cocoon/cocoon3/trunk/cocoon-sample/src/main/resources/META-INF/cocoon/spring/cocoon-sample-controller.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sample/src/main/resources/META-INF/cocoon/spring/cocoon-sample-controller.xml?rev=765123&r1=765122&r2=765123&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sample/src/main/resources/META-INF/cocoon/spring/cocoon-sample-controller.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-sample/src/main/resources/META-INF/cocoon/spring/cocoon-sample-controller.xml Wed Apr 15 10:33:44 2009
@@ -33,6 +33,9 @@
scope-resolver="org.apache.cocoon.rest.controller.ControllerBeanScopeResolver">
<context:include-filter type="annotation" expression="org.apache.cocoon.rest.controller.annotation.RESTController" />
</context:component-scan>
+
<context:annotation-config />
-
+
+ <bean id="org.apache.cocoon.sample.controller.aspect1" class="org.apache.cocoon.sample.controller.DemoRESTControllerAspect1" />
+ <bean id="org.apache.cocoon.sample.controller.aspect2" class="org.apache.cocoon.sample.controller.DemoRESTControllerAspect2" />
</beans>