Example #1
0
  public Connection getConexionTango() throws DataStoreException {

    if (_connTango == null) {
      _p = Props.getProps("partesMO", null);
      _driverTango = _p.getProperty("driverTango", "sun.jdbc.odbc.JdbcOdbcDriver");
      _urlTango = _p.getProperty("urlTango", "jdbc:odbc:tango");
      _userTango = _p.getProperty("userTango", "tango");
      _passWordTango = _p.getProperty("passWordTango", "tango");

      try {
        // Se carga el driver JDBC-ODBC
        Class.forName(_driverTango);
      } catch (ClassNotFoundException e) {
        MessageLog.writeErrorMessage(e, null);
        throw new DataStoreException("Imposible cargar el driver para Tango: " + e.getMessage());
      }

      try {
        // Se establece la conexión con la base de datos
        _connTango = DriverManager.getConnection(_urlTango, _userTango, _passWordTango);
      } catch (Exception e) {
        MessageLog.writeErrorMessage(e, null);
        throw new DataStoreException(
            "imposible establecer conexión con la base tango: " + e.getMessage());
      }
    }

    return _connTango;
  }
Example #2
0
  /** This method generates the html used by the tag. */
  public void generateComponentHTML(JspWriter p) throws IOException {
    try {

      HtmlTreeControl tree = (HtmlTreeControl) getHelper().getController().getComponent(getName());
      if (tree == null) return;

      tree.generateHTML(new PrintWriter(p), -1);

    } catch (IOException ioe) {
      MessageLog.writeErrorMessage("generateComponentHTML", ioe, this);
      throw ioe;

    } catch (Exception e) {
      MessageLog.writeErrorMessage("generateComponentHTML", e, this);
    }
  }
  /**
   * Replaces the default browse image with one you specify
   *
   * @param comp - component that is replacing the browse image
   * @param dataType - data type of the component being replaced ( use DataStore.DATATYPE_*)
   * @param bound - flag that signifies if the component is bound to a datastore column
   * @param table - table component is bound to
   * @param column - column component is bound to
   */
  public void replaceBrowseImage(
      HtmlComponent comp, int dataType, boolean bound, String table, String column) {
    try {

      /** get the index of the edit field so we can replace it */
      if (_usePopup) {
        int browseIndex = _componentsVec.indexOf(_browsePopupImageHandle);
        if (browseIndex != -1) {
          replaceCompositeComponent(comp, _browsePopupImageHandle, dataType, bound, table, column);
          _componentsVec.setElementAt(comp, browseIndex);
          comp.setParent(this);
          _browsePopupImageHandle = comp;
        }
      } else {
        int browseIndex = _componentsVec.indexOf(_browseImageHandle);
        if (browseIndex != -1) {
          replaceCompositeComponent(comp, _browseImageHandle, dataType, bound, table, column);
          _componentsVec.setElementAt(comp, browseIndex);
          comp.setParent(this);
          _browseImageHandle = comp;
        }
      }
    } catch (Exception e) {
      MessageLog.writeErrorMessage("replaceBrowseImage", e, this);
    }
  }
 /** Do not use this method in this class. */
 public void add(HtmlComponent comp) {
   try {
     throw new Exception(" DO NOT USE: HtmlLookUpComponent.add. Use addLookupComp instead");
   } catch (Exception e) {
     MessageLog.writeErrorMessage(
         " DO NOT USE: HtmlLookUpComponent.add. Use addLookupComp instead", e, this);
   }
 }
Example #5
0
  /**
   * JspCookieCrumble constructor comment.
   *
   * @param name java.lang.String
   * @param p com.salmonllc.html.HtmlPage
   */
  public JspCookieCrumble(String name, HtmlPage p) {
    super("CookieCrumbleComp" + name, p);

    try {
      _cont = new HtmlContainer("crumble_cont", p);
      _fSeparator = " : ";
    } catch (Exception e) {
      MessageLog.writeErrorMessage("CookieCrumbleComp", e, this);
    }
  }
