Package hirondelle.web4j.util

Examples of hirondelle.web4j.util.Stopwatch


  private static final String UNSPECIFIED = "Unspecified in Manifest";
  private static final long MILLISECONDS_PER_DAY = 1000*60*60*24L;
  private static final Logger fLogger = Util.getLogger(ShowDiagnostics.class);
 
  private void placeDiagnosticDataInScope(HttpServletRequest aRequest, HttpServletResponse aResponse) throws DAOException {
    Stopwatch stopwatch = new Stopwatch();
    stopwatch.start();
   
    fLogger.fine("Adding system properties.");
    addToRequest("systemProperties", sortMap(System.getProperties()));
    fLogger.fine("Adding Context init-params.");
    addToRequest("contextInitParams", sortMap(getContextInitParams(aRequest)));
    fLogger.fine("Adding application scope items.");
    addToRequest("appScopeItems", getAppScope(aRequest));
    fLogger.fine("Adding session scope items.");
    addToRequest("sessionScopeItems", getSessionScope(aRequest));
    fLogger.fine("Adding container/servlet info.");
    addToRequest("containerServletInfo", getContainerServletInfo(aRequest));
    fLogger.fine("Adding request info.");
    addToRequest("requestInfo", getRequestInfo(aRequest));
    fLogger.fine("Adding database information.");
    addToRequest("dbInfo", getDbInfo());
    fLogger.fine("Adding loggers.");
    addToRequest("loggers", getLoggers());
    fLogger.fine("Adding Controller name/version");
    addToRequest("controller_name_version", Controller.WEB4J_VERSION);
    fLogger.fine("Adding JAR versions.");
    addToRequest("jarVersions", getJarVersions(aRequest));
    fLogger.fine("Adding uptime.");
    addToRequest("uptime", getUptime(aRequest));
    fLogger.fine("Adding request headers.");
    addToRequest("headers", getHeaders(aRequest));
    addToRequest("responseEncoding", getResponseEncoding(aResponse));
    fLogger.fine("Adding cookies.");
    addToRequest("cookies", getCookies(aRequest));
   
    fLogger.fine("Finished retrieving data.");
    stopwatch.stop();
    addToRequest("stopwatch", stopwatch.toString());
  }
View Full Code Here


   
    if( ! fHasLoggedBadReqDetectorDetails ) {
      logBadResponseDetectorDetails();
    }
   
    Stopwatch stopwatch = new Stopwatch();
    stopwatch.start();
   
    aChain.doFilter(aRequest, aResponse);
   
    stopwatch.stop();
    addResponseTime(stopwatch.toValue(), aRequest);
    //fLogger.fine(fPerformanceHistory.toString());
    fLogger.fine("END PerformanceMonitor Filter. Response Time: " + stopwatch);
  }
