1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.web.includeservletasstring

File IncludeServletAsString.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

6
14
2
1
74
37
5
0.36
7
2
2.5

Classes

Class Line # Actions
IncludeServletAsString 32 14 0% 5 22
0.00%
 

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 com.xpn.xwiki.web.includeservletasstring;
21   
22    import java.io.IOException;
23   
24    import javax.servlet.RequestDispatcher;
25    import javax.servlet.ServletException;
26    import javax.servlet.http.HttpServletRequest;
27    import javax.servlet.http.HttpServletResponse;
28   
29    import org.slf4j.Logger;
30    import org.slf4j.LoggerFactory;
31   
 
32    public class IncludeServletAsString
33    {
34    private static final Logger LOGGER = LoggerFactory.getLogger(IncludeServletAsString.class);
35   
36    /**
37    * Creates a new instance of IncludeServletAsString
38    */
 
39  0 toggle private IncludeServletAsString()
40    {
41    }
42   
 
43  0 toggle static public String invokeServletAndReturnAsString(String url, HttpServletRequest servletRequest,
44    HttpServletResponse servletResponse) throws IOException, ServletException
45    {
46   
47  0 if (LOGGER.isDebugEnabled()) {
48  0 LOGGER.debug("Including url \"" + url + "\"...");
49    }
50   
51  0 RequestDispatcher requestDispatcher = servletRequest.getRequestDispatcher(url);
52   
53  0 if (requestDispatcher == null) {
54  0 IllegalArgumentException iae =
55    new IllegalArgumentException("Failed to get RequestDispatcher for url: " + url);
56  0 LOGGER.error(iae.getMessage(), iae);
57  0 throw iae;
58    }
59   
60  0 BufferedResponse bufferedResponse = new BufferedResponse(servletResponse);
61   
62  0 requestDispatcher.include(servletRequest, bufferedResponse);
63   
64  0 byte[] buffer = bufferedResponse.getBufferAsByteArray();
65  0 if (LOGGER.isDebugEnabled()) {
66  0 LOGGER.debug("Buffer returned with " + buffer.length + " bytes.");
67    }
68   
69  0 String bufferString = new String(buffer, servletResponse.getCharacterEncoding());
70   
71  0 return bufferString;
72    }
73   
74    }