package com.guidewire.pl.system.servlet;

import com.guidewire.pl.system.servlet.SafeHttpServlet.1;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;

public abstract class SafeHttpServlet extends HttpServlet {
   private boolean _enabled;
   private boolean _initCalled = false;
   private boolean _initCompleted = false;
   private String _servletName = "Unknown";

   public final void init(final ServletConfig config) throws ServletException {
      this._servletName = config.getServletName();
      boolean runInit;
      synchronized (this) {
         runInit = !this._initCalled;
         this._initCalled = true;
      }

      if (runInit) {
         this._enabled = true;
         ServletContext servletContext = config.getServletContext();
         ServletUtilities.initServletEnvironment(servletContext);
         SafeHttpServlet servlet = this;
         Thread initThread = new 1(this, servlet, config);
         String className = servlet.getClass().getName();
         String threadName = "SHTTPS-" + className.substring(className.lastIndexOf(".") + 1) + "-INIT";
         initThread.setName(threadName);
         initThread.setDaemon(true);
         initThread.start();
      } else {
         super.init(config);
      }
   }

   public final void service(ServletRequest request, ServletResponse response) throws IOException, ServletException {
      if (this._enabled) {
         this.waitForCompletionOfReallyInit();
      }

      this.reallyService(request, response);
   }

   protected void reallyInit(ServletConfig servletContext) throws ServletException {
   }

   public void reallyService(ServletRequest request, ServletResponse response) throws ServletException, IOException {
      super.service(request, response);
   }

   private void waitForCompletionOfReallyInit() {
      synchronized (this) {
         while (!this._initCompleted) {
            try {
               this.wait();
            } catch (InterruptedException var4) {
            }
         }
      }
   }
}
