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
  }
  @Override
  public void handleEvent(Event evt) {
    StringBuilder code = new StringBuilder();

    // Registramos antes de que se ejecute el auto-complete
    // Filtramos los eventos change generados por el navegador por el autocomplete
    code.append("var filter = function (evt)\n");
    code.append("{\n");
    code.append("  var evtList = evt.getListenerWrapper(); \n");
    code.append("  if (!evtList.getType) return true;\n");
    code.append(
        "  return (evtList.getType() != \"change\");\n"); // Si devuelve false entonces no enviar al
                                                          // servidor este evento
    code.append("};\n");
    code.append("itsNatDoc.addGlobalEL(filter);\n");

    code.append("var listener = function ()\n");
    code.append("{\n");
    code.append("  var itsNatDoc = arguments.callee.itsNatDoc;\n");
    code.append(
        "  itsNatDoc.removeGlobalEL(arguments.callee.filter);\n"); // Restauramos tras el auto
                                                                   // complete

    // Reconstuirmos así el objeto de utilidad response en fase load aunque ya no estamos en esa
    // fase
    // y evitamos así problemas de serialización si memorizáramos el objeto original como un
    // atributo (o por captura de contexto ocurre serialización indirecta)
    ResponseLoadStfulDocumentValid response =
        new ResponseLoadStfulDocumentValidFakeForOperaOld(clientDoc);
    ResponseDelegateStfulWebLoadDocImpl responseDeleg =
        (ResponseDelegateStfulWebLoadDocImpl)
            ResponseDelegateStfulLoadDocImpl.createResponseDelegateStfulLoadDoc(response);
    code.append(responseDeleg.rewriteClientUIControlProperties(true));

    code.append("};\n");
    code.append("listener.filter = filter;\n");
    code.append("listener.itsNatDoc = itsNatDoc;\n");

    code.append(
        "itsNatDoc.setTimeout(listener,0);"); // El listener se ejecutará *después* del
                                              // auto-complete

    ClientDocument clientDoc = ((ItsNatEvent) evt).getClientDocument();
    clientDoc.addCodeToSend(code.toString());

    // Antes de ejecutarse el rewriteClientUIControlProperties(), Opera hace el autofill
  }
Пример #3
0
  public static void testSerialization(ItsNatServletRequest request) {
    ClientDocument clientDoc = request.getClientDocument();
    // String file = "c:\\tmp\\itsnat_serialize_test.tmp";

    ByteArrayOutputStream ostream = null;
    ByteArrayInputStream istream = null;
    try {
      ItsNatSession session = clientDoc.getItsNatSession();

      ostream = new ByteArrayOutputStream();
      ObjectOutputStream p = new DebuggingObjectOutputStream(ostream);
      p.writeObject(session);
      // p.writeObject(clientDoc); // Write the tree to the stream.
      p.flush();
      ostream.close(); // close the file.

      Thread.sleep(500); // Para que se note que estamos haciendo este test

      byte[] stream = ostream.toByteArray();
      istream = new ByteArrayInputStream(stream);
      ObjectInputStream q =
          new ItsNatSessionObjectInputStream(
              istream); // ItsNatSessionObjectInputStream es INTERNO DE ITSNAT sólo usar para estas
                        // pruebas
      // clientDoc = (ClientDocument)q.readObject();
      session = (ItsNatSession) q.readObject();
      istream.close(); // close the file.
    } catch (Exception ex) {
      try {
        if (ostream != null) ostream.close();
        if (istream != null) istream.close();
      } catch (IOException ex2) {
        ex.printStackTrace();
        throw new RuntimeException(ex2);
      }
      throw new RuntimeException(ex);
    }
  }