Browse files

Added libraries and test case.

  • Loading branch information...
1 parent 6fefe68 commit a822ee458086d04840cc702a8297a96aa850b22a @bmuschko committed Apr 10, 2012
View
31 test/org/apache/catalina/loader/TestHandleTypesWebappLoader.java
@@ -0,0 +1,31 @@
+package org.apache.catalina.loader;
+
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.junit.Test;
+
+import java.io.File;
+
+public class TestHandleTypesWebappLoader extends TomcatBaseTest {
+ public static final String TEST_DIR = "test/webapp-3.0-spring";
+
+ @Test
+ public void testStartInternal() throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+ StandardContext context = (StandardContext)tomcat.addWebapp(null, "/spring", TEST_DIR + "/src/main/webapp");
+ context.setLoader(new WebappLoader());
+ context.setUnpackWAR(false);
+ context.getLoader().addRepository(new File(TEST_DIR, "/src/main/java").toURI().toURL().toString());
+ context.getLoader().addRepository(new File(TEST_DIR, "/src/main/resources").toURI().toURL().toString());
+
+ File folder = new File(TEST_DIR, "/lib");
+ File[] libs = folder.listFiles();
+
+ for(File lib : libs) {
+ context.getLoader().addRepository(lib.toURI().toURL().toString());
+ }
+
+ tomcat.start();
+ }
+}
View
BIN test/webapp-3.0-spring/lib/aopalliance-1.0.jar
Binary file not shown.
View
BIN test/webapp-3.0-spring/lib/commons-logging-1.1.1.jar
Binary file not shown.
View
BIN test/webapp-3.0-spring/lib/jcl-over-slf4j-1.6.4.jar
Binary file not shown.
View
BIN test/webapp-3.0-spring/lib/logback-classic-1.0.0.jar
Binary file not shown.
View
BIN test/webapp-3.0-spring/lib/logback-core-1.0.0.jar
Binary file not shown.
View
BIN test/webapp-3.0-spring/lib/slf4j-api-1.6.4.jar
Binary file not shown.
View
BIN test/webapp-3.0-spring/lib/spring-aop-3.1.1.RELEASE.jar
Binary file not shown.
View
BIN test/webapp-3.0-spring/lib/spring-asm-3.1.1.RELEASE.jar
Binary file not shown.
View
BIN test/webapp-3.0-spring/lib/spring-beans-3.1.1.RELEASE.jar
Binary file not shown.
View
BIN test/webapp-3.0-spring/lib/spring-context-3.1.1.RELEASE.jar
Binary file not shown.
View
BIN test/webapp-3.0-spring/lib/spring-context-support-3.1.1.RELEASE.jar
Binary file not shown.
View
BIN test/webapp-3.0-spring/lib/spring-core-3.1.1.RELEASE.jar
Binary file not shown.
View
BIN test/webapp-3.0-spring/lib/spring-expression-3.1.1.RELEASE.jar
Binary file not shown.
View
BIN test/webapp-3.0-spring/lib/spring-web-3.1.1.RELEASE.jar
Binary file not shown.
View
BIN test/webapp-3.0-spring/lib/spring-webmvc-3.1.1.RELEASE.jar
Binary file not shown.
View
15 test/webapp-3.0-spring/src/main/java/org/apache/tomcat/spring/example/IndexController.java
@@ -0,0 +1,15 @@
+package org.apache.tomcat.spring.example;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.servlet.ModelAndView;
+
+@Controller
+public class IndexController {
+ @RequestMapping(value = "/index.htm")
+ public ModelAndView indexPage() {
+ ModelAndView modelAndView = new ModelAndView("/WEB-INF/jsp/index.jsp");
+ modelAndView.addObject("var", "Hello!");
+ return modelAndView;
+ }
+}
View
34 ...rc/main/java/org/apache/tomcat/spring/example/SpringExampleWebApplicationInitializer.java
@@ -0,0 +1,34 @@
+package org.apache.tomcat.spring.example;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRegistration;
+
+import org.springframework.web.WebApplicationInitializer;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+import org.springframework.web.servlet.DispatcherServlet;
+
+import org.apache.tomcat.spring.example.config.WebMvcContextConfiguration;
+
+public class SpringExampleWebApplicationInitializer implements WebApplicationInitializer {
+ @Override
+ public void onStartup(final ServletContext servletContext) throws ServletException {
+ registerDispatcherServlet(servletContext);
+ }
+
+ private void registerDispatcherServlet(final ServletContext servletContext) {
+ WebApplicationContext dispatcherContext = createContext(WebMvcContextConfiguration.class);
+ DispatcherServlet dispatcherServlet = new DispatcherServlet(dispatcherContext);
+ ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", dispatcherServlet);
+ dispatcher.setLoadOnStartup(1);
+ dispatcher.addMapping("*.htm");
+ }
+
+ private WebApplicationContext createContext(final Class<?>... annotatedClasses) {
+ AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
+ context.register(annotatedClasses);
+ context.getEnvironment().setActiveProfiles("local");
+ return context;
+ }
+}
View
14 ...ing/src/main/java/org/apache/tomcat/spring/example/config/WebMvcContextConfiguration.java
@@ -0,0 +1,14 @@
+package org.apache.tomcat.spring.example.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import org.apache.tomcat.spring.example.IndexController;
+
+@Configuration
+public class WebMvcContextConfiguration {
+ @Bean
+ public IndexController indexController() {
+ return new IndexController();
+ }
+}
View
23 test/webapp-3.0-spring/src/main/resources/logback.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<configuration>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+ <file>pizzas-r-us.log</file>
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <logger name="org.springframework" level="INFO" />
+ <logger name="com.apache.tomcat.spring.example" level="DEBUG" />
+
+ <root level="WARN">
+ <appender-ref ref="STDOUT" />
+ <appender-ref ref="FILE" />
+ </root>
+</configuration>
View
10 test/webapp-3.0-spring/src/main/webapp/WEB-INF/jsp/index.jsp
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ <title>Welcome</title>
+ </head>
+ <body>
+ <p>Welcome from Spring through embedded Tomcat!</p>
+ <br/>
+ <p>Passed down variable: ${var}</p>
+ </body>
+</html>

0 comments on commit a822ee4

Please sign in to comment.