public void processNotDocument(ItsNatAttachedClientEvent event) {
    ItsNatServletResponse response = event.getItsNatServletResponse();
    if (event.getPhase() == ItsNatAttachedClientEvent.REQUEST) {
      ItsNatServlet servlet = response.getItsNatServlet();
      ServletRequest servRequest = event.getItsNatServletRequest().getServletRequest();
      @SuppressWarnings("unchecked")
      Map<String, String[]> newParams =
          new HashMap<String, String[]>(servRequest.getParameterMap());
      newParams.remove("itsnat_action"); // Removes: itsnat_action=attach_doc
      newParams.put("itsnat_doc_name", new String[] {"feashow.ext.core.misc.remCtrlDocNotFound"});
      servRequest = servlet.createServletRequest(servRequest, newParams);
      servlet.processRequest(servRequest, response.getServletResponse());
    } else // ItsNatAttachedClientEvent.REFRESH
    {
      response.addCodeToSend("if (confirm('Session is expired. Close Window?')) window.close();");
    }

    /*
         if (event.getPhase() == ItsNatAttachedClientEvent.REQUEST)
         {
             ServletRequest request =
    event.getItsNatServletRequest().getServletRequest();
             String sessionId = request.getParameter("itsnat_session_id");
             String docId = request.getParameter("itsnat_doc_id");
             try
             {
               Writer out = response.getServletResponse().getWriter();
               out.write("<html><body><h1>Session/document not found with id:");
               out.write(sessionId + "/" + docId);
               out.write("</h1></body></html>");
             }
             catch(IOException ex) { new RuntimeException(ex); }
         }
         */
  }
  public void processWithDocument(ItsNatAttachedClientEvent event) {
    int phase = event.getPhase();
    if (phase == ItsNatAttachedClientEvent.REQUEST) {
      String[] msg = new String[1];
      if (event instanceof ItsNatAttachedClientTimerEvent) {
        ItsNatAttachedClientTimerEvent timerEvent = (ItsNatAttachedClientTimerEvent) event;
        boolean accepted = (timerEvent.getRefreshInterval() >= 3000);
        event.setAccepted(accepted);
        if (!accepted) msg[0] = "Refresh interval too short: " + timerEvent.getRefreshInterval();
      } else if (event instanceof ItsNatAttachedClientCometEvent) {
        event.setAccepted(true);
      } else // "none" refresh mode
      {
        event.setAccepted(true);
      }

      if (event.getWaitDocTimeout() > 30000) {
        event.setAccepted(false);
        msg[0] = "Too much time waiting for iframe/object/embed: " + event.getWaitDocTimeout();
      }

      ItsNatServletRequest request = event.getItsNatServletRequest();
      ServletRequest servRequest = request.getServletRequest();

      if (!event.isAccepted()) {
        ItsNatServletResponse response = event.getItsNatServletResponse();
        ItsNatServlet servlet = response.getItsNatServlet();
        @SuppressWarnings("unchecked")
        Map<String, String[]> newParams =
            new HashMap<String, String[]>(servRequest.getParameterMap());
        newParams.remove("itsnat_action"); // Removes: itsnat_action=attach_doc
        newParams.put("itsnat_doc_name", new String[] {"feashow.ext.core.misc.remCtrlReqRejected"});
        newParams.put("reason", msg); // submitted as array
        servRequest = servlet.createServletRequest(servRequest, newParams);
        servlet.processRequest(servRequest, response.getServletResponse());
      }
    } else if (phase == ItsNatAttachedClientEvent.REFRESH) {
      ClientDocument observer = event.getClientDocument();
      if (observer.getItsNatDocument().isInvalid()) {
        observer.addCodeToSend("alert('Observed document was destroyed');");
      } else {
        long initTime = observer.getCreationTime();
        long currentTime = System.currentTimeMillis();
        long limitMilisec = 15 * 60 * 1000;
        // 15 minutes (to avoid a long monitoring session)
        if (currentTime - initTime > limitMilisec) {
          event.setAccepted(false);
          observer.addCodeToSend("alert('Remote Control Timeout');\n");
        }
      }
    }
    // ItsNatAttachedClientEvent.LOAD & UNLOAD : nothing to do

    if (!event.isAccepted()) event.getItsNatEventListenerChain().stop(); // Not really necessary
  }