Example #6
0
 /**
  * Adds a hit to a particular activity. The average time for each named time can be seen in the
  * connection monitor servlet
  */
 public static synchronized void recordTimerActivity(
     String name, long time, Object o, boolean writeToMessageLog) {
   Timer t = (Timer) _timers.get(name);
   if (t == null) {
     t = new Timer();
     _timers.put(name, t);
   }
   t.count++;
   t.totalTime += time;
   if (writeToMessageLog)
     MessageLog.writeDebugMessage("Timer:" + name + " elapsed time (ms):" + time, o);
 }
Example #7
0
  public static void setUpApplicationContext(ServletContext sContext) {
    ApplicationContext context = ApplicationContext.getContext();
    if (context == null) {
      context = new ApplicationContext();
      ApplicationContext.setContext(context);
    }
    context.setAppDocumentRoot(sContext.getRealPath("/"));
    String webAppName;
    try {
      webAppName = sContext.getResource("/").toString();
      if (webAppName.endsWith("/")) webAppName = webAppName.substring(0, webAppName.length() - 1);
      int pos = webAppName.lastIndexOf("/");
      if (pos > -1) webAppName = webAppName.substring(pos + 1);
      if (webAppName == null) webAppName = "";
      context.setAppID(webAppName);
      context.setLogger(MessageLog.getLoggerForApplication(webAppName));

    } catch (MalformedURLException e) {
      MessageLog.writeErrorMessage("setUpApplicationContext", e, null);
    }
  }
  /**
   * This method returns the hidden description filed
   *
   * @return HtmlTextEdit
   */
  public HtmlHiddenField getHiddenDescrField() {
    try {

      /** get the index of the edit field so we can replace it */
      int editIndex = _componentsVec.indexOf(_hiddenDescriptionHandle);
      if (editIndex != -1) {
        return (HtmlHiddenField) _componentsVec.elementAt(editIndex);
      }
    } catch (Exception e) {
      MessageLog.writeErrorMessage("getHiddenDescrField", e, this);
    }
    return null;
  }
Example #9
0
 public static void setUpApplicationContext(ServletContext sContext, HttpServletRequest req) {
   ApplicationContext context = ApplicationContext.getContext();
   if (context == null) {
     context = new ApplicationContext();
     ApplicationContext.setContext(context);
   }
   String webAppName = URLGenerator.generateServletBaseURL(req);
   int pos = webAppName.indexOf("/");
   if (pos > -1) webAppName = webAppName.substring(0, pos);
   context.setAppDocumentRoot(sContext.getRealPath("/"));
   if (webAppName == null) webAppName = "";
   context.setAppID(webAppName);
   context.setLogger(MessageLog.getLoggerForApplication(webAppName));
 }
  /**
   * Replaces the default edit field with one you specify
   *
   * @param comp - component that is replacing the edit field
   * @param dataType - data type of the component being replaced ( use DataStore.DATATYPE_*)
   * @param bound - flag that signifies if the component is bound to a datastore column
   * @param table - table component is bound to
   * @param column - column component is bound to
   */
  public void replaceEdit(
      HtmlComponent comp, int dataType, boolean bound, String table, String column) {
    try {

      /** get the index of the edit field so we can replace it */
      int editIndex = _componentsVec.indexOf(_editHandle);
      if (editIndex != -1) {
        replaceCompositeComponent(comp, _editHandle, dataType, bound, table, column);
        comp.setParent(this);
        _editHandle = comp;
      }
    } catch (Exception e) {
      MessageLog.writeErrorMessage("replaceEdit", e, this);
    }
  }
