+ @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];
+ }
+