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.net.URL;
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.FileResource;
30 import org.eclipse.jetty.util.resource.Resource;
31 import org.eclipse.jetty.webapp.WebAppContext;
32 import org.eclipse.jetty.xml.XmlConfiguration;
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public class GlobalWebappConfigBinding implements AppLifeCycle.Binding
49 {
50 private static final Logger LOG = Log.getLogger(GlobalWebappConfigBinding.class);
51
52
53 private String _jettyXml;
54
55 public String getJettyXml()
56 {
57 return _jettyXml;
58 }
59
60 public void setJettyXml(String jettyXml)
61 {
62 this._jettyXml = jettyXml;
63 }
64
65 public String[] getBindingTargets()
66 {
67 return new String[] { "deploying" };
68 }
69
70 public void processBinding(Node node, App app) throws Exception
71 {
72 ContextHandler handler = app.getContextHandler();
73 if (handler == null)
74 {
75 throw new NullPointerException("No Handler created for App: " + app);
76 }
77
78 if (handler instanceof WebAppContext)
79 {
80 WebAppContext context = (WebAppContext)handler;
81
82 if (LOG.isDebugEnabled())
83 {
84 LOG.debug("Binding: Configuring webapp context with global settings from: " + _jettyXml);
85 }
86
87 if ( _jettyXml == null )
88 {
89 LOG.warn("Binding: global context binding is enabled but no jetty-web.xml file has been registered");
90 }
91
92 Resource globalContextSettings = Resource.newResource(_jettyXml);
93
94 if (globalContextSettings.exists())
95 {
96 XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings.getInputStream());
97
98 jettyXmlConfig.configure(context);
99 }
100 else
101 {
102 LOG.info("Binding: Unable to locate global webapp context settings: " + _jettyXml);
103 }
104 }
105 }
106
107 }