Example #11
0
 private void createPage(
     HttpServletRequest req,
     HttpServletResponse res,
     HttpSession sess,
     String url,
     String sessID) {
   try {
     String contextToken = "$contextToken$" + _reqCount++;
     URL u = new URL(url);
     HttpURLConnection conn = (HttpURLConnection) u.openConnection();
     conn.setDoInput(true);
     conn.setUseCaches(false);
     HttpURLConnection.setFollowRedirects(false);
     Enumeration e = req.getHeaderNames();
     while (e.hasMoreElements()) {
       String name = (String) e.nextElement();
       String value = req.getHeader(name);
       conn.setRequestProperty(name, value);
     }
     conn.setRequestProperty(
         "Cookie",
         "sesessionid="
             + sessID
             + ";session="
             + sessID
             + ";sessionid="
             + sessID
             + ";JSESSIONID="
             + sessID);
     conn.setRequestProperty(SALMON_CREATE_PAGE_HEADER, "true");
     conn.setRequestProperty(SALMON_CONTEXT_TOKEN, contextToken);
     InputStream in = conn.getInputStream();
     while (in.read() > -1) ;
     in.close();
     conn.disconnect();
     Cookie cookie = new Cookie("JSESSIONID", sessID);
     cookie.setMaxAge(-1);
     res.addCookie(cookie);
     TagContext tc = (TagContext) sess.getAttribute(contextToken);
     if (tc != null) {
       sess.removeAttribute(contextToken);
       req.setAttribute(TagContext.TAG_CONTEXT_REQ_KEY, tc);
     }
   } catch (Exception e) {
     MessageLog.writeErrorMessage("Error creating page", e, this);
   }
 }
Example #12
0
  private void loadCachedController(String key, HttpSession sess) {
    if (!_cacheControllers) return;

    if (sess.getAttribute(key) != null) return;

    byte[] b = (byte[]) _controllerCache.get(key);
    if (b == null) return;

    try {
      JspServletObjectInputStream in =
          new JspServletObjectInputStream(
              new ByteArrayInputStream(b), Thread.currentThread().getContextClassLoader());
      Object o = in.readObject();
      sess.setAttribute(key, o);
      in.close();
    } catch (Exception e) {
      MessageLog.writeErrorMessage("Error reading cached controller for:" + key, e, this);
    }
  }
Example #13
0
  /** This method was created in VisualAge. */
  public void initialize() throws Exception {
    try {
      super.initialize();

      addPageListener(this);

      // Assigning to main cont
      Enumeration e = getComponentTable().elements();
      while (e.hasMoreElements()) {
        HtmlComponent comp = (HtmlComponent) e.nextElement();
        if (comp instanceof JspListForm) {
          _mainCont = (JspListForm) comp;
          break;
        }
      }

    } catch (Exception e) {
      MessageLog.writeErrorMessage("initialize", e, this);
    }
  }
Example #14
0
  private void cacheController(String key, JspController cont) {
    try {
      if (!_cacheControllers) return;

      if (cont == null) return;

      synchronized (_controllerCache) {
        if (_controllerCache.containsKey(key)) return;

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream p = new ObjectOutputStream(out);
        p.writeObject(cont);
        p.flush();
        byte b[] = out.toByteArray();
        _controllerCache.put(key, b);
        out.close();
      }
    } catch (IOException e) {
      MessageLog.writeErrorMessage(
          "Error caching controller:" + cont.getClass().getName(), e, this);
    }
  }
