Coverage Report - org.apache.tapestry.engine.RestartService
 
Classes in this File Line Coverage Branch Coverage Complexity
RestartService
0%
0/25
0%
0/4
1.5
 
 1  
 // Copyright 2004, 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry.engine;
 16  
 
 17  
 import java.io.IOException;
 18  
 import java.util.HashMap;
 19  
 import java.util.Map;
 20  
 
 21  
 import javax.servlet.http.HttpServletRequest;
 22  
 import javax.servlet.http.HttpServletResponse;
 23  
 import javax.servlet.http.HttpSession;
 24  
 
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.tapestry.IRequestCycle;
 27  
 import org.apache.tapestry.Tapestry;
 28  
 import org.apache.tapestry.services.LinkFactory;
 29  
 
 30  
 /**
 31  
  * Restarts the Tapestry application. This is normally reserved for dealing with
 32  
  * catastrophic failures of the application. Discards the
 33  
  * {@link javax.servlet.http.HttpSession}, if any, and redirects to the
 34  
  * Tapestry application servlet URL (invoking the {@link HomeService}).
 35  
  * 
 36  
  * @author Howard Lewis Ship
 37  
  * @since 1.0.9
 38  
  */
 39  
 
 40  0
 public class RestartService implements IEngineService
 41  
 {
 42  
 
 43  
     /** @since 4.0 */
 44  
     private Log _log;
 45  
 
 46  
     /** @since 4.0 */
 47  
     private HttpServletRequest _request;
 48  
 
 49  
     /** @since 4.0 */
 50  
     private HttpServletResponse _response;
 51  
 
 52  
     /** @since 4.0 */
 53  
     private LinkFactory _linkFactory;
 54  
 
 55  
     /** @since 4.0 */
 56  
     private String _servletPath;
 57  
 
 58  
     public ILink getLink(boolean post, Object parameter)
 59  
     {
 60  0
         if (parameter != null)
 61  0
             throw new IllegalArgumentException(EngineMessages
 62  
                     .serviceNoParameter(this));
 63  
 
 64  0
         Map parameters = new HashMap();
 65  
 
 66  0
         return _linkFactory.constructLink(this, post, parameters, true);
 67  
     }
 68  
 
 69  
     public void service(IRequestCycle cycle)
 70  
         throws IOException
 71  
     {
 72  0
         HttpSession session = _request.getSession(false);
 73  
 
 74  0
         if (session != null)
 75  
         {
 76  
             try
 77  
             {
 78  0
                 session.invalidate();
 79  
             }
 80  0
             catch (IllegalStateException ex)
 81  
             {
 82  0
                 _log.warn("Exception thrown invalidating HttpSession.", ex);
 83  
 
 84  
                 // Otherwise, ignore it.
 85  0
             }
 86  
         }
 87  
 
 88  0
         String url = cycle.getAbsoluteURL(_servletPath);
 89  
 
 90  0
         _response.sendRedirect(url);
 91  0
     }
 92  
 
 93  
     public String getName()
 94  
     {
 95  0
         return Tapestry.RESTART_SERVICE;
 96  
     }
 97  
 
 98  
     /** @since 4.0 */
 99  
     public void setLog(Log log)
 100  
     {
 101  0
         _log = log;
 102  0
     }
 103  
 
 104  
     /** @since 4.0 */
 105  
     public void setRequest(HttpServletRequest request)
 106  
     {
 107  0
         _request = request;
 108  0
     }
 109  
 
 110  
     /** @since 4.0 */
 111  
     public void setResponse(HttpServletResponse response)
 112  
     {
 113  0
         _response = response;
 114  0
     }
 115  
 
 116  
     /** @since 4.0 */
 117  
     public void setLinkFactory(LinkFactory linkFactory)
 118  
     {
 119  0
         _linkFactory = linkFactory;
 120  0
     }
 121  
 
 122  
     /** @since 4.0 */
 123  
     public void setServletPath(String servletPath)
 124  
     {
 125  0
         _servletPath = servletPath;
 126  0
     }
 127  
 }