Repository: olingo-odata4 Updated Branches: refs/heads/master cc0a6a51a -> 69659a1a9
[OLINGO-1004] refactored embedded tomcat modified pom to write properties to a file. refactored the embedded tomcat to use those properties. Signed-off-by: Christian Amend <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/69659a1a Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/69659a1a Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/69659a1a Branch: refs/heads/master Commit: 69659a1a9027d6eb8e758694be20fd8198197c91 Parents: cc0a6a5 Author: Morten Riedel <[email protected]> Authored: Tue Oct 18 14:39:24 2016 +0200 Committer: Christian Amend <[email protected]> Committed: Wed Oct 19 14:35:03 2016 +0200 ---------------------------------------------------------------------- fit/pom.xml | 48 ++++++++++++++------ .../olingo/fit/server/TomcatTestServer.java | 32 ++++++------- fit/src/main/resources/tomcat-fit.properties | 21 --------- fit/src/main/resources/tomcat-users.xml | 28 ------------ 4 files changed, 49 insertions(+), 80 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69659a1a/fit/pom.xml ---------------------------------------------------------------------- diff --git a/fit/pom.xml b/fit/pom.xml index ffb8599..7316376 100644 --- a/fit/pom.xml +++ b/fit/pom.xml @@ -39,6 +39,9 @@ <sonar.skip>true</sonar.skip> <!-- exclude proxy tests by default --> <exclude.regex>.*proxy.*</exclude.regex> + <project-web-app-dir>${project.build.directory}/${project.build.finalName}</project-web-app-dir> + <tomcat-base-dir>${project.build.directory}/emb-tom-fit</tomcat-base-dir> + <project-resource-dir>${project.build.outputDirectory}</project-resource-dir> </properties> <profiles> @@ -122,19 +125,6 @@ <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-jasper</artifactId> - <exclusions> - <exclusion> - <groupId>javax.servlet</groupId> - <artifactId>javax.servlet-api</artifactId> - </exclusion> - </exclusions> - </dependency> - - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.5</version> - <scope>provided</scope> </dependency> <dependency> @@ -194,10 +184,40 @@ <skip>true</skip> </configuration> </plugin> + + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>properties-maven-plugin</artifactId> + <version>1.0.0</version> + <executions> + <execution> + <phase>generate-resources</phase> + <goals> + <goal>write-project-properties</goal> + </goals> + <configuration> + <outputFile> + ${project.build.outputDirectory}/mavenBuild.properties + </outputFile> + </configuration> + </execution> + </executions> + </plugin> + <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> + <systemPropertyVariables> + <property> + <propertyName>buildDirectory</propertyName> + <buildDirectory>${project.build.directory}</buildDirectory> + </property> + <property> + <propertyName>finalName</propertyName> + <buildDirectory>${project.build.finalName}</buildDirectory> + </property> + </systemPropertyVariables> <includes> <include>**/*ITCase.java</include> <include>**/*Test.java</include> @@ -205,7 +225,7 @@ <excludes> <exclude>%regex[${exclude.regex}]</exclude> </excludes> - </configuration> + </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69659a1a/fit/src/main/java/org/apache/olingo/fit/server/TomcatTestServer.java ---------------------------------------------------------------------- diff --git a/fit/src/main/java/org/apache/olingo/fit/server/TomcatTestServer.java b/fit/src/main/java/org/apache/olingo/fit/server/TomcatTestServer.java index 7d1ed46..9d2c4e4 100644 --- a/fit/src/main/java/org/apache/olingo/fit/server/TomcatTestServer.java +++ b/fit/src/main/java/org/apache/olingo/fit/server/TomcatTestServer.java @@ -48,7 +48,6 @@ import org.apache.catalina.Context; import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleState; import org.apache.catalina.loader.WebappLoader; -import org.apache.catalina.realm.MemoryRealm; import org.apache.catalina.startup.Tomcat; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -151,9 +150,9 @@ public class TomcatTestServer { } public static class TestServerBuilder { - private static final String TOMCAT_BASE_DIR = "TOMCAT_BASE_DIR"; - private static final String PROJECT_WEB_APP_DIR = "PROJECT_WEB_APP_DIR"; - private static final String PROJECT_RESOURCES_DIR = "PROJECT_RESOURCES_DIR"; + private static final String TOMCAT_BASE_DIR = "tomcat-base-dir"; + private static final String PROJECT_RESOURCES_DIR = "project-resource-dir"; + private static final String PROJECT_WEB_APP_DIR = "project-web-app-dir"; private final Tomcat tomcat; private final File baseDir; @@ -163,7 +162,6 @@ public class TomcatTestServer { private TestServerBuilder(final int fixedPort) { initializeProperties(); - // baseDir = new File(System.getProperty("java.io.tmpdir"), "tomcat-test"); baseDir = getFileForDirProperty(TOMCAT_BASE_DIR); if (!baseDir.exists() && !baseDir.mkdirs()) { throw new RuntimeException("Unable to create temporary test directory at {" + baseDir.getAbsolutePath() + "}"); @@ -173,7 +171,6 @@ public class TomcatTestServer { throw new RuntimeException("Unable to load resources"); } - final String TOMCAT_USERS_XML = "tomcat-users.xml"; tomcat = new Tomcat(); tomcat.setBaseDir(baseDir.getParentFile().getAbsolutePath()); tomcat.setPort(fixedPort); @@ -181,17 +178,17 @@ public class TomcatTestServer { tomcat.getHost().setDeployOnStartup(true); tomcat.getConnector().setSecure(false); tomcat.setSilent(true); - // tomcat.addUser("odatajclient", "odatajclient"); - // tomcat.addRole("odatajclient", "odatajclient"); - String tomcatUserPath = resourceDir.getPath() + File.separator + TOMCAT_USERS_XML; - MemoryRealm realm = new MemoryRealm(); - realm.setPathname(tomcatUserPath); - tomcat.getEngine().setRealm(realm); + tomcat.addUser("odatajclient", "odatajclient"); + tomcat.addRole("odatajclient", "odatajclient"); } private void initializeProperties() { + /* + * The property file is build with a maven plugin (properties-maven-plugin) defined in pom.xml of the FIT module. + * Since the property file is build with maven its located inside the resource folder of the project. + */ InputStream propertiesFile = - Thread.currentThread().getContextClassLoader().getResourceAsStream("tomcat-fit.properties"); + Thread.currentThread().getContextClassLoader().getResourceAsStream("mavenBuild.properties"); try { properties = new Properties(); properties.load(propertiesFile); @@ -222,6 +219,7 @@ public class TomcatTestServer { } public TestServerBuilder addWebApp(final boolean copy) throws IOException { + if (server != null) { return this; } @@ -240,6 +238,7 @@ public class TomcatTestServer { } String contextPath = "/stub"; + Context context = tomcat.addWebapp(tomcat.getHost(), contextPath, webAppDir.getAbsolutePath()); context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader())); LOG.info("Webapp {} at context {}.", webAppDir.getName(), contextPath); @@ -285,11 +284,11 @@ public class TomcatTestServer { return this; } final String TOMCAT_WEB_XML = "web.xml"; - String webxmluri = resourceDir.getPath() + File.separator + TOMCAT_WEB_XML; + String webXMLPath = Thread.currentThread().getContextClassLoader().getResource(TOMCAT_WEB_XML).getPath(); String servletClassname = factoryClass.getName(); HttpServlet httpServlet = (HttpServlet) Class.forName(servletClassname).newInstance(); Context cxt = tomcat.addWebapp(servletPath, baseDir.getAbsolutePath()); - cxt.setAltDDName(webxmluri); + cxt.setAltDDName(webXMLPath); String randomServletId = UUID.randomUUID().toString(); Tomcat.addServlet(cxt, randomServletId, httpServlet); cxt.addServletMapping(contextPath, randomServletId); @@ -298,8 +297,7 @@ public class TomcatTestServer { } public TestServerBuilder addStaticContent(final String uri, final String resourceName) throws IOException { - File targetResourcesDir = getFileForDirProperty(PROJECT_RESOURCES_DIR); - String resource = new File(targetResourcesDir, resourceName).getAbsolutePath(); + String resource = new File(resourceDir, resourceName).getAbsolutePath(); LOG.info("Added static content from '{}' at uri '{}'.", resource, uri); StaticContent staticContent = new StaticContent(uri, resource); return addServlet(staticContent, String.valueOf(uri.hashCode()), uri); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69659a1a/fit/src/main/resources/tomcat-fit.properties ---------------------------------------------------------------------- diff --git a/fit/src/main/resources/tomcat-fit.properties b/fit/src/main/resources/tomcat-fit.properties deleted file mode 100644 index acebff4..0000000 --- a/fit/src/main/resources/tomcat-fit.properties +++ /dev/null @@ -1,21 +0,0 @@ -# -# 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. -# -TOMCAT_BASE_DIR=${project.build.directory}/emb-tom-fit -PROJECT_WEB_APP_DIR=${project.build.directory}/${project.build.finalName} -PROJECT_RESOURCES_DIR=${project.build.outputDirectory} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69659a1a/fit/src/main/resources/tomcat-users.xml ---------------------------------------------------------------------- diff --git a/fit/src/main/resources/tomcat-users.xml b/fit/src/main/resources/tomcat-users.xml deleted file mode 100644 index d70e63c..0000000 --- a/fit/src/main/resources/tomcat-users.xml +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version='1.0' encoding='utf-8'?> -<!-- - - 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. - ---> -<tomcat-users> - <role rolename="manager-gui"/> - <role rolename="odatajclient"/> - - <user name="admin" password="" roles="manager-gui"/> - <user name="odatajclient" password="odatajclient" roles="odatajclient"/> -</tomcat-users>