Example #15
0
  public void service(ServletRequest request, ServletResponse response)
      throws ServletException, IOException {
    setUpApplicationContext(getServletConfig().getServletContext(), (HttpServletRequest) request);
    JspController cont = null;
    boolean sessionKeepAlive = true;
    try {
      long time = System.currentTimeMillis();
      request.setAttribute(SALMON_SERVLET_KEY, this);
      sessionKeepAlive = request.getParameter("sessionKeepAlive") != null;

      if (!_replaceFactoryInit) {
        Props p = Props.getSystemProps();
        _replaceFactoryInit = true;
        _replaceFactory = p.getBooleanProperty(Props.SYS_REPLACE_JSP_FACTORY, true);
        _cacheControllers = p.getBooleanProperty(Props.SYS_CACHE_CONTROLLERS, false);
        MessageLog.writeInfoMessage(
            "***JspServlet initialized with properties: "
                + Props.SYS_REPLACE_JSP_FACTORY
                + "="
                + _replaceFactory
                + ", "
                + Props.SYS_CACHE_CONTROLLERS
                + "="
                + _cacheControllers
                + ". To reset, change the System.properties file and restart the server.***",
            this);
      }

      //			if (_replaceFactory) {
      //				JspFactory fact = JspFactory.getDefaultFactory();
      //				if (fact == null ||
      // !fact.getClass().getName().equals("com.salmonllc.jsp.engine.JspFactoryImpl"))
      //					JspFactory.setDefaultFactory(new com.salmonllc.jsp.engine.JspFactoryImpl(fact));
      //			}

      HttpServletRequest req = (HttpServletRequest) request;
      HttpServletResponse res = (HttpServletResponse) response;

      if (sessionKeepAlive)
        com.salmonllc.util.MessageLog.writeInfoMessage(
            "JspServlet.service() keepAlive - URI=" + req.getRequestURI(),
            Props.LOG_LEVEL_10,
            this);
      else {
        notifyListeners((HttpServletRequest) request, (HttpServletResponse) response, true);
        com.salmonllc.util.MessageLog.writeInfoMessage(
            "JspServlet.service() start - URI=" + req.getRequestURI(), Props.LOG_LEVEL_10, this);
      }

      String sessID = req.getParameter(PageTag.getSessionIdentifier());
      HttpSession sess = PageTag.getSession(sessID);
      boolean sessValid = true;
      if (sess == null) {
        sessID = req.getRequestedSessionId();
        sessValid = req.isRequestedSessionIdValid();
        if (!sessValid && sessionKeepAlive) return;
        sess = req.getSession(true);
      }

      boolean onSession = false;
      boolean sessExp = false;
      if (sessID != null && !sessValid) sess.setAttribute("AppServer_SessExp", new Boolean(true));

      boolean createPage = (req.getHeader(SALMON_CREATE_PAGE_HEADER) != null);
      if (_replaceFactory) {
        Object sessToken = sess.getAttribute("AppServer_SessionToken");
        if (sessToken == null) {
          sess.setAttribute("AppServer_SessionToken", new String("tok"));
          sessToken = sess.getAttribute("AppServer_SessionToken");
        }
        synchronized (sessToken) {
          String sessName = "$jsp$" + com.salmonllc.jsp.tags.PageTag.generateSessionName(req);
          loadCachedController(sessName, sess);
          onSession = sess.getAttribute(sessName) != null;

          if (!onSession) _jspService(req, new HttpServletResponseDummy(res, null));

          cont = (JspController) sess.getAttribute(sessName);
          generateExpireResponseHeaders(res, cont.getAddExpireHeaders());

          cacheController(sessName, cont);
          cont.setSessionExpired(sessExp);
          cont.setDoPostRedirected(false);
          _jspService(req, res);
        }
      } else {
        String sessName = "$jsp$" + com.salmonllc.jsp.tags.PageTag.generateSessionName(req);
        String token = sessName + "$pageToken$";
        try {
          if (!createPage) {

            if (sess.getAttribute(token) != null) {

              /*
               * srufle : Jun 25, 2004 4 : 26 : 38 PM
               * This was put in to solve a thread deadlocking issue is was encountering
               *
               * Possible enhancements include
               * - making vars get their values from system parameters
               */
              int index = 0;
              int indexLimit = 1024;
              int sleepCount = 0;
              int sleepCountLimit = 4096;
              int sleepTime = 10;
              while (sess.getAttribute(token) != null) {
                index++;
                Thread.yield();

                if (index >= (indexLimit)) {
                  Thread.sleep(sleepTime);
                  index = 0;
                  sleepCount++;
                  if (sleepCount >= sleepCountLimit) {
                    throw (new ServletException("Thread Locked:Throwing to unlock"));
                  }
                }
              }
            }
            sess.setAttribute(token, token);
          }

          loadCachedController(sessName, sess);
          onSession = sess.getAttribute(sessName) != null;
          if (!onSession && !createPage) {
            createPage(req, res, sess, getPageURL(req, res), sess.getId());
            cont = (JspController) sess.getAttribute(sessName);

            cacheController(sessName, cont);
          } else cont = (JspController) sess.getAttribute(sessName);

          if (cont != null) {
            generateExpireResponseHeaders(res, cont.getAddExpireHeaders());
            cont.setSessionExpired(sessExp);
            cont.setDoPostRedirected(false);
            synchronized (cont) {
              _jspService(req, res);
            }
          } else {
            String contextToken = req.getHeader(SALMON_CONTEXT_TOKEN);
            _jspService(req, res);
            if (contextToken != null) {
              TagContext t = (TagContext) req.getAttribute(TagContext.TAG_CONTEXT_REQ_KEY);
              if (t != null) sess.setAttribute(contextToken, t);
            }
          }
        } catch (Exception e) {
          if (cont == null || cont.getPortletException() == null) {

            if (e instanceof SocketException) {
              // ignore java.net.SocketException
              MessageLog.writeInfoMessage("SocketException would have been thrown", this);
            } else {
              MessageLog.writeErrorMessage("service", e, this);
              throw (new ServletException(e.getMessage()));
            }
          }

        } finally {
          if (!createPage) sess.removeAttribute(token);
        }
      }

      if (!sessionKeepAlive) {
        time = (System.currentTimeMillis() - time);

        if (!createPage) addPageHit(time);

        if (Props.getSystemProps().getBooleanProperty(Props.SYS_RECORD_PAGE_TIMERS))
          recordTimerActivity(req.getRequestURI(), time, this, false);
        com.salmonllc.util.MessageLog.writeInfoMessage(
            "JspServlet.service() end - URI="
                + req.getRequestURI()
                + " Time="
                + time
                + " Init="
                + (!onSession),
            Props.LOG_LEVEL_10,
            this);
      }
    } catch (java.net.SocketException e) {
      // ignore java.net.SocketException
      MessageLog.writeInfoMessage("SocketException would have been thrown", this);
    } catch (ServletException e) {
      if (cont == null || cont.getPortletException() == null) {
        com.salmonllc.util.MessageLog.writeErrorMessage("JspServlet.service()", e, this);
        throw (e);
      }
    } catch (IOException e) {
      com.salmonllc.util.MessageLog.writeErrorMessage("JspServlet.service()", e, this);
      throw (e);
    } catch (Exception e) {
      com.salmonllc.util.MessageLog.writeErrorMessage("JspServlet.service()", e, this);
      throw (new ServletException(e));
    } finally {
      try {
        if (!sessionKeepAlive)
          notifyListeners((HttpServletRequest) request, (HttpServletResponse) response, false);
      } catch (Exception e) {
        com.salmonllc.util.MessageLog.writeErrorMessage("JspServlet.service()", e, this);
        throw (new ServletException(e));
      }
    }
  }
