/**
 * Copyright (C) 2014-2018 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.photon.core.servlet;

import java.io.IOException;

import javax.annotation.Nonnull;
import javax.annotation.OverridingMethodsMustInvokeSuper;
import javax.servlet.ServletException;

import com.helger.photon.core.app.html.IHTMLProvider;
import com.helger.photon.core.app.html.PhotonHTMLHelper;
import com.helger.servlet.response.UnifiedResponse;
import com.helger.web.scope.IRequestWebScopeWithoutResponse;
import com.helger.xservlet.handler.simple.IXServletSimpleHandler;

/**
 * Base XServlet handler for the main application.
 *
 * @author Philip Helger
 */
public abstract class AbstractApplicationXServletHandler implements IXServletSimpleHandler
{
  protected AbstractApplicationXServletHandler ()
  {}

  /**
   * @param aRequestScope
   *        The request scope
   * @return The HTML provider that creates the content. May not be
   *         <code>null</code>.
   */
  @Nonnull
  protected abstract IHTMLProvider createHTMLProvider (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope);

  @OverridingMethodsMustInvokeSuper
  public void handleRequest (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,
                             @Nonnull final UnifiedResponse aUnifiedResponse) throws IOException, ServletException
  {
    // Who is responsible for creating the HTML?
    final IHTMLProvider aHTMLProvider = createHTMLProvider (aRequestScope);

    // Create the HTML and put it into the response
    PhotonHTMLHelper.createHTMLResponse (aRequestScope, aUnifiedResponse, aHTMLProvider);
  }
}

@@ -846,24 +846,174 @@
 Exception;%0A%0A
+import com.helger.commons.debug.GlobalDebug;%0Aimport com.helger.commons.state.EContinue;%0Aimport com.helger.photon.core.app.error.InternalErrorBuilder;%0A
 import com.h
@@ -1527,16 +1527,771 @@
 )%0A  %7B%7D%0A%0A
+  @Nonnull%0A  public EContinue onException (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,%0A                                @Nonnull final UnifiedResponse aUnifiedResponse,%0A                                @Nonnull final Throwable t)%0A  %7B%0A    if (!GlobalDebug.isDebugMode ())%0A    %7B%0A      // Send internal error mail if needed%0A      new InternalErrorBuilder ().setThrowable (t)%0A                                 .setRequestScope (aRequestScope)%0A                                 .addErrorMessage (%22Error running application servlet %22 + getClass ().getSimpleName ())%0A                                 .handle ();%0A%0A      // Do not propagate%0A      return EContinue.BREAK;%0A    %7D%0A%0A    // Propagate only in debug mode%0A    return EContinue.CONTINUE;%0A  %7D%0A%0A
   /**%0A  

Send internal error mail on application error