You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by ma...@apache.org on 2012/08/09 14:06:47 UTC
svn commit: r1371176 - in /rave/sandbox/content-services/rave-web-hmvc: ./
src/main/java/org/apache/rave/portal/web/hmvc/
src/main/java/org/apache/rave/portal/web/hmvc/support/
src/test/java/org/apache/rave/portal/web/hmvc/ src/test/resources/
Author: marijan
Date: Thu Aug 9 12:06:46 2012
New Revision: 1371176
URL: http://svn.apache.org/viewvc?rev=1371176&view=rev
Log:
- dynamic mapping skeleton
Added:
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMappingByConfig.java (with props)
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMappingByConfigTest.java (with props)
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/TestController.java (with props)
rave/sandbox/content-services/rave-web-hmvc/src/test/resources/test-config.xml (with props)
Modified:
rave/sandbox/content-services/rave-web-hmvc/pom.xml
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodHandlerAdapter.java
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMapping.java
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/support/ResponseHolder.java
rave/sandbox/content-services/rave-web-hmvc/src/test/resources/log4j.xml
Modified: rave/sandbox/content-services/rave-web-hmvc/pom.xml
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/pom.xml?rev=1371176&r1=1371175&r2=1371176&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-web-hmvc/pom.xml (original)
+++ rave/sandbox/content-services/rave-web-hmvc/pom.xml Thu Aug 9 12:06:46 2012
@@ -36,6 +36,11 @@
<dependencies>
<dependency>
+ <groupId>org.apache.rave.sandbox.jcr</groupId>
+ <artifactId>rave-jcr-config</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.rave</groupId>
<artifactId>rave-core</artifactId>
<version>${apache.rave.version}</version>
Modified: rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodHandlerAdapter.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodHandlerAdapter.java?rev=1371176&r1=1371175&r2=1371176&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodHandlerAdapter.java (original)
+++ rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodHandlerAdapter.java Thu Aug 9 12:06:46 2012
@@ -31,14 +31,14 @@ public class HmvcHandlerMethodHandlerAda
protected boolean supportsInternal(HandlerMethod handlerMethod) {
return handlerMethod instanceof HmvcHandlerMethod;
}
-
+
@Override
protected ModelAndView handleInternal(HttpServletRequest request, HttpServletResponse response,
- HandlerMethod handlerMethod) throws Exception {
- HmvcHandlerMethod hm = (HmvcHandlerMethod)handlerMethod;
+ HandlerMethod handlerMethod) throws Exception {
+ HmvcHandlerMethod hm = (HmvcHandlerMethod) handlerMethod;
ModelAndView mv = super.handleInternal(request, response, handlerMethod);
- Map<String, ModelAndView> cmvMap = new LinkedHashMap<String,ModelAndView>();
+ Map<String, ModelAndView> cmvMap = new LinkedHashMap<String, ModelAndView>();
for (String name : hm.getChildrenNames()) {
HmvcHandlerMethod chm = hm.getChild(name);
ModelAndView cmv = handleInternal(request, response, chm);
@@ -46,13 +46,13 @@ public class HmvcHandlerMethodHandlerAda
cmvMap.put(name, cmv);
}
}
-
+
if (mv == null) {
mv = new ModelAndView();
}
-
+
mv.getModelMap().addAttribute(HmvcHandlerMethod.MODEL_AND_VIEW, cmvMap);
-
+
return mv;
}
}
Modified: rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMapping.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMapping.java?rev=1371176&r1=1371175&r2=1371176&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMapping.java (original)
+++ rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMapping.java Thu Aug 9 12:06:46 2012
@@ -78,11 +78,15 @@ public class HmvcHandlerMethodMapping ex
// assuming for now this to be the only/single @RequestMapping HandlerMethod for a @HController type
// if more than one is defined it might/should cause a conflict on url pattern already,
// if we ignore the other differentiators like method parameters etc.
- super.registerHandlerMethod(handler, method, mapping);
+ registerHandler(handler, method, mapping);
HandlerMethod handlerMethod = super.getHandlerMethods().get(mapping);
hmvcHandlerMethods.put(handlerMethod, getHmvcHandlerMethod(handler, method));
}
+ protected void registerHandler(Object handler, Method method, RequestMappingInfo mapping) {
+ super.registerHandlerMethod(handler, method, mapping);
+ }
+
protected HmvcHandlerMethod getHmvcHandlerMethod(Object handler, Method method) {
Class<?> handlerType = getBeanType(handler);
HController hcontroller = AnnotationUtils.findAnnotation(handlerType, HController.class);
@@ -141,4 +145,8 @@ public class HmvcHandlerMethodMapping ex
}
return (handlerMethod != null) ? handlerMethod.createWithResolvedBean() : null;
}
+
+ public Map<HandlerMethod, HmvcHandlerMethod> getHmvcHandlerMethods() {
+ return hmvcHandlerMethods;
+ }
}
Added: rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMappingByConfig.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMappingByConfig.java?rev=1371176&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMappingByConfig.java (added)
+++ rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMappingByConfig.java Thu Aug 9 12:06:46 2012
@@ -0,0 +1,216 @@
+/*
+ * 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.rave.portal.web.hmvc;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.rave.jcr.config.model.JcrPageConfiguration;
+import org.apache.rave.jcr.config.model.JcrPageDefinition;
+import org.apache.rave.jcr.config.model.JcrPageFragment;
+import org.apache.rave.jcr.config.model.api.PageConfiguration;
+import org.apache.rave.jcr.config.model.api.PageDefinition;
+import org.apache.rave.jcr.config.model.api.PageFragment;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.util.ClassUtils;
+import org.springframework.util.ReflectionUtils;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.method.HandlerMethod;
+import org.springframework.web.method.HandlerMethodSelector;
+import org.springframework.web.servlet.mvc.condition.ConsumesRequestCondition;
+import org.springframework.web.servlet.mvc.condition.HeadersRequestCondition;
+import org.springframework.web.servlet.mvc.condition.ParamsRequestCondition;
+import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
+import org.springframework.web.servlet.mvc.condition.ProducesRequestCondition;
+import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition;
+import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
+
+/**
+ * @version "$Id$"
+ */
+public class HmvcHandlerMethodMappingByConfig extends HmvcHandlerMethodMapping {
+
+ private static final Logger log = LoggerFactory.getLogger(HmvcHandlerMethodMappingByConfig.class);
+
+
+ private String configurationName;
+ private String user;
+ private String password;
+
+ @Override
+ protected void initHandlerMethods() {
+
+
+ log.info("@parsing configuration");
+ // TODO wire & inject configuration manager
+ /*final Session session = new SessionImpl();
+ final ConfigManager manager = new JcrConfigManager(session, "/raveconfig");
+ */
+
+ final PageConfiguration configuration = new JcrPageConfiguration();
+ final PageDefinition myPage = new JcrPageDefinition();
+ myPage.setName("myPage");
+ myPage.setPath("/mypage2");
+ myPage.setController("org.apache.rave.portal.web.hmvc.example.MyPageController");
+ configuration.addPageDefinition(myPage);
+ //add kids:
+ final PageFragment myHeader = new JcrPageFragment();
+ myHeader.setName("head");
+ myHeader.setPath("myHeader");
+ myHeader.setController("org.apache.rave.portal.web.hmvc.example.MyHeaderController");
+ myPage.addChild(myHeader);
+ final PageFragment myBody = new JcrPageFragment();
+ myBody.setName("body");
+ myBody.setPath("myBody");
+ myBody.setController("org.apache.rave.portal.web.hmvc.example.MyBodyController");
+ myPage.addChild(myBody);
+ //
+ final PageFragment myMenu = new JcrPageFragment();
+ myMenu.setName("menu");
+ myMenu.setPath("myMenu");
+ myMenu.setController("org.apache.rave.portal.web.hmvc.example.MyMenuController");
+ myBody.addChild(myMenu);
+ final PageFragment myContent = new JcrPageFragment();
+ myContent.setName("content");
+ myContent.setPath("myContent");
+ myContent.setController("org.apache.rave.portal.web.hmvc.example.MyContentController");
+ myBody.addChild(myContent);
+ processConfiguration(configuration);
+ }
+
+ private void processConfiguration(PageConfiguration configuration) {
+ final List<PageDefinition> pageDefinitions = configuration.getPageDefinitions();
+ for (PageDefinition pageDefinition : pageDefinitions) {
+ final String controller = pageDefinition.getController();
+ log.info("Processing controller [ {} ]", controller);
+ final Class<?> clazz = classFromString(controller);
+ if (clazz != null) {
+ final Class<?> userType = ClassUtils.getUserClass(clazz);
+ Set<Method> methods = HandlerMethodSelector.selectMethods(userType, new ReflectionUtils.MethodFilter() {
+ public boolean matches(Method method) {
+ final RequestMapping annotation = AnnotationUtils.findAnnotation(method, RequestMapping.class);
+ return annotation != null;
+ }
+ });
+ // take first
+ if (methods.iterator().hasNext()) {
+ if (methods.size() > 1) {
+ log.warn("Found more than one @RequestMapping annotated methods: we'll use first one");
+ }
+ final Method method = methods.iterator().next();
+ final RequestMapping annotation = AnnotationUtils.findAnnotation(method, RequestMapping.class);
+ final RequestMappingInfo mappingInfo = createMappingInfo(annotation, pageDefinition);
+ try {
+ final Object handler = userType.newInstance();
+ registerFragment(pageDefinition, handler, method, mappingInfo);
+ } catch (InstantiationException e) {
+ log.error("Error", e);
+ } catch (IllegalAccessException e) {
+ log.error("Error", e);
+ }
+
+ }
+ }
+ }
+ }
+
+
+ protected void registerFragment(PageFragment fragment, Object handler, Method method, RequestMappingInfo mapping) {
+ registerHandler(handler, method, mapping);
+ HandlerMethod handlerMethod = super.getHandlerMethods().get(mapping);
+ getHmvcHandlerMethods().put(handlerMethod, getHmvcHandlerMethodForFragment(handler, method, fragment));
+ }
+
+
+ private HmvcHandlerMethod getHmvcHandlerMethodForFragment(Object handler, Method method, PageFragment fragment) {
+ Map<String, HmvcHandlerMethod> controllerMethods = new HashMap<String, HmvcHandlerMethod>();
+ final List<PageFragment> children = fragment.getChildren();
+ for (PageFragment child : children) {
+ Class<?> clazz = classFromString(child.getController());
+ if (clazz == null) {
+ continue;
+ }
+ Method renderMethod = getCCRenderMethod(clazz);
+ if (renderMethod != null) {
+ Object ccInstance;
+ try {
+ ccInstance = clazz.newInstance();
+ } catch (Exception e) {
+ throw new IllegalStateException("Cannot instantiate found CController");
+ }
+ log.info("@@@ Registering child component [{}] for parent [{}] ", child.getName(), fragment.getName());
+ controllerMethods.put(child.getName(), getHmvcHandlerMethodForFragment(ccInstance, renderMethod, child));
+ }
+
+ }
+ return new HmvcHandlerMethod(handler, method, controllerMethods);
+ }
+
+
+ //*************************************************************************************
+ // UTILITIES
+ //*************************************************************************************
+ private Class<?> classFromString(String controller) {
+ try {
+ return Class.forName(controller);
+ } catch (ClassNotFoundException e) {
+ if (log.isDebugEnabled()) {
+ log.error("Could not find class", e);
+ } else {
+ log.error("Could not find class for controller: {}", controller);
+ }
+ }
+ return null;
+ }
+
+
+ private RequestMappingInfo createMappingInfo(RequestMapping annotation, PageFragment pageDefinition) {
+ final String[] patterns = {pageDefinition.getPath()};
+ log.info("Creating mapping for patterns:[{}]", patterns);
+ final PatternsRequestCondition requestCondition = new PatternsRequestCondition(
+ patterns, getUrlPathHelper(), getPathMatcher(), useSuffixPatternMatch(), useTrailingSlashMatch());
+ return new RequestMappingInfo(
+ requestCondition,
+ new RequestMethodsRequestCondition(annotation.method()),
+ new ParamsRequestCondition(annotation.params()),
+ new HeadersRequestCondition(annotation.headers()),
+ new ConsumesRequestCondition(annotation.consumes(), annotation.headers()),
+ new ProducesRequestCondition(annotation.produces(), annotation.headers()),
+ null);
+ }
+
+
+ public void setConfigurationName(String configurationName) {
+ this.configurationName = configurationName;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+}
\ No newline at end of file
Propchange: rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMappingByConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMappingByConfig.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/support/ResponseHolder.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/support/ResponseHolder.java?rev=1371176&r1=1371175&r2=1371176&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/support/ResponseHolder.java (original)
+++ rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/support/ResponseHolder.java Thu Aug 9 12:06:46 2012
@@ -50,12 +50,12 @@ public class ResponseHolder {
private Locale defaultLocale;
private boolean flushed;
-
+
private ByteArrayOutputStream byteOutputBuffer;
private CharArrayWriterBuffer charOutputBuffer;
private ServletOutputStream outputStream;
private PrintWriter printWriter;
-
+
private Map<String, List<String>> addedHeaders;
private Map<String, List<String>> setHeaders;
private List<Cookie> cookies;
@@ -74,17 +74,17 @@ public class ResponseHolder {
private int statusCode;
private final HttpServletResponse response;
-
+
private String redirectLocation;
-
+
private String forwardPathInfo;
private String formatDateHeaderValue(long date) {
- DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
- dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
- return dateFormat.format(new Date(date));
+ DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
+ dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
+ return dateFormat.format(new Date(date));
}
-
+
public ResponseHolder(HttpServletResponse response) {
this.response = response;
this.defaultLocale = null;
@@ -94,14 +94,14 @@ public class ResponseHolder {
if (addedHeaders == null) {
addedHeaders = new HashMap<String, List<String>>();
}
-
+
List<String> headerList = addedHeaders.get(name);
-
+
if (headerList == null && create) {
headerList = new ArrayList<String>();
addedHeaders.put(name, headerList);
}
-
+
return headerList;
}
@@ -109,14 +109,14 @@ public class ResponseHolder {
if (setHeaders == null) {
setHeaders = new HashMap<String, List<String>>();
}
-
+
List<String> headerList = setHeaders.get(name);
-
+
if (headerList == null && create) {
headerList = new ArrayList<String>();
setHeaders.put(name, headerList);
}
-
+
return headerList;
}
@@ -205,16 +205,16 @@ public class ResponseHolder {
public int getErrorCode() {
return this.errorCode;
}
-
+
public String getErrorMessage() {
return this.errorMessage;
}
-
+
/*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletResponseWrapper#sendRedirect(java.lang.String)
- */
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletResponseWrapper#sendRedirect(java.lang.String)
+ */
public void sendRedirect(String redirectLocation) throws IOException {
failIfCommitted();
closed = true;
@@ -222,30 +222,30 @@ public class ResponseHolder {
this.redirectLocation = redirectLocation;
}
-
+
public String getRedirectLocation() {
return redirectLocation;
}
public void forward(String pathInfo) throws IOException {
if (response instanceof HmvcServletResponse) {
- ((HmvcServletResponse)response).forward(pathInfo);
+ ((HmvcServletResponse) response).forward(pathInfo);
}
failIfCommitted();
closed = true;
committed = true;
forwardPathInfo = pathInfo;
}
-
+
public String getForwardPathInfo() {
return forwardPathInfo;
}
-
+
/*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletResponseWrapper#setDateHeader(java.lang.String, long)
- */
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletResponseWrapper#setDateHeader(java.lang.String, long)
+ */
public void setDateHeader(String name, long date) {
setHeader(name, formatDateHeaderValue(date));
}
@@ -290,7 +290,7 @@ public class ResponseHolder {
public void setStatus(int statusCode) {
if (!committed) {
if (response instanceof HmvcServletResponse) {
- ((HmvcServletResponse)response).setStatus(statusCode);
+ response.setStatus(statusCode);
} else {
this.statusCode = statusCode;
hasStatus = true;
@@ -530,7 +530,7 @@ public class ResponseHolder {
statusCode = 0;
redirectLocation = null;
}
-
+
public void flush() throws IOException {
if (flushed) {
//throw new IllegalStateException("Already flushed");
@@ -629,43 +629,43 @@ public class ResponseHolder {
protected void setResponseLocale(Locale locale) {
this.response.setLocale(locale);
}
-
+
protected void addResponseCookie(Cookie cookie) {
this.response.addCookie(cookie);
}
-
+
protected void setResponseCharacterEncoding(String characterEncoding) {
this.response.setCharacterEncoding(characterEncoding);
}
-
+
protected void setResponseContentType(String contentType) {
this.response.setContentType(contentType);
}
-
+
protected void addResponseHeader(String name, String value) {
this.response.addHeader(name, value);
}
-
+
protected void setResponseHeader(String name, String value) {
this.response.setHeader(name, value);
}
-
+
protected void setResponseStatus(int status) {
this.response.setStatus(status);
}
-
+
protected void setResponseContentLength(int len) {
this.response.setContentLength(len);
}
-
+
protected OutputStream getResponseOutputStream() throws IOException {
return this.response.getOutputStream();
}
-
+
protected PrintWriter getResponseWriter() throws IOException {
return this.response.getWriter();
}
-
+
//*************************************************************************************
// HELP CLASSES
//*************************************************************************************
Added: rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMappingByConfigTest.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMappingByConfigTest.java?rev=1371176&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMappingByConfigTest.java (added)
+++ rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMappingByConfigTest.java Thu Aug 9 12:06:46 2012
@@ -0,0 +1,105 @@
+/*
+ * 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.rave.portal.web.hmvc;
+
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.rave.portal.web.hmvc.example.MyPageController;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.web.servlet.HandlerExecutionChain;
+import org.springframework.web.servlet.HandlerMapping;
+import org.springframework.web.servlet.ModelAndView;
+
+import static junit.framework.Assert.assertTrue;
+import static org.springframework.test.web.ModelAndViewAssert.assertViewName;
+
+/**
+ * @version "$Id$"
+ */
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration({"classpath:test-config.xml"})
+public class HmvcHandlerMethodMappingByConfigTest {
+ private static Logger log = LoggerFactory.getLogger(HmvcHandlerMethodMappingByConfigTest.class);
+
+ @Autowired
+ private ApplicationContext applicationContext;
+ private MockHttpServletRequest request;
+ private MockHttpServletResponse response;
+ private HmvcHandlerMethodHandlerAdapter handlerAdapter;
+ //<bean name="handlerAdapter" class="org.apache.rave.portal.web.hmvc.HmvcHandlerMethodHandlerAdapter"/>
+
+ private MyPageController controller;
+
+
+ @Before
+ public void setUp() throws Exception {
+ request = new MockHttpServletRequest();
+ response = new MockHttpServletResponse();
+ handlerAdapter = (HmvcHandlerMethodHandlerAdapter) applicationContext.getBean("handlerAdapter");
+ controller = new MyPageController();
+
+ }
+
+ @Test
+ public void testRegistering() throws Exception {
+
+ final String requestUri = "/mypage2";
+ request.setRequestURI(requestUri);
+ final Object handler = this.getHandler(request);
+ HmvcHandlerMethod handlerMethod = (HmvcHandlerMethod) handler;
+ final ModelAndView mav = handlerAdapter.handle(request, response, handlerMethod);
+ final Set<String> childrenNames = handlerMethod.getChildrenNames();
+ assertTrue("Expected 2 child names", childrenNames.size() == 2);
+ assertTrue("Expected body", childrenNames.contains("body"));
+ assertTrue("Expected head", childrenNames.contains("head"));
+ final HmvcHandlerMethod child = handlerMethod.getChild("body");
+ final Set<String> bodyKids = child.getChildrenNames();
+ assertTrue("body should have two nodes", bodyKids.size() == 2);
+ assertTrue("body should have menu", bodyKids.contains("menu"));
+ assertTrue("body should have content", bodyKids.contains("content"));
+ assertViewName(mav, "mypage");
+ }
+
+
+ private Object getHandler(HttpServletRequest request) throws Exception {
+ Map<String, HandlerMapping> map = applicationContext.getBeansOfType(HandlerMapping.class);
+ for (HandlerMapping mapping : map.values()) {
+ HandlerExecutionChain chain = mapping.getHandler(request);
+ if (chain != null) {
+ return chain.getHandler();
+ }
+ }
+ return null;
+ }
+}
Propchange: rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMappingByConfigTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/HmvcHandlerMethodMappingByConfigTest.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/TestController.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/TestController.java?rev=1371176&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/TestController.java (added)
+++ rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/TestController.java Thu Aug 9 12:06:46 2012
@@ -0,0 +1,33 @@
+/*
+ * 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.rave.portal.web.hmvc;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version "$Id$"
+ */
+
+public class TestController {
+
+ private static Logger log = LoggerFactory.getLogger(TestController.class);
+
+}
Propchange: rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/TestController.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/TestController.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: rave/sandbox/content-services/rave-web-hmvc/src/test/resources/log4j.xml
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/test/resources/log4j.xml?rev=1371176&r1=1371175&r2=1371176&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-web-hmvc/src/test/resources/log4j.xml (original)
+++ rave/sandbox/content-services/rave-web-hmvc/src/test/resources/log4j.xml Thu Aug 9 12:06:46 2012
@@ -22,38 +22,42 @@
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
- <!-- ====================================================================== -->
- <!-- A P P E N D E R S -->
- <!-- ====================================================================== -->
-
-
- <!-- console -->
- <appender name="console" class="org.apache.log4j.ConsoleAppender">
- <param name="Target" value="System.out"/>
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%-5p - [%-80m] - at %c.%M(%F:%L)%n"/>
- </layout>
- <filter class="org.apache.log4j.varia.LevelRangeFilter">
- <param name="levelMin" value="DEBUG"/>
- </filter>
- </appender>
-
- <!-- ====================================================================== -->
- <!-- L O G G E R S -->
- <!-- ====================================================================== -->
-
- <category name="org.apache.jackrabbit">
- <level value="warn"/>
- </category>
-
- <category name="org.apache.rave.portal.web.hmvc">
- <level value="debug"/>
- </category>
-
- <root>
- <level value="debug"/>
- <appender-ref ref="console"/>
- </root>
+ <!-- ====================================================================== -->
+ <!-- A P P E N D E R S -->
+ <!-- ====================================================================== -->
+
+
+ <!-- console -->
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out"/>
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%-5p - [%-80m] - at %c.%M(%F:%L)%n"/>
+ </layout>
+ <filter class="org.apache.log4j.varia.LevelRangeFilter">
+ <param name="levelMin" value="DEBUG"/>
+ </filter>
+ </appender>
+
+ <!-- ====================================================================== -->
+ <!-- L O G G E R S -->
+ <!-- ====================================================================== -->
+
+ <category name="org.apache.jackrabbit">
+ <level value="warn"/>
+ </category>
+
+ <category name="org.springframework">
+ <level value="warn"/>
+ </category>
+
+ <category name="org.apache.rave.portal.web.hmvc">
+ <level value="debug"/>
+ </category>
+
+ <root>
+ <level value="debug"/>
+ <appender-ref ref="console"/>
+ </root>
</log4j:configuration>
Added: rave/sandbox/content-services/rave-web-hmvc/src/test/resources/test-config.xml
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/test/resources/test-config.xml?rev=1371176&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-web-hmvc/src/test/resources/test-config.xml (added)
+++ rave/sandbox/content-services/rave-web-hmvc/src/test/resources/test-config.xml Thu Aug 9 12:06:46 2012
@@ -0,0 +1,48 @@
+<!--
+ 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:mvc="http://www.springframework.org/schema/mvc"
+ xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+
+ <context:component-scan base-package="org.apache.rave.portal.web.hmvc"/>
+
+ <!-- Configures the @Controller programming model -->
+ <mvc:annotation-driven/>
+
+ <!-- Resolves view names to protected .jsp resources within the /WEB-INF/jsp/hmvc directory -->
+ <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
+ <property name="prefix" value="/WEB-INF/jsp/hmvc/"/>
+ <property name="suffix" value=".jsp"/>
+ </bean>
+
+ <!--<bean name="handlerMapping" class="org.apache.rave.portal.web.hmvc.HmvcHandlerMethodMapping" />-->
+ <bean name="handlerMapping" class="org.apache.rave.portal.web.hmvc.HmvcHandlerMethodMappingByConfig">
+ <property name="configurationName" value="myConfiguration"/>
+ <property name="user" value="admin"/>
+ <property name="password" value="admin"/>
+ </bean>
+ <bean name="handlerAdapter" class="org.apache.rave.portal.web.hmvc.HmvcHandlerMethodHandlerAdapter"/>
+
+
+</beans>
+
Propchange: rave/sandbox/content-services/rave-web-hmvc/src/test/resources/test-config.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-web-hmvc/src/test/resources/test-config.xml
------------------------------------------------------------------------------
svn:keywords = Id