]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - server/runtime/org.argeo.server.webextender/src/main/java/org/argeo/server/webextender/TomcatDeployer.java
f20ceb13fe48096931a88d2218e0f8e04c36ed29
2 * Copyright (C) 2007-2012 Mathieu Baudier
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
= "/org.argeo.rap.webapp";
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 if (log
.isTraceEnabled())
43 log
.trace("Argeo modified Tomcat deployer used");
47 protected String
getServerInfo() {
52 protected void startDeployment(WarDeployment deployment
) throws Exception
{
53 // Context context = ((TomcatWarDeployment)
54 // deployment).getCatalinaContext();
55 // context.setCookies(false);
56 super.startDeployment(deployment
);
58 // Required for multiple RAP sessions to work with Tomcat
60 // http://wiki.eclipse.org/RAP/FAQ#How_to_run_a_RAP_application_in_multiple_browser_tabs.2Fwindows.3F
61 Context context
= getContext(contextPath
);
63 context
.setCookies(false);
66 /** @return null if not found */
67 private Context
getContext(String path
) {
68 for (Container container
: getHost().findChildren()) {
69 if (log
.isTraceEnabled())
70 log
.trace(container
.getClass() + ": " + container
.getName());
71 if (container
instanceof Context
) {
72 Context context
= (Context
) container
;
73 if (path
.equals(context
.getPath()))
80 private Container
getHost() {
82 Container container
= service
.getContainer();
84 if (container
== null)
85 throw new IllegalStateException(
86 "The Tomcat server doesn't have any Engines defined");
88 Container
[] children
= container
.findChildren();
89 if (ObjectUtils
.isEmpty(children
))
90 throw new IllegalStateException(
91 "The Tomcat server doesn't have any Hosts defined");
93 // pick the first one and associate the context with it
97 public void setContextPath(String contextPath
) {
98 this.contextPath
= contextPath
;