1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.container.servlet.internal

File DefaultServletContainerInitializer.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
22
5
1
137
85
9
0.41
4.4
5
1.8

Classes

Class Line # Actions
DefaultServletContainerInitializer 46 22 0% 9 2
0.935483993.5%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.container.servlet.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Singleton;
24    import javax.servlet.ServletContext;
25    import javax.servlet.http.HttpServletRequest;
26    import javax.servlet.http.HttpServletResponse;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.component.manager.ComponentManager;
30    import org.xwiki.container.ApplicationContext;
31    import org.xwiki.container.ApplicationContextListenerManager;
32    import org.xwiki.container.Container;
33    import org.xwiki.container.RequestInitializerManager;
34    import org.xwiki.container.servlet.ServletApplicationContext;
35    import org.xwiki.container.servlet.ServletContainerException;
36    import org.xwiki.container.servlet.ServletContainerInitializer;
37    import org.xwiki.container.servlet.ServletRequest;
38    import org.xwiki.container.servlet.ServletResponse;
39    import org.xwiki.container.servlet.ServletSession;
40    import org.xwiki.context.Execution;
41    import org.xwiki.context.ExecutionContext;
42    import org.xwiki.context.ExecutionContextManager;
43   
44    @Component
45    @Singleton
 
46    public class DefaultServletContainerInitializer implements ServletContainerInitializer
47    {
48    // Implementation note: It's important that we don't use @Inject annotations here
49    // for RequestInitializerManager and ExecutionContextManager since we can have
50    // RequestInitializer and ExecutionContextInitializer components which try to access
51    // the Application Context in their initialize() method and we need it to be available
52    // (i.e. initializeApplicationContext() needs to have been called) before they are
53    // looked up (and thus initialized).
54   
55    @Inject
56    private ApplicationContextListenerManager applicationContextListenerManager;
57   
58    @Inject
59    private Container container;
60   
61    @Inject
62    private Execution execution;
63   
64    @Inject
65    private ComponentManager componentManager;
66   
67    /**
68    * @deprecated starting with 3.5M1, use the notion of Environment instead
69    */
 
70  116 toggle @Deprecated
71    @Override
72    public void initializeApplicationContext(ServletContext servletContext)
73    {
74  116 ApplicationContext applicationContext = new ServletApplicationContext(servletContext, this.componentManager);
75  116 this.container.setApplicationContext(applicationContext);
76  116 this.applicationContextListenerManager.initializeApplicationContext(applicationContext);
77    }
78   
 
79  13127 toggle @Override
80    public void initializeRequest(HttpServletRequest httpServletRequest, Object xwikiContext)
81    throws ServletContainerException
82    {
83    // 1) Create an empty request. From this point forward request initializers can use the
84    // Container object to get any data they want from the Request.
85  13137 this.container.setRequest(new ServletRequest(httpServletRequest));
86   
87    // 2) Create an empty Execution context so that the Container initializers can put things in the
88    // execution context when they execute.
89  13147 this.execution.setContext(new ExecutionContext());
90   
91    // 3) Bridge with old code to play well with new components. Old code relies on the
92    // XWikiContext object whereas new code uses the Container component.
93  13124 if (xwikiContext != null) {
94  11415 ExecutionContext ec = this.execution.getContext();
95  11414 String key = "xwikicontext";
96  11412 if (ec.hasProperty(key)) {
97  144 ec.setProperty(key, xwikiContext);
98    } else {
99  11252 ec.newProperty(key).inherited().initial(xwikiContext).declare();
100    }
101    }
102   
103    // 4) Call the request initializers to populate the Request further.
104  13129 try {
105  13141 RequestInitializerManager manager = this.componentManager.getInstance(RequestInitializerManager.class);
106  13160 manager.initializeRequest(this.container.getRequest());
107    } catch (Exception e) {
108  0 throw new ServletContainerException("Failed to initialize request", e);
109    }
110   
111    // 5) Call Execution Context initializers to perform further Execution Context initializations
112  13148 try {
113  13153 ExecutionContextManager manager = this.componentManager.getInstance(ExecutionContextManager.class);
114  13163 manager.initialize(this.execution.getContext());
115    } catch (Exception e) {
116  0 throw new ServletContainerException("Failed to initialize Execution Context", e);
117    }
118    }
119   
 
120  1713 toggle @Override
121    public void initializeRequest(HttpServletRequest httpServletRequest) throws ServletContainerException
122    {
123  1716 initializeRequest(httpServletRequest, null);
124    }
125   
 
126  13127 toggle @Override
127    public void initializeResponse(HttpServletResponse httpServletResponse)
128    {
129  13140 this.container.setResponse(new ServletResponse(httpServletResponse));
130    }
131   
 
132  13110 toggle @Override
133    public void initializeSession(HttpServletRequest httpServletRequest)
134    {
135  13131 this.container.setSession(new ServletSession(httpServletRequest));
136    }
137    }