1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.deploy.bindings;
20
21 import java.io.File;
22
23 import org.eclipse.jetty.deploy.App;
24 import org.eclipse.jetty.deploy.AppLifeCycle;
25 import org.eclipse.jetty.deploy.graph.Node;
26 import org.eclipse.jetty.server.handler.ContextHandler;
27 import org.eclipse.jetty.util.log.Log;
28 import org.eclipse.jetty.util.log.Logger;
29 import org.eclipse.jetty.util.resource.Resource;
30 import org.eclipse.jetty.webapp.WebAppContext;
31 import org.eclipse.jetty.xml.XmlConfiguration;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public class GlobalWebappConfigBinding implements AppLifeCycle.Binding
48 {
49 private static final Logger LOG = Log.getLogger(GlobalWebappConfigBinding.class);
50
51
52 private String _jettyXml;
53
54 public String getJettyXml()
55 {
56 return _jettyXml;
57 }
58
59 public void setJettyXml(String jettyXml)
60 {
61 this._jettyXml = jettyXml;
62 }
63
64 public String[] getBindingTargets()
65 {
66 return new String[] { "deploying" };
67 }
68
69 public void processBinding(Node node, App app) throws Exception
70 {
71 ContextHandler handler = app.getContextHandler();
72 if (handler == null)
73 {
74 throw new NullPointerException("No Handler created for App: " + app);
75 }
76
77 if (handler instanceof WebAppContext)
78 {
79 WebAppContext context = (WebAppContext)handler;
80
81 if (LOG.isDebugEnabled())
82 {
83 LOG.debug("Binding: Configuring webapp context with global settings from: " + _jettyXml);
84 }
85
86 if ( _jettyXml == null )
87 {
88 LOG.warn("Binding: global context binding is enabled but no jetty-web.xml file has been registered");
89 }
90
91 Resource globalContextSettings = Resource.newResource(_jettyXml);
92
93 if (globalContextSettings.exists())
94 {
95 XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings.getInputStream());
96
97 Resource resource = Resource.newResource(app.getOriginId());
98 File file = resource.getFile();
99 jettyXmlConfig.getIdMap().put("Server",app.getDeploymentManager().getServer());
100 jettyXmlConfig.getProperties().put("jetty.home",System.getProperty("jetty.home","."));
101 jettyXmlConfig.getProperties().put("jetty.base",System.getProperty("jetty.base","."));
102 jettyXmlConfig.getProperties().put("jetty.webapp",file.getCanonicalPath());
103 jettyXmlConfig.getProperties().put("jetty.webapps",file.getParentFile().getCanonicalPath());
104
105 jettyXmlConfig.configure(context);
106 }
107 else
108 {
109 LOG.info("Binding: Unable to locate global webapp context settings: " + _jettyXml);
110 }
111 }
112 }
113
114 }