0 Replies Latest reply: Dec 20, 2012 2:46 AM by Rajnikanth RSS

    doGet() method is being called every 3inutes repetitively in servlet

    Rajnikanth
      HI,

      There are 2 managed servers in one unix box.

      i have one war application deployed in cluster level. This war application will search the logs and will give particular content as a result.

      The Jsp page will send the request and it is able to get the correct results if the operation completes within 3 minutes. if there are so many logs, it is giving unreliable results as war application is sending the request again and again in the interval of 3 mins.

      Request parameters are getting by servlet, and this servlet will create the unix shellscript in background and it will execute in a box.

      0-3 mins 1st .sh creating and executing..
      3-6 mins 2nd .sh creats and starts the execution, once the 1 one is completed...
      .
      .
      .
      its becomes infinite loop...

      after some time Browser is going to diagnostic error state..
      i did debugging there i can see doGet method of servlet is being called for every 3 minutes..

      to avoid this i tried to give some parameters in weblogic.xml file...but its not working..

      please fine below weblogic.xml file

      ====================================
      <?xml version='1.0' encoding='UTF-8'?>
      <weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.2/weblogic-web-app.xsd">
      <session-descriptor>
      </session-descriptor>
      <jsp-descriptor>
      <page-check-seconds>-1</page-check-seconds>
      <debug>true</debug>
      </jsp-descriptor>
      <container-descriptor>
      <resource-reload-check-secs>-1</resource-reload-check-secs>
      <servlet-reload-check-secs>-1</servlet-reload-check-secs>
      <prefer-web-inf-classes>true</prefer-web-inf-classes>
      </container-descriptor>
      <logging>
      <log-filename>/wls_domains/b2borap2/application_MT/logs/messagetracker.log</log-filename>
      </logging>

      </weblogic-web-app>
      =======================================================

      and web.xml file is


      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

      <listener>
      <listener-class>
      com.tm.messagetracker.listeners.MTrackerSession
      </listener-class>
      </listener>

      <servlet>
      <servlet-name>Controller</servlet-name>
      <servlet-class>com.tm.messagetracker.Controller</servlet-class>
      <load-on-startup>1</load-on-startup>
      </servlet>

      <servlet-mapping>
      <servlet-name>Controller</servlet-name>
      <url-pattern>*.do</url-pattern>
      </servlet-mapping>

      <session-config>
      <session-timeout>30</session-timeout>
      </session-config>

      <mime-mapping>
      <extension>txt</extension>
      <mime-type>text/plain</mime-type>
      </mime-mapping>

      <mime-mapping>
      <extension>html</extension>
      <mime-type>text/html</mime-type>
      </mime-mapping>

      <mime-mapping>
      <extension>htm</extension>
      <mime-type>text/html</mime-type>
      </mime-mapping>

      <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
      <welcome-file>index.html</welcome-file>
      </welcome-file-list>

      </web-app>

      =========================================

      please find the servlet code..




      public class Controller extends HttpServlet
      {
      public void init()
      {
           
      }
           

      public void doGet(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException
      {
           System.out.println("Iam at doGet");
      res.setContentType("text/html");

      HttpSession session = req.getSession (false);

      if (session==null) {
           // We Send a Redirect
           res.sendRedirect("./../pages/login.jsp");
      }
      //HttpSession session = req.getSession(true);
      boolean loginTravelled = new Boolean((String)session.getAttribute("loginTravelled")).booleanValue();
      UserVerification uv = new UserVerification();
      MTUtils mTUtils = new MTUtils();
      Properties systemProps = SerializeProperties.doLoad();
      int noOFrecordsPerPage = 10;

      if (loginTravelled)
      {
           System.out.println("loginTravelled value :"+loginTravelled);
      String pageId = req.getParameter("pageId");

      String actionId = req.getParameter("actionId");


      if (actionId.equals("logout"))
      {
      session.removeAttribute("CompleteSearchRecords");
      session.removeAttribute("DisplaySearchRecords");
      session.invalidate();
      System.gc();
      res.sendRedirect("./../pages/login.jsp");
      }
      else if (pageId.equals("faq"))
      {
      if (actionId.equals("homepage"))
      {
      System.gc();
      res.sendRedirect("./../pages/login.jsp");
      }
      else if (actionId.equals("download"))
      {
      String fileName = req.getParameter("fileName");
      String originalFileName = req.getParameter("originalFileName");
      doDownload(req, res, fileName, originalFileName);
      }

      }
      else if (pageId.equals("login"))
      {
      if (actionId.equals("downloads"))
      {
      List downloadListRecords = null;
      try
      {
      downloadListRecords = DownloadableRecords.getDownloadableRecords(new File(systemProps.getProperty("faq")));
      }
      catch (Exception e)
      {
      e.printStackTrace();
      }

      session.setAttribute("DownloadListRecords", downloadListRecords);

      res.sendRedirect("./../pages/downloads.jsp");
      }
      else if (actionId.equals("userlogin"))
      {
      String userId = req.getParameter("uname").trim();
      String password = req.getParameter("passwd").trim();

      if ((userId != null) && (userId.length() > 0) && (password != null) && (password.length() > 0))
      {
      if ((userId.equals("superadmin")) && (password.equals("superadmin")))
      {
      res.sendRedirect("./../pages/admin.jsp");
      }

      String userAuthMsg = UserVerification.verifyUser(userId, password);

      if (userAuthMsg.equals("adminuser"))
      {
      res.sendRedirect("./../pages/admin.jsp");
      }
      else if (userAuthMsg.equals("guestuser"))
      {
      res.sendRedirect("./../pages/search.jsp");
      }
      else if (userAuthMsg.equals("wrongpassword"))
      {
      res.sendRedirect("./../pages/login.jsp?userAuthDispMsg=Sorry wrong password");
      }
      else if (userAuthMsg.equals("unauthorizeduser"))
      {
      res.sendRedirect("./../pages/login.jsp?userAuthDispMsg=User is not Authorized ");
      }
      else if ((userAuthMsg.equals("adminpropsNotFound")) || (userAuthMsg.equals("guestpropsNotFound")))
      {
      res.sendRedirect("./../pages/error.jsp?userAuthDispMsg=user configurations not found , Please contact admin");
      }

      }
      else
      {
      res.sendRedirect("./../pages/login.jsp?userAuthDispMsg=UserName or password cannot be null");
      }

      }

      }
      else if (pageId.equals("adminPage"))
      {
      if (actionId.equals("adduser"))
      {
      CommonProperties adminProps = MTrackerProperties.getAdminProps();
      CommonProperties guestProps = MTrackerProperties.getGuestProps();

      String userId = req.getParameter("adduname").trim();
      String password = req.getParameter("passwd").trim();

      String userAuthMsg = uv.verifyUser(userId);

      if (userAuthMsg.equals("adminuser"))
      {
      res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Admin user with name exists");
      }
      else if (userAuthMsg.equals("guestuser"))
      {
      res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Guest user with name exists");
      }
      else
      {
      String userType = req.getParameter("usertype").trim();

      if (userType.equals("admin"))
      {
      adminProps.addProperty(userId, password);
      res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=User " + userId + " added successfully");
      }
      else
      {
      guestProps.addProperty(userId, password);
      res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=User " + userId + " added successfully");
      }

      }

      }
      else if (actionId.equals("deleteuser"))
      {
      CommonProperties adminProps = MTrackerProperties.getAdminProps();
      CommonProperties guestProps = MTrackerProperties.getGuestProps();

      String userId = req.getParameter("deluname").trim();
      String userAuthMsg = uv.verifyUser(userId);

      if (userAuthMsg.equals("adminuser"))
      {
      adminProps.deleteProperty(userId);
      res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Admin user " + userId + " deleted");
      }
      else if (userAuthMsg.equals("guestuser"))
      {
      guestProps.deleteProperty(userId);
      res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Guest user " + userId + " deleted");
      }
      else
      {
      res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=User " + userId + " does not exists ");
      }

      }
      else if (actionId.equals("updatescript"))
      {
      String perlScriptLoc = req.getParameter("perlloc").trim();

      SerializeProperties.doSave(perlScriptLoc);
      try
      {
      Thread.sleep(2500L);
      }
      catch (InterruptedException e) {
      e.printStackTrace();
      }
      res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Perl script location updated with -> " + perlScriptLoc);
      }

      else if (actionId.equals("updatepropertyfile"))
      {
      String propfileLoc = req.getParameter("proploc").trim();

      SerializeProperties.doSave(propfileLoc);
      try
      {
      Thread.sleep(2500L);
      }
      catch (InterruptedException e) {
      e.printStackTrace();
      }
      res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Property file location updated with -> " + propfileLoc);
      }

      else if (actionId.equals("searchLink"))
      {
      res.sendRedirect("./../pages/search.jsp");
      }
      if (actionId.equals("cleanup"))
      {
      String resultsDir = systemProps.getProperty("results");
      mTUtils.deleteFiles(new File(resultsDir), 24);

      res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Cleanup Done !!!");
      }

      }

      else if (pageId.equals("searchPage"))
           
      {
           
           
           System.out.println("Start searching process Here");
           if (actionId.equals("search"))
      {
           System.out.println("Started searching process");
      String tboxValue = req.getParameter("tbox");
      String tareaValue = req.getParameter("tarea");
      String SearchString = "";


      String auditEnable = req.getParameter("audit");
      String errorEnable = req.getParameter("error");
      String debugEnable = req.getParameter("debug");

      String srchStartDate = req.getParameter("srchstartDate");
      String srchEndDate = req.getParameter("srchendDate");

      String srchInZipFile = "";
      if (req.getParameter("srchInZipFile") != null) {
      srchInZipFile = req.getParameter("srchInZipFile");
      }

      String mode = req.getParameter("inputmode");
      try
      {
      if (req.getParameter("recordsPerPage") != null)
      noOFrecordsPerPage = new Integer(req.getParameter("recordsPerPage")).intValue();
      }
      catch (Exception e)
      {
      res.sendRedirect("./../pages/error.jsp?userAuthDispMsg=recordsPerPage should be a number");
      }

      if (mode.equals("single"))
      {
      SearchString = tboxValue;
      }
      else
      {
      SearchString = tareaValue;
      }

      String inputDir = systemProps.getProperty("inputs");
      String resultsDir = systemProps.getProperty("results");

      String inputFileName = new Integer(mTUtils.getRandom()).toString();

      File inputParams = new File(inputDir + "/" + inputFileName + ".properties");
      File inputTxt = new File(inputDir + "/" + inputFileName + ".txt");

      synchronized (inputParams) {
           System.out.println("inputParams"+inputParams);
      synchronized (inputTxt)
      {
           System.out.println("inputtxt"+inputTxt);
      boolean saved = false;

      CommonProperties singleSerProps = new CommonProperties(inputParams);

      Properties searchProps = new Properties();

      searchProps.setProperty("search_from_date", srchStartDate);
      searchProps.setProperty("search_to_date", srchEndDate);
      searchProps.setProperty("force_zip_search", srchInZipFile);

      if ((SearchProperties.saveSingeSearchProps(singleSerProps, searchProps)) && (SearchProperties.saveSearchFile(inputTxt, SearchString)))
      {
      if (mTUtils.genarateScript(auditEnable, debugEnable, errorEnable, srchInZipFile, inputFileName))
      {
           
      if (mTUtils.runScript("sh", inputFileName))
      {
           
      List tRecords = null;

      TrackingLogReader treader = new TrackingLogReader();

      try
      {
      tRecords = treader.getRecords(new File(resultsDir), inputFileName);
      }
      catch (Exception e)
      {
      e.printStackTrace();
      }

      if (tRecords == null)
      {
      tRecords = new ArrayList();
      tRecords.add("No Records Found");
      }

      String backEnb = "";
      String nextEnb = "";

      int fromRec = 0;
      int toRec = 0;

      if (tRecords.size() > noOFrecordsPerPage)
      {
      toRec = noOFrecordsPerPage;
      backEnb = "false";
      nextEnb = "true";
      }
      else
      {
      toRec = tRecords.size();
      backEnb = "false";
      nextEnb = "false";
      }

      List subList = tRecords.subList(fromRec, toRec);


      session.setAttribute("CompleteSearchRecords", tRecords);
      session.setAttribute("DisplaySearchRecords", subList);
      session.setAttribute("fromRec", new Integer(fromRec));
      session.setAttribute("toRec", new Integer(toRec));
      session.setAttribute("nextEnb", nextEnb);
      session.setAttribute("backEnb", backEnb);
      session.setAttribute("recsPerPage", new Integer(noOFrecordsPerPage));

      res.sendRedirect("./../pages/SearchResults.jsp");
      }
      else {
      res.sendRedirect("./../pages/error.jsp?userAuthDispMsg=Problem in calling PERL system , Please contact admin");
      }

      }
      else
      {
      res.sendRedirect("./../pages/error.jsp?userAuthDispMsg=Script not generated , Please contact admin");
      }

      }
      else
      {
      res.sendRedirect("./../pages/error.jsp?userAuthDispMsg=Search input directory not found, Please contact admin ");
      }

      }

      //inputParams.delete();
      //inputTxt.delete();
      }
      }
      }




      else if (pageId.equals("searchresults"))
      {
      noOFrecordsPerPage = ((Integer)session.getAttribute("recsPerPage")).intValue();

      if (actionId.equals("newSearch"))
      {
      session.removeAttribute("CompleteSearchRecords");
      session.removeAttribute("DisplaySearchRecords");
      session.removeAttribute("fromRec");
      session.removeAttribute("toRec");
      session.removeAttribute("recsPerPage");
      System.gc();
      res.sendRedirect("./../pages/search.jsp");
      }
      else if (actionId.equals("first"))
      {
      List completeRecords = (List)session.getAttribute("CompleteSearchRecords");
      int fromRec = 0;
      int toRec = 0;

      String backEnb = "";
      String nextEnb = "";

      if (completeRecords.size() > noOFrecordsPerPage)
      {
      toRec = noOFrecordsPerPage;
      backEnb = "false";
      nextEnb = "true";
      }
      else
      {
      toRec = completeRecords.size();
      backEnb = "false";
      nextEnb = "false";
      }

      List subList = completeRecords.subList(fromRec, toRec);

      session.setAttribute("CompleteSearchRecords", completeRecords);
      session.setAttribute("DisplaySearchRecords", subList);
      session.setAttribute("fromRec", new Integer(fromRec));
      session.setAttribute("toRec", new Integer(toRec));
      session.setAttribute("nextEnb", nextEnb);
      session.setAttribute("backEnb", backEnb);
      session.setAttribute("recsPerPage", new Integer(noOFrecordsPerPage));

      res.sendRedirect("./../pages/SearchResults.jsp");
      }
      else if (actionId.equals("last"))
      {
      List completeRecords = (List)session.getAttribute("CompleteSearchRecords");
      int fromRec = 0;
      int toRec = completeRecords.size();

      String backEnb = "";
      String nextEnb = "";

      if (noOFrecordsPerPage > completeRecords.size())
      {
      fromRec = 0;
      backEnb = "false";
      nextEnb = "false";
      }
      else
      {
      fromRec = completeRecords.size() - noOFrecordsPerPage;
      backEnb = "true";
      nextEnb = "false";
      }

      List subList = completeRecords.subList(fromRec, toRec);

      session.setAttribute("CompleteSearchRecords", completeRecords);
      session.setAttribute("DisplaySearchRecords", subList);
      session.setAttribute("fromRec", new Integer(fromRec));
      session.setAttribute("toRec", new Integer(toRec));
      session.setAttribute("nextEnb", nextEnb);
      session.setAttribute("backEnb", backEnb);
      session.setAttribute("recsPerPage", new Integer(noOFrecordsPerPage));

      res.sendRedirect("./../pages/SearchResults.jsp");
      }
      else if (actionId.equals("back"))
      {
      List completeRecords = (List)session.getAttribute("CompleteSearchRecords");
      int fromRec = ((Integer)session.getAttribute("fromRec")).intValue();
      int toRec = ((Integer)session.getAttribute("toRec")).intValue();

      toRec = fromRec;
      if (fromRec - noOFrecordsPerPage > 0)
      {
      session.setAttribute("backEnb", "true");
      fromRec -= noOFrecordsPerPage;
      }
      else
      {
      fromRec = 0;
      session.setAttribute("backEnb", "false");
      }

      session.setAttribute("nextEnb", "true");

      session.setAttribute("fromRec", new Integer(fromRec));
      session.setAttribute("toRec", new Integer(toRec));

      List subList = completeRecords.subList(fromRec, toRec);
      session.setAttribute("DisplaySearchRecords", subList);

      res.sendRedirect("./../pages/SearchResults.jsp");
      }
      else if (actionId.equals("next"))
      {
      List completeRecords = (List)session.getAttribute("CompleteSearchRecords");
      int fromRec = ((Integer)session.getAttribute("fromRec")).intValue();
      int toRec = ((Integer)session.getAttribute("toRec")).intValue();

      fromRec = toRec;
      if (toRec + noOFrecordsPerPage <= completeRecords.size())
      {
      session.setAttribute("nextEnb", "true");
      toRec += noOFrecordsPerPage;
      }
      else
      {
      toRec = completeRecords.size();
      session.setAttribute("nextEnb", "false");
      }

      session.setAttribute("backEnb", "true");

      session.setAttribute("fromRec", new Integer(fromRec));
      session.setAttribute("toRec", new Integer(toRec));

      List subList = completeRecords.subList(fromRec, toRec);
      session.setAttribute("DisplaySearchRecords", subList);

      res.sendRedirect("./../pages/SearchResults.jsp");
      }
      else if (actionId.equals("download"))
      {
      String fileName = req.getParameter("fileName");
      String originalFileName = req.getParameter("originalFileName");
      doDownload(req, res, fileName, originalFileName);
      }

      }

      }
      else
      {
      res.sendRedirect("./../pages/login.jsp?userAuthDispMsg=Invalid USER");
      }
      }

      public void doPost(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException
      {
      doGet(req, res);
      }

      private void doDownload(HttpServletRequest req, HttpServletResponse resp, String filename, String original_filename)
      throws IOException
      {
      File f = new File(filename);
      int length = 0;
      ServletOutputStream op = resp.getOutputStream();
      ServletContext context = getServletConfig().getServletContext();
      String mimetype = context.getMimeType(filename);

      resp.setContentType(mimetype != null ? mimetype : "application/octet-stream");
      resp.setContentLength((int)f.length());
      resp.setHeader("Content-Disposition", "attachment; filename=\"" + original_filename + "\"");

      byte[] bbuf = new byte[10240];
      DataInputStream in = new DataInputStream(new FileInputStream(f));

      while ((in != null) && ((length = in.read(bbuf)) != -1))
      {
      op.write(bbuf, 0, length);
      }
      in.close();
      op.flush();
      op.close();
      }

      =========================

      anyone please help me on above......Thanks in advance..