Improve RAP deployment in Tomcat
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 2 Jun 2011 08:08:42 +0000 (08:08 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 2 Jun 2011 08:08:42 +0000 (08:08 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@4553 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

eclipse/features/org.argeo.eclipse.dep.rap/pom.xml
security/features/org.argeo.security.dep.node.rap/pom.xml
server/modules/org.argeo.server.tomcat/conf/server.xml
server/runtime/org.argeo.server.webextender/pom.xml
server/runtime/org.argeo.server.webextender/src/main/java/org/argeo/server/webextender/TomcatDeployer.java

index bad03f41911f4d7da6af97327118eb08924e9213..3e00bc17ef6d5ccc0a3709e9e644c6030dbe1493 100644 (file)
@@ -74,7 +74,7 @@
                        <groupId>org.eclipse.rap</groupId>
                        <artifactId>org.eclipse.rap.ui.views</artifactId>
                </dependency>
-               <!-- Jetty -->
+               <!-- Jetty (TO BE REMOVED and replaced by Tomcat -->
                <dependency>
                        <groupId>org.eclipse.equinox</groupId>
                        <artifactId>org.eclipse.equinox.http.jetty</artifactId>
index 1b251d5aec82919994da890cd46c2cb749cb4a2b..85771e6b87c1fa361c445b0a08ace7923694c09d 100644 (file)
                <!-- For Tomcat deployment -->
                <dependency>
                        <groupId>org.argeo.commons.server</groupId>
-                       <artifactId>org.argeo.server.osgi.webapp</artifactId>
+                       <artifactId>org.argeo.server.rap.webapp</artifactId>
                        <version>${version.argeo-commons}</version>
                </dependency>
 
index f79a912441dd8422bd1c6419c9c0ce6adee0143f..14c4b9ebc5be5317111cd23ac8210b560bc583a2 100644 (file)
                        -->
                        <Host name="localhost" appBase="webapps" unpackWARs="true"
                                autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"
-                               workDir="${argeo.osgi.data.dir}/tomcat/work">
-
+                               workDir="work">
                                <!--
                                        SingleSignOn valve, share authentication between web applications
                                        Documentation at: /docs/config/valve.html
index 9ad34dc3441e7426de2077582fd7089a5f473ff4..d83db445089e33f18afd0475c54d85726d52fa1d 100644 (file)
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
                <groupId>org.argeo.commons.server</groupId>
                        <groupId>org.springframework</groupId>
                        <artifactId>org.springframework.beans</artifactId>
                </dependency>
+               <dependency>
+                       <groupId>org.eclipse.osgi</groupId>
+                       <artifactId>org.eclipse.osgi</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>javax.servlet</groupId>
+                       <artifactId>com.springsource.javax.servlet</artifactId>
+               </dependency>
                <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
index f93a5f3e50141b2a82fb1bd603ecb390a6024be8..c41351dc0083440165d534fb75e2ab2431f9db53 100644 (file)
@@ -1,20 +1,27 @@
 package org.argeo.server.webextender;
 
+import org.apache.catalina.Container;
+import org.apache.catalina.Context;
 import org.apache.catalina.Service;
+import org.springframework.osgi.web.deployer.WarDeployment;
 import org.springframework.osgi.web.deployer.tomcat.TomcatWarDeployer;
+import org.springframework.util.ObjectUtils;
 
 /**
  * Wraps the Spring DM Tomcat deployer in order to avoid issue with call to
- * getServerInfo() when undeployed.
+ * getServerInfo() when undeployed. We need to hack a lot here because Spring
+ * OSGi Web is really not extendable.
  */
 public class TomcatDeployer extends TomcatWarDeployer {
        private String serverInfo;
+       private Service service;
 
        @Override
        public void setService(Object service) {
+               this.service = (Service) service;
                super.setService(service);
                // TODO: listen to OSGi service so that we get notified in the
-               // (unlikely) cae the underlying service is update
+               // (unlikely) case the underlying service is updated
                serverInfo = ((Service) service).getInfo();
                if (log.isDebugEnabled())
                        log.debug("Argeo modified Tomcat deployer used");
@@ -25,4 +32,50 @@ public class TomcatDeployer extends TomcatWarDeployer {
                return serverInfo;
        }
 
+       @Override
+       protected void startDeployment(WarDeployment deployment) throws Exception {
+               // Context context = ((TomcatWarDeployment)
+               // deployment).getCatalinaContext();
+               // context.setCookies(false);
+               super.startDeployment(deployment);
+
+               // Required for multiple RAP sessions to work with Tomcat
+               // see
+               // http://wiki.eclipse.org/RAP/FAQ#How_to_run_a_RAP_application_in_multiple_browser_tabs.2Fwindows.3F
+               // TODO make it configurable in order to cover other web apps
+               Context context = getContext("/org.argeo.rap.webapp");
+               if (context != null)
+                       context.setCookies(false);
+       }
+
+       /** @return null if not found */
+       private Context getContext(String path) {
+               for (Container container : getHost().findChildren()) {
+                       log.debug(container.getClass() + ": " + container.getName());
+                       if (container instanceof Context) {
+                               Context context = (Context) container;
+                               if (path.equals(context.getPath()))
+                                       return context;
+                       }
+               }
+               return null;
+       }
+
+       private Container getHost() {
+               // get engine
+               Container container = service.getContainer();
+
+               if (container == null)
+                       throw new IllegalStateException(
+                                       "The Tomcat server doesn't have any Engines defined");
+               // now get host
+               Container[] children = container.findChildren();
+               if (ObjectUtils.isEmpty(children))
+                       throw new IllegalStateException(
+                                       "The Tomcat server doesn't have any Hosts defined");
+
+               // pick the first one and associate the context with it
+               return children[0];
+       }
+
 }