]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - server/runtime/org.argeo.server.webextender/src/main/java/org/argeo/server/webextender/TomcatDeployer.java
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.server
.webextender
;
18 import org
.apache
.catalina
.Container
;
19 import org
.apache
.catalina
.Context
;
20 import org
.apache
.catalina
.Service
;
21 import org
.springframework
.osgi
.web
.deployer
.WarDeployment
;
22 import org
.springframework
.osgi
.web
.deployer
.tomcat
.TomcatWarDeployer
;
23 import org
.springframework
.util
.ObjectUtils
;
26 * Wraps the Spring DM Tomcat deployer in order to avoid issue with call to
27 * getServerInfo() when undeployed. We need to hack a lot here because Spring
28 * OSGi Web is really not extendable.
30 public class TomcatDeployer
extends TomcatWarDeployer
{
31 private String serverInfo
;
32 private Service service
;
33 private String contextPath
= "/ui";
36 public void setService(Object service
) {
37 this.service
= (Service
) service
;
38 super.setService(service
);
39 // TODO: listen to OSGi service so that we get notified in the
40 // (unlikely) case the underlying service is updated
41 serverInfo
= ((Service
) service
).getInfo();
42 log
.info("Enhanced Argeo Tomcat webapp deployer being used");
46 protected String
getServerInfo() {
51 protected void startDeployment(WarDeployment deployment
) throws Exception
{
52 // Context context = ((TomcatWarDeployment)
53 // deployment).getCatalinaContext();
54 // context.setCookies(false);
55 super.startDeployment(deployment
);
57 // Required for multiple RAP sessions to work with Tomcat
59 // http://wiki.eclipse.org/RAP/FAQ#How_to_run_a_RAP_application_in_multiple_browser_tabs.2Fwindows.3F
60 Context context
= getContext(contextPath
);
62 context
.setCookies(false);
65 /** @return null if not found */
66 private Context
getContext(String path
) {
67 for (Container container
: getHost().findChildren()) {
68 if (log
.isTraceEnabled())
69 log
.trace(container
.getClass() + ": " + container
.getName());
70 if (container
instanceof Context
) {
71 Context context
= (Context
) container
;
72 if (path
.equals(context
.getPath()))
79 private Container
getHost() {
81 Container container
= service
.getContainer();
83 if (container
== null)
84 throw new IllegalStateException(
85 "The Tomcat server doesn't have any Engines defined");
87 Container
[] children
= container
.findChildren();
88 if (ObjectUtils
.isEmpty(children
))
89 throw new IllegalStateException(
90 "The Tomcat server doesn't have any Hosts defined");
92 // pick the first one and associate the context with it
96 public void setContextPath(String contextPath
) {
97 this.contextPath
= contextPath
;