Example #16
0
  public boolean controlaLegajoTango() throws DataStoreException {
    Connection connTango;
    Statement st = null;
    ResultSet r = null;
    int personal_id;
    int nro_legajo = -1;
    String apeynom = null;
    String nombre = null;
    String apellido = null;
    java.sql.Date fechaingreso = null;
    String SQL = null;
    boolean hubo_errores = false;

    // realiza las tareas de lookup sobre los datos de tango y completa información
    for (int i = 0; i < getRowCount(); i++) {
      // verifico lookup y actualiza los datos automáticos en caso de insertar
      if (getRowStatus(i) == STATUS_NEW_MODIFIED || getRowStatus(i) == STATUS_MODIFIED) {

        // recupera la conexión a tango
        connTango = getConexionTango();
        nro_legajo = getSupervisoresNroLegajo(i);

        try {
          // Legajos que tengan un periodo de vigencia actual
          SQL =
              "select L.ID_LEGAJO, L.NOMBRE, L.APELLIDO, I.FECHA_INGRESO "
                  + " from LEGAJO L inner join INGRESO_EGRESO I "
                  + " on L.ID_LEGAJO = I.ID_LEGAJO and I.FECHA_EGRESO IS NULL"
                  + " where L.NRO_LEGAJO = "
                  + Integer.toString(nro_legajo);

          st =
              connTango.createStatement(
                  ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
          r = st.executeQuery(SQL);

          if (r.first()) {
            personal_id = r.getInt(1); // ID_LEGAJO
            nombre = r.getString(2); // NOMBRE
            apellido = r.getString(3); // APELLIDO
            fechaingreso = r.getDate(4); // FECHA_INGRESO
          } else {
            // no es por el numero de legajo, busco por el id
            r.close();
            st.close();

            personal_id = getSupervisoresPersonalId(i);

            // Legajos que tengan un periodo de vigencia actual
            SQL =
                "select L.NRO_LEGAJO, L.NOMBRE, L.APELLIDO, I.FECHA_INGRESO "
                    + " from LEGAJO L inner join INGRESO_EGRESO I "
                    + " on L.ID_LEGAJO = I.ID_LEGAJO and I.FECHA_EGRESO IS NULL"
                    + " where L.ID_LEGAJO = "
                    + Integer.toString(personal_id);

            st =
                connTango.createStatement(
                    ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
            r = st.executeQuery(SQL);

            if (r.first()) {
              nro_legajo = r.getInt(1); // NRO_LEGAJO
              nombre = r.getString(2); // NOMBRE
              apellido = r.getString(3); // APELLIDO
              fechaingreso = r.getDate(4); // FECHA_INGRESO
            } else {
              // no existe el legajo, setea el error y marca el
              // procesamiento con error
              throw new DataStoreException("Legajo inexistente en tango");
            }
          }

          apeynom = apellido + ", " + nombre;

        } catch (SQLException e) {
          MessageLog.writeErrorMessage(e, null);
          // además de escribir en el log mando mensaje a la página
          throw new DataStoreException("Error determinando legajo en tango: " + e.getMessage());
        } finally {
          if (r != null) {
            try {
              r.close();
            } catch (Exception ex) {
            }
          }

          if (st != null)
            try {
              st.close();
            } catch (SQLException e) {
              e.printStackTrace();
            }
        }

        // si la fecha de inicio como supervisor es anterior al ingreso de legajo
        if (getSupervisoresFechaDesde(i).before(fechaingreso)) {
          throw new DataStoreException(
              "La fecha de inicio es anterior a la fecha de ingreso del legajo");
        } else {
          // setea los datos recuperados
          setSupervisoresApeynom(i, apeynom);
          setSupervisoresNroLegajo(i, nro_legajo);
          setSupervisoresPersonalId(i, personal_id);
        }
      }
    }

    return hubo_errores;
  }
  public void completaCategorias() throws DataStoreException {
    Props p;
    String driverTango = null;
    String urlTango = null;
    String userTango = null;
    String passWordTango = null;
    Connection connTango;
    Statement st = null;
    ResultSet r = null;
    String SQL = null;
    String cod_categoria = null;
    String desc_categoria = null;

    p = Props.getProps("partesMO", null);
    driverTango = p.getProperty("driverTango", "sun.jdbc.odbc.JdbcOdbcDriver");
    urlTango = p.getProperty("urlTango", "jdbc:odbc:tango");
    userTango = p.getProperty("userTango", "tango");
    passWordTango = p.getProperty("passWordTango", "tango");

    // realiza una búsqueda custom de los legajos
    try {
      // Se carga el driver
      Class.forName(driverTango);
    } catch (ClassNotFoundException e) {
      MessageLog.writeErrorMessage(e, null);
      throw new DataStoreException("Imposible cargar el driver para Tango: " + e.getMessage());
    }

    try {
      // Se establece la conexión con la base de datos
      connTango = DriverManager.getConnection(urlTango, userTango, passWordTango);
    } catch (Exception e) {
      MessageLog.writeErrorMessage(e, null);
      throw new DataStoreException(
          "imposible establecer conexión con la base tango: " + e.getMessage());
    }

    try {
      SQL = "select COD_CATEGORIA,DESC_CATEGORIA from CATEGORIA order by COD_CATEGORIA";
      st = connTango.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
      r = st.executeQuery(SQL);

      MessageLog.writeErrorMessage(SQL, 1, null, null);

      _categoriaTE2.resetOptions();
      _categoriaTE2.addOption("", "");

      while (r.next()) {
        cod_categoria = r.getString("COD_CATEGORIA");
        desc_categoria = r.getString("DESC_CATEGORIA");

        _categoriaTE2.addOption(cod_categoria, desc_categoria);
      }

    } catch (SQLException e) {
      MessageLog.writeErrorMessage(e, null);
      // adem�s de escribir en el log mando mensaje a la p�gina
      throw new DataStoreException("Error determinando categorías en tango: " + e.getMessage());

    } finally {
      if (r != null) {
        try {
          r.close();
        } catch (Exception ex) {
        }
      }

      if (st != null)
        try {
          st.close();
        } catch (SQLException e) {
          e.printStackTrace();
        }
    }
  }