Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2014 Philip Helger (www.helger.com) philip[at]helger[dot]com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package com.helger.webbasics.servlet;
 
 import java.util.List;
 
 
 
Base servlet for the main application.

Author(s):
Philip Helger
 
 {
   private static final Logger s_aLogger = LoggerFactory.getLogger (AbstractApplicationServlet.class);
 
 
   {
   }
 
   @Override
   protected void onRequestBegin (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope)
   {
     // Run default request initialization (menu item and locale)
     ApplicationRequestManager.getInstance ().onRequestBegin (aRequestScope);
 
     // Invoke all "request begin" listener
     for (final IApplicationRequestListenerSPI aListener : )
       try
       {
         aListener.onRequestBegin (aRequestScope);
       }
       catch (final Throwable t)
       {
         .error ("Failed to invoke onRequestBegin on " + aListenert);
       }
   }
 
   @Override
   protected void onRequestEnd (final boolean bExceptionOccurred)
   {
     // Invoke all "request end" listener
     for (final IApplicationRequestListenerSPI aListener : )
       try
       {
         aListener.onRequestEnd (bExceptionOccurred);
       }
       catch (final Throwable t)
       {
         .error ("Failed to invoke onRequestEnd on " + aListenert);
       }
   }

  

Parameters:
aRequestScope The request scope
Returns:
The HTML provider that creates the content. May not be null.
 
   @Nonnull
   protected abstract IHTMLProvider createHTMLProvider (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope);
 
  protected final void handleRequest (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,
                                      @Nonnull final UnifiedResponse aUnifiedResponsethrows ServletException
  {
    try
    {
      // Who is responsible for creating the HTML?
      final IHTMLProvider aHTMLProvider = createHTMLProvider (aRequestScope);
      // Create the HTML and put it into the response
      WebHTMLCreator.createHTMLResponse (aRequestScopeaUnifiedResponseaHTMLProvider);
    }
    catch (final Throwable t)
    {
      // Do not show the exceptions that occur, when client cancels a request.
      if (!StreamUtils.isKnownEOFException (t))
      {
        .error ("Error running application"t);
        // Catch Exception and re-throw
        if (t instanceof ServletException)
          throw (ServletExceptiont;
        throw new ServletException (t);
      }
    }
  }
New to GrepCode? Check out our FAQ X