View Full Code Here

    Ping the target URL by attempting to fetch its HTTP header.
    Email the webmaster if the response status code in the header is 400 or more, or if the ping times out. 
  */
  @Override public void run() {
    fLogger.fine("Pinging the target URL " + Util.quote(fTargetURL));
    Stopwatch stopwatch = new Stopwatch();
    String problem = EMPTY_STRING;
    String pageContent = null;
    int statusCode = 0;
    URLConnection connection = null;
    try {
      stopwatch.start();
      URL target = new URL(fTargetURL);
      connection = target.openConnection();
      connection.setConnectTimeout(fTimeout*1000);
      connection.connect();
      statusCode = extractStatusCode(connection);
      pageContent = getEntireContent(connection);
      if( statusCode == NOT_FOUND ) {
        problem = "Cannot extract status code for : " + fTargetURL;
      }
      else if ( isError(statusCode) ) {
        problem = "URL " + fTargetURL + " is returning an error status code : " + statusCode;
      }
    }
    catch(MalformedURLException ex){
      fLogger.fine("Malformed URL : " + fTargetURL); //this is checked in ctor
    }
    catch(SocketTimeoutException ex){
      problem = "Connection timed out.";
    }
    catch (IOException ex) {
      problem = "Cannot open connection to the URL : " + fTargetURL;
    }
   
    stopwatch.stop();
    if( stopwatch.toValue() > fTimeout * 1000) {
      problem = problem + "Response took too long : " + stopwatch;
    }
   
    if( Util.textHasContent(problem) ) {
      mailTroubleTicket(problem);
View Full Code Here

  */
  @Override public final void init(ServletConfig aConfig) throws ServletException {
    super.init(aConfig);
    fConfig = aConfig;
   
    Stopwatch stopwatch = new Stopwatch();
    stopwatch.start();
   
    BuildImpl.init(aConfig); //first load of application-specific classes; configures and begins logging as well
   
    displaySystemProperties();
    displayConfigInfo(aConfig);
    setPoorPerformanceThreshold(aConfig);
    setCharacterEncodingAndPutIntoAppScope(aConfig);
    putWebmasterEmailAddressIntoAppScope(aConfig);
    putDefaultLocaleIntoAppScope(aConfig);
    putDefaultTimeZoneIntoAppScope(aConfig);
    putStartTimeIntoAppScope(aConfig);
    fLogger.fine("System properties and first app scope items completed " + stopwatch + " after start.");
   
    /*
     Implementation Note
     There are strong order dependencies here: ConfigReader is used later in the
     init of SqlStatement, for example
    */
    ConfigReader.init(aConfig);
    RequestParser.initUiLayer(aConfig); //inits other classes in that layer as well
    WebUtil.init(aConfig);
   
    //This will be the first loading of application-specific classes.
    //This will cause static fields to be initialized.
    ApplicationInfo appInfo = BuildImpl.forApplicationInfo();
    displayVersionInfo(aConfig, appInfo);
    placeAppInfoIntoAppScope(aConfig, appInfo);

    TroubleTicket.init(aConfig, appInfo);
    initMoney(aConfig);
   
    fLogger.config("Calling ConnectionSource.init(ServletConfig).");
    ConnectionSource connSource = BuildImpl.forConnectionSource();
    connSource.init(aConfig);
    fLogger.fine("Init of internal classes, ConnectionSource completed " + stopwatch + " after start.");

    tryDatabaseInitAndStartupTasks();
    fLogger.fine("Database init and startup tasks completed " + stopwatch + " after start.");
   
    CheckModelObjects checkModelObjects = new CheckModelObjects();
    checkModelObjects.performChecks();
    stopwatch.stop();
    fLogger.fine("Cross-Site Scripting scan completed " + stopwatch + " after start.");
   
    fLogger.config("*** SUCCESS : STARTUP COMPLETED SUCCESSFULLY. *** Total startup time : " + stopwatch );
  }
View Full Code Here

   <li>if the response time exceeds a configured threshold, build a
   {@link TroubleTicket}, log it, and email it to the webmaster address configured in <tt>web.xml</tt>
   </ul>
  */
  protected void processRequest(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletException, IOException {
    Stopwatch stopwatch = new Stopwatch();
    stopwatch.start();
   
    aRequest.setCharacterEncoding(fCHARACTER_ENCODING);
    aResponse.setCharacterEncoding(fCHARACTER_ENCODING);
   
    addCurrentUriToRequest(aRequest, aResponse);
    RequestParser requestParser = RequestParser.getInstance(aRequest, aResponse);
    try {
      LoginTasksHelper loginHelper = new LoginTasksHelper();
      loginHelper.reactToNewLogins(aRequest);
      Action action = requestParser.getWebAction();
      ApplicationFirewall appFirewall = BuildImpl.forApplicationFirewall();
      appFirewall.doHardValidation(action, requestParser);
      logAttributesForAllScopes(aRequest);
      ensureDatabasesOk();
      ResponsePage responsePage = checkOwnershipThenExecuteAction(action, requestParser);
      if ( responsePage.hasBinaryData() ) {
        fLogger.fine("Serving binary data. Controller not performing a forward or redirect.");
      }
      else {
        if ( responsePage.getIsRedirect() ) {
          redirect(responsePage, aResponse);
        }
        else {
          forward(responsePage, aRequest, aResponse);
        }
      }
    }
    catch (BadRequestException ex){
      //NOTE : sendError() commits the response.
      if( Util.textHasContent(ex.getErrorMessage()) ){
        aResponse.sendError(ex.getStatusCode(), ex.getErrorMessage());     
      }
      else {
        aResponse.sendError(ex.getStatusCode());     
      }
    }
    catch (Throwable ex) {
      //Bugs OR rare conditions, for example datastore failure
      logAndEmailSeriousProblem(ex, aRequest);
      aResponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
    }
   
    stopwatch.stop();
    if ( stopwatch.toValue() >= fPOOR_PERFORMANCE_THRESHOLD ) {
      logAndEmailPerformanceProblem(stopwatch.toValue(), aRequest);
    }
  }
View Full Code Here

TOP

Related Classes of hirondelle.web4j.util.Stopwatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.