Package org.apache.geronimo.management.geronimo

Examples of org.apache.geronimo.management.geronimo.WebAccessLog$LogMessage


        Map products = new LinkedHashMap();
        String chosen = renderRequest.getParameter("selectedContainer");
        if(chosen != null) { // Carry on to render the results with the right selection
            renderRequest.setAttribute("selectedContainer", chosen);
        }
        WebAccessLog chosenLog = null;
        if(managers != null) {
            for (int i = 0; i < managers.length; i++) {
                WebManager manager = managers[i];
                AbstractName managerName = PortletManager.getNameFor(renderRequest, manager);
                WebContainer[] containers = (WebContainer[]) manager.getContainers();
                if (containers != null) {
                    for (int j = 0; j < containers.length; j++) {
                        WebContainer container = containers[j];
                        AbstractName containerName = PortletManager.getNameFor(renderRequest, container);
                        String combined = managerName+"%"+containerName;
                        if(containers.length == 1) {
                            products.put(manager.getProductName(), combined);
                        } else {
                            products.put(manager.getProductName()+" ("+containerName.getName().get(NameFactory.J2EE_NAME)+")", combined);
                        }
                        if(chosenLog == null) { // will pick the correct match, or the first if no selection is specified
                            if(chosen == null || chosen.equals(combined)) {
                                chosenLog = PortletManager.getWebAccessLog(renderRequest, managerName, containerName);
                            }
                        }
                    }
                } else {
                    log.error("No web containers found for manager "+manager.getProductName());
                }
            }
        } else {
            log.error("No web managers found!");
        }
        renderRequest.setAttribute("webContainers", products);
        final String[] logNames = chosenLog.getLogNames();
        renderRequest.setAttribute("webLogs", logNames);
        String logToSearch = renderRequest.getParameter("selectedLog");
        if(logToSearch == null) {
            logToSearch = logNames[0];
        } else { //what if the log options for Jetty were showing, but the user picked Tomcat to search?  todo: fix this with some AJAX to repopulate the form when container is changed
            boolean found = false;
            for (int i = 0; i < logNames.length; i++) {
                String test = logNames[i];
                if(test.equals(logToSearch)) {
                    found = true;
                    break;
                }
            }
            if(!found) { // Must has been for the other container -- make it work.
                logToSearch = logNames[0];
            }
        }

        String action = renderRequest.getParameter("action");
        if (criteria == null || (action != null && !"refresh".equals(action))) {
            if(criteria == null)
                criteria = new Criteria();
           
            String fromDate = renderRequest.getParameter("fromDate");
            String toDate = renderRequest.getParameter("toDate");
            String requestHost = renderRequest.getParameter("requestHost");
            String authUser = renderRequest.getParameter("authUser");
            String method = renderRequest.getParameter("requestMethod");
            String uri = renderRequest.getParameter("requestedURI");
            String result = renderRequest.getParameter("startResult");
            Integer max = criteria.maxResult;
            try{
                max = Integer.parseInt(renderRequest.getParameter("maxResult"));
            }catch(NumberFormatException e){
            //ignore
            }
            String ignoreDates = renderRequest.getParameter("ignoreDates");
           
            criteria.fromDate = fromDate == null || fromDate.equals("") ? null : fromDate;
            criteria.toDate = toDate == null || toDate.equals("") ? null : toDate;
            criteria.requestHost = requestHost == null || requestHost.equals("") ? null : requestHost;
            criteria.authUser = authUser == null || authUser.equals("") ? null : authUser;
            criteria.requestMethod = method == null || method.equals("") ? null : method;
            criteria.requestedURI = uri == null || uri.equals("") ? null : uri;
            criteria.startResult = result == null || result.equals("") ? null : result;
            criteria.maxResult = max;
            criteria.ignoreDates = ignoreDates != null && !ignoreDates.equals("")
        }
        String fromDateStr = criteria.fromDate;
        String toDateStr = criteria.toDate;

        Calendar cal1 = Calendar.getInstance(), cal2 = Calendar.getInstance();
        // If not all dates were passed and ignoreDates is not enabled, filter on the current date.
        // Note: This happens only when the portlet is loaded for the first time. Subsequent invocation (other than
        // using "Refresh") will have either ignoreDates enabled or both the dates non null.
        if((fromDateStr == null || toDateStr == null) && !criteria.ignoreDates) {
            // just keep the month date and year
            cal1.set(Calendar.MILLISECOND, 0);
            cal1.set(Calendar.MINUTE, 0);
            cal1.set(Calendar.SECOND, 0);
            cal1.set(Calendar.HOUR_OF_DAY, 0);

            cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
            cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
            cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
            cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));

            WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                        null, null, null, null, cal1.getTime(), cal2.getTime(), null, Integer.valueOf(criteria.maxResult.intValue()-1));
            renderRequest.setAttribute("logs", matchingItems.getResults());
            renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            renderRequest.setAttribute("maxResult", criteria.maxResult);
            renderRequest.setAttribute("ignoreDates", Boolean.valueOf(criteria.ignoreDates));
           
        } else {
            // Get other search criteria
            String requestHost = criteria.requestHost;
            String authUser = criteria.authUser;
            String requestMethod = criteria.requestMethod;
            String requestedURI = criteria.requestedURI;
            String startResult = criteria.startResult;
            Integer iStartResult = null;
            Integer iMaxResult = criteria.maxResult;
            try{
                iStartResult = Integer.valueOf(startResult);
            }catch(NumberFormatException e){
                //ignore
            }
           
            boolean ignoreDates = criteria.ignoreDates;
            if (ignoreDates) {
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, null, null, iStartResult, Integer.valueOf(iMaxResult.intValue()-1));
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            } else {
                Date fromDate = null, toDate = null;
                // Check if the from and to date format is MM/DD/YYYY
                DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
                try {
                    fromDate = df.parse(fromDateStr);
                    // get the requested start date (defaults to 00:00:00:000 for time)
                    cal1.setTime(fromDate);
                    String mmddyyyy = (cal1.get(Calendar.MONTH) < 9 ? "0":"") + (cal1.get(Calendar.MONTH)+1);
                    mmddyyyy += "/"+(cal1.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (cal1.get(Calendar.DAY_OF_MONTH));
                    mmddyyyy += "/"+cal1.get(Calendar.YEAR);
                    if(!mmddyyyy.equals(fromDateStr)) {
                        // This should not arise since date input has been validated using javascript.
                        // If this does occur, ignore dates in search criteria and log a WARNING
                        log.warn("From date must be a date in MM/DD/YYYY format, not '"+fromDateStr+"'. Dates will be ignored.");
                        fromDate = null;
                    }
                    toDate = df.parse(toDateStr);
                    cal2.setTime(toDate);
                    mmddyyyy = (cal2.get(Calendar.MONTH) < 9 ? "0":"") + (cal2.get(Calendar.MONTH)+1);
                    mmddyyyy += "/"+(cal2.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (cal2.get(Calendar.DAY_OF_MONTH));
                    mmddyyyy += "/"+cal2.get(Calendar.YEAR);
                    if(!mmddyyyy.equals(toDateStr)) {
                        // This should not arise since date input has been validated using javascript.
                        // If this does occur, ignore to date in search criteria and log a WARNING
                        log.warn("To date must be a date in MM/DD/YYYY format, not "+toDateStr+"'. Dates will be ignored.");
                        toDate = null;
                    } else {
                        // get the requested end date - Note: must set time to end of day
                        cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
                        cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
                        cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
                        cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));
                        toDate = cal2.getTime();
                    }
                } catch (ParseException e) {
                    // Should not occur since date input has been validated using javascript.
                    // If this does occur, ignore from and to dates and log a WARNING
                    log.warn("Error parsing input dates.  Dates will be ignored.", e);
                }
                if(fromDate == null || toDate == null) {
                    fromDate = toDate = null;
                }
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, fromDate, toDate, iStartResult, Integer.valueOf(iMaxResult.intValue()-1));
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            }
            renderRequest.setAttribute("ignoreDates", new Boolean(ignoreDates));
View Full Code Here


        if (names != null) {
            String managerName = names[0]//todo: handle multiple
            String[] containers = PortletManager.getWebContainerNames(renderRequest, managerName)//todo: handle multiple
            if (containers != null) {
                String containerName = containers[0]//todo: handle multiple
                WebAccessLog log = PortletManager.getWebAccessLog(renderRequest, managerName, containerName);

                String action = renderRequest.getParameter("action");
                if ("refresh".equals(action)) {
                    //todo: currently refreshes on every request; that's pretty slow.
                }


                //todo: completely revamp this argument processing
                String startDate = (String) renderRequest.getParameter("startDate");
                String startMonth = (String) renderRequest.getParameter("startMonth");
                String startYear = (String) renderRequest.getParameter("startYear");
                String endDate = (String) renderRequest.getParameter("endDate");
                String endMonth = (String) renderRequest.getParameter("endMonth");
                String endYear = (String) renderRequest.getParameter("endYear");

                Calendar cal1 = Calendar.getInstance(), cal2 = Calendar.getInstance();
                // If not all dates were passed we assume than no fields were passed and just
                // filter on the current date.
                if (startDate == null || startMonth == null || startYear == null
                        || endDate == null || endMonth == null || endYear == null) {
                    // just keep the month date and year
                    cal1.set(Calendar.MILLISECOND, 0);
                    cal1.set(Calendar.MINUTE, 0);
                    cal1.set(Calendar.SECOND, 0);
                    cal1.clear(Calendar.HOUR_OF_DAY);
                    cal2.setTime(cal1.getTime());
                    cal2.add(Calendar.DAY_OF_YEAR, 1);

                    WebAccessLog.SearchResults matchingItems = log.getMatchingItems(log.getLogFileNames()[0], //todo: handle multiple
                                                null, null, null, null, cal1.getTime(), cal2.getTime(), null, null);
                    renderRequest.setAttribute("logs", matchingItems.getResults());
                    renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
                } else {
                    int sdt = Integer.parseInt(startDate),
                        smnth = Integer.parseInt(startMonth),
                        syr = Integer.parseInt(startYear),
                        edt = Integer.parseInt(endDate),
                        emnth = Integer.parseInt(endMonth),
                        eyr = Integer.parseInt(endYear);
                    boolean ignoreDates = renderRequest.getParameter("ignoreDates") == null;
                    String requestHost = (String) renderRequest.getParameter("requestHost");
                    String authUser = (String) renderRequest.getParameter("authUser");
                    String requestMethod = (String) renderRequest.getParameter("requestMethod");
                    String requestedURI = (String) renderRequest.getParameter("requestedURI");
                    if (ignoreDates) {
                        cal1.clear();
                        cal2.clear();
                        cal1.set(Calendar.DATE, sdt);
                        cal1.set(Calendar.MONTH, smnth);
                        cal1.set(Calendar.YEAR, syr);
                        cal2.set(Calendar.DATE, edt);
                        cal2.set(Calendar.MONTH, emnth);
                        cal2.set(Calendar.YEAR, eyr);
                        WebAccessLog.SearchResults matchingItems = log.getMatchingItems(log.getLogFileNames()[0], //todo: handle multiple
                                                        requestHost, authUser, requestMethod, requestedURI, cal1.getTime(), cal2.getTime(), null, null);
                        renderRequest.setAttribute("logs", matchingItems.getResults());
                        renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
                    } else {
                        WebAccessLog.SearchResults matchingItems = log.getMatchingItems(log.getLogFileNames()[0], //todo: handle multiple
                                                        requestHost, authUser, requestMethod, requestedURI, null, null, null, null);
                        renderRequest.setAttribute("logs", matchingItems.getResults());
                        renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
                    }
                    renderRequest.setAttribute("ignoreDates", new Boolean(ignoreDates));
                    renderRequest.setAttribute("requestHost", requestHost);
                    renderRequest.setAttribute("authUser", authUser);
                    renderRequest.setAttribute("requestMethod", requestMethod);
                    renderRequest.setAttribute("requestedURI", requestedURI);

                }
                renderRequest.setAttribute("toDate", cal2.getTime());
                renderRequest.setAttribute("fromDate", cal1.getTime());
                searchView.include(renderRequest, renderRespose);
            } else {
                log.error("No web containers found");
            }
        } else {
            log.error("No web managers found");
        }
    }
View Full Code Here

//      We don't current enable this in the portlet anyway and at the moment it is just unnecessary data traveling back and forth.
//      chosenContainer = renderRequest.getParameter("selectedContainer");
//      if(chosenContainer != null) { // Carry on to render the results with the right selection
//          renderRequest.setAttribute("selectedContainer", chosenContainer);
//      }
        WebAccessLog chosenLog = null;
        if(managers != null) {
            for (int i = 0; i < managers.length; i++) {
                WebManager manager = managers[i];
                AbstractName managerName = PortletManager.getNameFor(renderRequest, manager);
                WebContainer[] containers = (WebContainer[]) manager.getContainers();
                if (containers != null) {
                    for (int j = 0; j < containers.length; j++) {
                        WebContainer container = containers[j];
                        AbstractName containerName = PortletManager.getNameFor(renderRequest, container);
                        String combined = managerName+"%"+containerName;
                        if(containers.length == 1) {
                            products.put(manager.getProductName(), combined);
                        } else {
                            products.put(manager.getProductName()+" ("+containerName.getName().get(NameFactory.J2EE_NAME)+")", combined);
                        }
                        if(chosenLog == null) { // will pick the correct match, or the first if no selection is specified
                            if(chosenContainer == null || chosenContainer.equals(combined)) {
                                chosenLog = PortletManager.getWebAccessLog(renderRequest, managerName, containerName);
                            }
                        }
                    }
                } else {
                    log.error("No web containers found for manager "+manager.getProductName());
                }
            }
        } else {
            log.error("No web managers found!");
        }
//      Temporarily disable container and log parameters. 
//      We don't current enable this in the portlet anyway and at the moment it is just unnecessary data traveling back and forth.
//      renderRequest.setAttribute("webContainers", products);
        final String[] logNames = chosenLog.getLogNames();
//      renderRequest.setAttribute("webLogs", logNames);
        String logToSearch = null;
//      String logToSearch = renderRequest.getParameter("selectedLog");
        if(logToSearch == null) {
            logToSearch = logNames[0];
        } else { //what if the log options for Jetty were showing, but the user picked Tomcat to search?  todo: fix this with some AJAX to repopulate the form when container is changed
            boolean found = false;
            for (int i = 0; i < logNames.length; i++) {
                String test = logNames[i];
                if(test.equals(logToSearch)) {
                    found = true;
                    break;
                }
            }
            if(!found) { // Must has been for the other container -- make it work.
                logToSearch = logNames[0];
            }
        }

        String action = renderRequest.getParameter("action");
        if (criteria == null || (action != null && !"refresh".equals(action))) {
            if(criteria == null)
                criteria = new Criteria();
           
            String fromDate = renderRequest.getParameter("fromDate");
            String toDate = renderRequest.getParameter("toDate");
            String requestHost = renderRequest.getParameter("requestHost");
            String authUser = renderRequest.getParameter("authUser");
            String method = renderRequest.getParameter("requestMethod");
            String uri = renderRequest.getParameter("requestedURI");
            String result = renderRequest.getParameter("startResult");
            Integer max = criteria.maxResult;
            try{
                max = Integer.parseInt(renderRequest.getParameter("maxResult"));
            }catch(NumberFormatException e){
            //ignore
            }
            String ignoreDates = renderRequest.getParameter("ignoreDates");
           
            criteria.fromDate = fromDate == null || fromDate.equals("") ? null : fromDate;
            criteria.toDate = toDate == null || toDate.equals("") ? null : toDate;
            criteria.requestHost = requestHost == null || requestHost.equals("") ? null : requestHost;
            criteria.authUser = authUser == null || authUser.equals("") ? null : authUser;
            criteria.requestMethod = method == null || method.equals("") ? null : method;
            criteria.requestedURI = uri == null || uri.equals("") ? null : uri;
            criteria.startResult = result == null || result.equals("") ? null : result;
            criteria.maxResult = max;
            criteria.ignoreDates = ignoreDates != null && !ignoreDates.equals("")
        }
        String fromDateStr = criteria.fromDate;
        String toDateStr = criteria.toDate;

        Calendar cal1 = Calendar.getInstance(), cal2 = Calendar.getInstance();
        // If not all dates were passed and ignoreDates is not enabled, filter on the current date.
        // Note: This happens only when the portlet is loaded for the first time. Subsequent invocation (other than
        // using "Refresh") will have either ignoreDates enabled or both the dates non null.
        if((fromDateStr == null || toDateStr == null) && !criteria.ignoreDates) {
            // just keep the month date and year
            cal1.set(Calendar.MILLISECOND, 0);
            cal1.set(Calendar.MINUTE, 0);
            cal1.set(Calendar.SECOND, 0);
            cal1.set(Calendar.HOUR_OF_DAY, 0);

            cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
            cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
            cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
            cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));

            WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                        null, null, null, null, cal1.getTime(), cal2.getTime(), null, Integer.valueOf(criteria.maxResult.intValue()-1));
            renderRequest.setAttribute("logs", matchingItems.getResults());
            renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            renderRequest.setAttribute("maxResult", criteria.maxResult);
            renderRequest.setAttribute("ignoreDates", Boolean.valueOf(criteria.ignoreDates));
           
        } else {
            // Get other search criteria
            String requestHost = criteria.requestHost;
            String authUser = criteria.authUser;
            String requestMethod = criteria.requestMethod;
            String requestedURI = criteria.requestedURI;
            String startResult = criteria.startResult;
            Integer iStartResult = null;
            Integer iMaxResult = criteria.maxResult;
            try{
                iStartResult = Integer.valueOf(startResult);
            }catch(NumberFormatException e){
                //ignore
            }
           
            boolean ignoreDates = criteria.ignoreDates;
            if (ignoreDates) {
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, null, null, iStartResult, Integer.valueOf(iMaxResult.intValue()-1));
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            } else {
                Date fromDate = null, toDate = null;
                // Check if the from and to date format is MM/DD/YYYY
                DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
                try {
                    fromDate = df.parse(fromDateStr);
                    // get the requested start date (defaults to 00:00:00:000 for time)
                    cal1.setTime(fromDate);
                    String mmddyyyy = (cal1.get(Calendar.MONTH) < 9 ? "0":"") + (cal1.get(Calendar.MONTH)+1);
                    mmddyyyy += "/"+(cal1.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (cal1.get(Calendar.DAY_OF_MONTH));
                    mmddyyyy += "/"+cal1.get(Calendar.YEAR);
                    if(!mmddyyyy.equals(fromDateStr)) {
                        // This should not arise since date input has been validated using javascript.
                        // If this does occur, ignore dates in search criteria and log a WARNING
                        log.warn("From date must be a date in MM/DD/YYYY format, not '"+fromDateStr+"'. Dates will be ignored.");
                        fromDate = null;
                    }
                    toDate = df.parse(toDateStr);
                    cal2.setTime(toDate);
                    mmddyyyy = (cal2.get(Calendar.MONTH) < 9 ? "0":"") + (cal2.get(Calendar.MONTH)+1);
                    mmddyyyy += "/"+(cal2.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (cal2.get(Calendar.DAY_OF_MONTH));
                    mmddyyyy += "/"+cal2.get(Calendar.YEAR);
                    if(!mmddyyyy.equals(toDateStr)) {
                        // This should not arise since date input has been validated using javascript.
                        // If this does occur, ignore to date in search criteria and log a WARNING
                        log.warn("To date must be a date in MM/DD/YYYY format, not "+toDateStr+"'. Dates will be ignored.");
                        toDate = null;
                    } else {
                        // get the requested end date - Note: must set time to end of day
                        cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
                        cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
                        cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
                        cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));
                        toDate = cal2.getTime();
                    }
                } catch (ParseException e) {
                    // Should not occur since date input has been validated using javascript.
                    // If this does occur, ignore from and to dates and log a WARNING
                    log.warn("Error parsing input dates.  Dates will be ignored.", e);
                }
                if(fromDate == null || toDate == null) {
                    fromDate = toDate = null;
                }
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, fromDate, toDate, iStartResult, Integer.valueOf(iMaxResult.intValue()-1));
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            }
            renderRequest.setAttribute("ignoreDates", new Boolean(ignoreDates));
View Full Code Here

        Map products = new LinkedHashMap();
        String chosen = renderRequest.getParameter("selectedContainer");
        if(chosen != null) { // Carry on to render the results with the right selection
            renderRequest.setAttribute("selectedContainer", chosen);
        }
        WebAccessLog chosenLog = null;
        if(managers != null) {
            for (int i = 0; i < managers.length; i++) {
                WebManager manager = managers[i];
                AbstractName managerName = PortletManager.getNameFor(renderRequest, manager);
                WebContainer[] containers = (WebContainer[]) manager.getContainers();
                if (containers != null) {
                    for (int j = 0; j < containers.length; j++) {
                        WebContainer container = containers[j];
                        AbstractName containerName = PortletManager.getNameFor(renderRequest, container);
                        String combined = managerName+"%"+containerName;
                        if(containers.length == 1) {
                            products.put(manager.getProductName(), combined);
                        } else {
                            products.put(manager.getProductName()+" ("+containerName.getName().get(NameFactory.J2EE_NAME)+")", combined);
                        }
                        if(chosenLog == null) { // will pick the correct match, or the first if no selection is specified
                            if(chosen == null || chosen.equals(combined)) {
                                chosenLog = PortletManager.getWebAccessLog(renderRequest, managerName, containerName);
                            }
                        }
                    }
                } else {
                    log.error("No web containers found for manager "+manager.getProductName());
                }
            }
        } else {
            log.error("No web managers found!");
        }
        renderRequest.setAttribute("webContainers", products);
        final String[] logNames = chosenLog.getLogNames();
        renderRequest.setAttribute("webLogs", logNames);
        String logToSearch = renderRequest.getParameter("selectedLog");
        if(logToSearch == null) {
            logToSearch = logNames[0];
        } else { //what if the log options for Jetty were showing, but the user picked Tomcat to search?  todo: fix this with some AJAX to repopulate the form when container is changed
            boolean found = false;
            for (int i = 0; i < logNames.length; i++) {
                String test = logNames[i];
                if(test.equals(logToSearch)) {
                    found = true;
                    break;
                }
            }
            if(!found) { // Must has been for the other container -- make it work.
                logToSearch = logNames[0];
            }
        }

        String action = renderRequest.getParameter("action");
        if ("refresh".equals(action)) {
            //todo: currently refreshes on every request; that's pretty slow.
        }

        String fromDateStr = (String) renderRequest.getParameter("fromDate");
        String toDateStr = (String) renderRequest.getParameter("toDate");

        Calendar cal1 = Calendar.getInstance(), cal2 = Calendar.getInstance();
        // If not all dates were passed we assume than no fields were passed and just
        // filter on the current date.
        if(fromDateStr == null || toDateStr == null) {
            // just keep the month date and year
            cal1.set(Calendar.MILLISECOND, 0);
            cal1.set(Calendar.MINUTE, 0);
            cal1.set(Calendar.SECOND, 0);
            cal1.set(Calendar.HOUR_OF_DAY, 0);

            cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
            cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
            cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
            cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));

            WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                        null, null, null, null, cal1.getTime(), cal2.getTime(), null, Integer.valueOf(DEFAULT_MAX_RESULTS - 1));
            renderRequest.setAttribute("logs", matchingItems.getResults());
            renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            renderRequest.setAttribute("maxResult", Integer.valueOf(DEFAULT_MAX_RESULTS));
        } else {
            // Get other search criteria
            String requestHost = (String) renderRequest.getParameter("requestHost");
            String authUser = (String) renderRequest.getParameter("authUser");
            String requestMethod = (String) renderRequest.getParameter("requestMethod");
            String requestedURI = (String) renderRequest.getParameter("requestedURI");
            String startResult = (String) renderRequest.getParameter("startResult");
            String maxResult = (String) renderRequest.getParameter("maxResult");
            Integer iStartResult = null;
            Integer iMaxResult = Integer.valueOf(DEFAULT_MAX_RESULTS);
            try{
                iStartResult = Integer.valueOf(startResult);
            }catch(NumberFormatException e){
                //ignore
            }
            try{
                iMaxResult = Integer.valueOf(maxResult);
            }catch(NumberFormatException e){
                //ignore
            }
           
            boolean ignoreDates = renderRequest.getParameter("ignoreDates") != null;
            if (ignoreDates) {
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, null, null, iStartResult, Integer.valueOf(iMaxResult.intValue()-1));
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            } else {
                Date fromDate = null, toDate = null;
                // Check if the from and to date format is MM/DD/YYYY
                DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
                try {
                    fromDate = df.parse(fromDateStr);
                    // get the requested start date (defaults to 00:00:00:000 for time)
                    cal1.setTime(fromDate);
                    String mmddyyyy = (cal1.get(Calendar.MONTH) < 9 ? "0":"") + (cal1.get(Calendar.MONTH)+1);
                    mmddyyyy += "/"+(cal1.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (cal1.get(Calendar.DAY_OF_MONTH));
                    mmddyyyy += "/"+cal1.get(Calendar.YEAR);
                    if(!mmddyyyy.equals(fromDateStr)) {
                        // This should not arise since date input has been validated using javascript.
                        // If this does occur, ignore dates in search criteria and log a WARNING
                        log.warn("From date must be a date in MM/DD/YYYY format, not '"+fromDateStr+"'. Dates will be ignored.");
                        fromDate = null;
                    }
                    toDate = df.parse(toDateStr);
                    cal2.setTime(toDate);
                    mmddyyyy = (cal2.get(Calendar.MONTH) < 9 ? "0":"") + (cal2.get(Calendar.MONTH)+1);
                    mmddyyyy += "/"+(cal2.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (cal2.get(Calendar.DAY_OF_MONTH));
                    mmddyyyy += "/"+cal2.get(Calendar.YEAR);
                    if(!mmddyyyy.equals(toDateStr)) {
                        // This should not arise since date input has been validated using javascript.
                        // If this does occur, ignore to date in search criteria and log a WARNING
                        log.warn("To date must be a date in MM/DD/YYYY format, not "+toDateStr+"'. Dates will be ignored.");
                        toDate = null;
                    } else {
                        // get the requested end date - Note: must set time to end of day
                        cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
                        cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
                        cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
                        cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));
                        toDate = cal2.getTime();
                    }
                } catch (ParseException e) {
                    // Should not occur since date input has been validated using javascript.
                    // If this does occur, ignore from and to dates and log a WARNING
                    log.warn("Error parsing input dates.  Dates will be ignored.", e);
                }
                if(fromDate == null || toDate == null) {
                    fromDate = toDate = null;
                }
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, fromDate, toDate, iStartResult, Integer.valueOf(iMaxResult.intValue()-1));
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            }
            if (ignoreDates) renderRequest.setAttribute("ignoreDates", new Boolean(ignoreDates));
View Full Code Here

//      We don't current enable this in the portlet anyway and at the moment it is just unnecessary data traveling back and forth.
//      chosenContainer = renderRequest.getParameter("selectedContainer");
//      if(chosenContainer != null) { // Carry on to render the results with the right selection
//          renderRequest.setAttribute("selectedContainer", chosenContainer);
//      }
        WebAccessLog chosenLog = null;
        if(managers != null) {
            for (int i = 0; i < managers.length; i++) {
                WebManager manager = managers[i];
                AbstractName managerName = PortletManager.getNameFor(renderRequest, manager);
                WebContainer[] containers = (WebContainer[]) manager.getContainers();
                if (containers != null) {
                    for (int j = 0; j < containers.length; j++) {
                        WebContainer container = containers[j];
                        AbstractName containerName = PortletManager.getNameFor(renderRequest, container);
                        String combined = managerName+"%"+containerName;
                        if(containers.length == 1) {
                            products.put(manager.getProductName(), combined);
                        } else {
                            products.put(manager.getProductName()+" ("+containerName.getName().get(NameFactory.J2EE_NAME)+")", combined);
                        }
                        if(chosenLog == null) { // will pick the correct match, or the first if no selection is specified
                            if(chosenContainer == null || chosenContainer.equals(combined)) {
                                chosenLog = PortletManager.getWebAccessLog(renderRequest, managerName, containerName);
                            }
                        }
                    }
                } else {
                    log.error("No web containers found for manager "+manager.getProductName());
                }
            }
        } else {
            log.error("No web managers found!");
        }
//      Temporarily disable container and log parameters. 
//      We don't current enable this in the portlet anyway and at the moment it is just unnecessary data traveling back and forth.
//      renderRequest.setAttribute("webContainers", products);
        String[] logNames = chosenLog.getLogNames();
        if (logNames.length == 0) {
            searchView.include(renderRequest, renderRespose);
            return;
        }
//      renderRequest.setAttribute("webLogs", logNames);
        String logToSearch = null;
//      String logToSearch = renderRequest.getParameter("selectedLog");
        if(logToSearch == null) {
            logToSearch = logNames[0];
        } else { //what if the log options for Jetty were showing, but the user picked Tomcat to search?  todo: fix this with some AJAX to repopulate the form when container is changed
            boolean found = false;
            for (int i = 0; i < logNames.length; i++) {
                String test = logNames[i];
                if(test.equals(logToSearch)) {
                    found = true;
                    break;
                }
            }
            if(!found) { // Must has been for the other container -- make it work.
                logToSearch = logNames[0];
            }
        }

        String action = renderRequest.getParameter("action");
        if (criteria == null || (action != null && !"refresh".equals(action))) {
            if(criteria == null)
                criteria = new Criteria();
           
            String fromDate = renderRequest.getParameter("fromDate");
            String toDate = renderRequest.getParameter("toDate");
            String requestHost = renderRequest.getParameter("requestHost");
            String authUser = renderRequest.getParameter("authUser");
            String method = renderRequest.getParameter("requestMethod");
            String uri = renderRequest.getParameter("requestedURI");
            String result = renderRequest.getParameter("startResult");
            Integer max = criteria.maxResult;
            try{
                max = Integer.parseInt(renderRequest.getParameter("maxResult"));
            }catch(NumberFormatException e){
            //ignore
            }
            String ignoreDates = renderRequest.getParameter("ignoreDates");
           
            criteria.fromDate = fromDate == null || fromDate.equals("") ? null : fromDate;
            criteria.toDate = toDate == null || toDate.equals("") ? null : toDate;
            criteria.requestHost = requestHost == null || requestHost.equals("") ? null : requestHost;
            criteria.authUser = authUser == null || authUser.equals("") ? null : authUser;
            criteria.requestMethod = method == null || method.equals("") ? null : method;
            criteria.requestedURI = uri == null || uri.equals("") ? null : uri;
            criteria.startResult = result == null || result.equals("") ? null : result;
            criteria.maxResult = max;
            criteria.ignoreDates = ignoreDates != null && !ignoreDates.equals("")
        }
        String fromDateStr = criteria.fromDate;
        String toDateStr = criteria.toDate;

        Calendar cal1 = Calendar.getInstance(), cal2 = Calendar.getInstance();
        // If not all dates were passed and ignoreDates is not enabled, filter on the current date.
        // Note: This happens only when the portlet is loaded for the first time. Subsequent invocation (other than
        // using "Refresh") will have either ignoreDates enabled or both the dates non null.
        if((fromDateStr == null || toDateStr == null) && !criteria.ignoreDates) {
            // just keep the month date and year
            cal1.set(Calendar.MILLISECOND, 0);
            cal1.set(Calendar.MINUTE, 0);
            cal1.set(Calendar.SECOND, 0);
            cal1.set(Calendar.HOUR_OF_DAY, 0);

            cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
            cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
            cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
            cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));

            WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                        null, null, null, null, cal1.getTime(), cal2.getTime(), null, Integer.valueOf(criteria.maxResult.intValue()-1));
            renderRequest.setAttribute("logs", matchingItems.getResults());
            renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            renderRequest.setAttribute("maxResult", criteria.maxResult);
            renderRequest.setAttribute("ignoreDates", Boolean.valueOf(criteria.ignoreDates));
           
        } else {
            // Get other search criteria
            String requestHost = criteria.requestHost;
            String authUser = criteria.authUser;
            String requestMethod = criteria.requestMethod;
            String requestedURI = criteria.requestedURI;
            String startResult = criteria.startResult;
            Integer iStartResult = null;
            Integer iMaxResult = criteria.maxResult;
            try{
                iStartResult = Integer.valueOf(startResult);
            }catch(NumberFormatException e){
                //ignore
            }
           
            boolean ignoreDates = criteria.ignoreDates;
            if (ignoreDates) {
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, null, null, iStartResult, Integer.valueOf(iMaxResult.intValue()-1));
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            } else {
                Date fromDate = null, toDate = null;
                // Check if the from and to date format is MM/DD/YYYY
                DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
                try {
                    fromDate = df.parse(fromDateStr);
                    // get the requested start date (defaults to 00:00:00:000 for time)
                    cal1.setTime(fromDate);
                    String mmddyyyy = (cal1.get(Calendar.MONTH) < 9 ? "0":"") + (cal1.get(Calendar.MONTH)+1);
                    mmddyyyy += "/"+(cal1.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (cal1.get(Calendar.DAY_OF_MONTH));
                    mmddyyyy += "/"+cal1.get(Calendar.YEAR);
                    if(!mmddyyyy.equals(fromDateStr)) {
                        // This should not arise since date input has been validated using javascript.
                        // If this does occur, ignore dates in search criteria and log a WARNING
                        log.warn("From date must be a date in MM/DD/YYYY format, not '"+fromDateStr+"'. Dates will be ignored.");
                        fromDate = null;
                    }
                    toDate = df.parse(toDateStr);
                    cal2.setTime(toDate);
                    mmddyyyy = (cal2.get(Calendar.MONTH) < 9 ? "0":"") + (cal2.get(Calendar.MONTH)+1);
                    mmddyyyy += "/"+(cal2.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (cal2.get(Calendar.DAY_OF_MONTH));
                    mmddyyyy += "/"+cal2.get(Calendar.YEAR);
                    if(!mmddyyyy.equals(toDateStr)) {
                        // This should not arise since date input has been validated using javascript.
                        // If this does occur, ignore to date in search criteria and log a WARNING
                        log.warn("To date must be a date in MM/DD/YYYY format, not "+toDateStr+"'. Dates will be ignored.");
                        toDate = null;
                    } else {
                        // get the requested end date - Note: must set time to end of day
                        cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
                        cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
                        cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
                        cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));
                        toDate = cal2.getTime();
                    }
                } catch (ParseException e) {
                    // Should not occur since date input has been validated using javascript.
                    // If this does occur, ignore from and to dates and log a WARNING
                    log.warn("Error parsing input dates.  Dates will be ignored.", e);
                }
                if(fromDate == null || toDate == null) {
                    fromDate = toDate = null;
                }
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, fromDate, toDate, iStartResult, Integer.valueOf(iMaxResult.intValue()-1));
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            }
            renderRequest.setAttribute("ignoreDates", new Boolean(ignoreDates));
View Full Code Here

//      We don't current enable this in the portlet anyway and at the moment it is just unnecessary data traveling back and forth.
//      chosenContainer = renderRequest.getParameter("selectedContainer");
//      if(chosenContainer != null) { // Carry on to render the results with the right selection
//          renderRequest.setAttribute("selectedContainer", chosenContainer);
//      }
        WebAccessLog chosenLog = null;
        if(managers != null) {
            for (int i = 0; i < managers.length; i++) {
                WebManager manager = managers[i];
                AbstractName managerName = PortletManager.getNameFor(renderRequest, manager);
                WebContainer[] containers = (WebContainer[]) manager.getContainers();
                if (containers != null) {
                    for (int j = 0; j < containers.length; j++) {
                        WebContainer container = containers[j];
                        AbstractName containerName = PortletManager.getNameFor(renderRequest, container);
                        String combined = managerName+"%"+containerName;
                        if(containers.length == 1) {
                            products.put(manager.getProductName(), combined);
                        } else {
                            products.put(manager.getProductName()+" ("+containerName.getName().get(NameFactory.J2EE_NAME)+")", combined);
                        }
                        if(chosenLog == null) { // will pick the correct match, or the first if no selection is specified
                            if(chosenContainer == null || chosenContainer.equals(combined)) {
                                chosenLog = PortletManager.getWebAccessLog(renderRequest, managerName, containerName);
                            }
                        }
                    }
                } else {
                    log.error("No web containers found for manager "+manager.getProductName());
                }
            }
        } else {
            log.error("No web managers found!");
        }
//      Temporarily disable container and log parameters.
//      We don't current enable this in the portlet anyway and at the moment it is just unnecessary data traveling back and forth.
//      renderRequest.setAttribute("webContainers", products);
        String[] logNames = chosenLog.getLogNames();
        if (logNames.length == 0) {
            searchView.include(renderRequest, renderRespose);
            return;
        }
//      renderRequest.setAttribute("webLogs", logNames);
        String logToSearch = null;
//      String logToSearch = renderRequest.getParameter("selectedLog");
        if(logToSearch == null) {
            logToSearch = logNames[0];
        } else { //what if the log options for Jetty were showing, but the user picked Tomcat to search?  todo: fix this with some AJAX to repopulate the form when container is changed
            boolean found = false;
            for (int i = 0; i < logNames.length; i++) {
                String test = logNames[i];
                if(test.equals(logToSearch)) {
                    found = true;
                    break;
                }
            }
            if(!found) { // Must has been for the other container -- make it work.
                logToSearch = logNames[0];
            }
        }

        String action = renderRequest.getParameter("action");
        if (criteria == null || (action != null && !"refresh".equals(action))) {
            if(criteria == null)
                criteria = new Criteria();

            String fromDate = renderRequest.getParameter("fromDate");
            String toDate = renderRequest.getParameter("toDate");
            String requestHost = renderRequest.getParameter("requestHost");
            String authUser = renderRequest.getParameter("authUser");
            String method = renderRequest.getParameter("requestMethod");
            String uri = renderRequest.getParameter("requestedURI");
            String result = renderRequest.getParameter("startResult");
            Integer max = criteria.maxResult;
            try{
                max = Integer.parseInt(renderRequest.getParameter("maxResult"));
            }catch(NumberFormatException e){
            //ignore
            }
            String ignoreDates = renderRequest.getParameter("ignoreDates");

            criteria.fromDate = fromDate == null || fromDate.equals("") ? null : fromDate;
            criteria.toDate = toDate == null || toDate.equals("") ? null : toDate;
            criteria.requestHost = requestHost == null || requestHost.equals("") ? null : requestHost;
            criteria.authUser = authUser == null || authUser.equals("") ? null : authUser;
            criteria.requestMethod = method == null || method.equals("") ? null : method;
            criteria.requestedURI = uri == null || uri.equals("") ? null : uri;
            criteria.startResult = result == null || result.equals("") ? null : result;
            criteria.maxResult = max;
            criteria.ignoreDates = ignoreDates != null && !ignoreDates.equals("");
        }
        String fromDateStr = criteria.fromDate;
        String toDateStr = criteria.toDate;

        Calendar cal1 = Calendar.getInstance(), cal2 = Calendar.getInstance();
        // If not all dates were passed and ignoreDates is not enabled, filter on the current date.
        // Note: This happens only when the portlet is loaded for the first time. Subsequent invocation (other than
        // using "Refresh") will have either ignoreDates enabled or both the dates non null.
        if((fromDateStr == null || toDateStr == null) && !criteria.ignoreDates) {
            // just keep the month date and year
            cal1.set(Calendar.MILLISECOND, 0);
            cal1.set(Calendar.MINUTE, 0);
            cal1.set(Calendar.SECOND, 0);
            cal1.set(Calendar.HOUR_OF_DAY, 0);

            cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
            cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
            cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
            cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));

            WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                        null, null, null, null, cal1.getTime(), cal2.getTime(), null, Integer.valueOf(criteria.maxResult.intValue()-1));
            renderRequest.setAttribute("logs", matchingItems.getResults());
            renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            renderRequest.setAttribute("maxResult", criteria.maxResult);
            renderRequest.setAttribute("ignoreDates", Boolean.valueOf(criteria.ignoreDates));

        } else {
            // Get other search criteria
            String requestHost = criteria.requestHost;
            String authUser = criteria.authUser;
            String requestMethod = criteria.requestMethod;
            String requestedURI = criteria.requestedURI;
            String startResult = criteria.startResult;
            Integer iStartResult = null;
            Integer iMaxResult = criteria.maxResult;
            try{
                iStartResult = Integer.valueOf(startResult);
            }catch(NumberFormatException e){
                //ignore
            }

            boolean ignoreDates = criteria.ignoreDates;
            if (ignoreDates) {
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, null, null, iStartResult, Integer.valueOf(iMaxResult.intValue()-1));
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            } else {
                Date fromDate = null, toDate = null;
                // Check if the from and to date format is MM/DD/YYYY
                DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
                try {
                    fromDate = df.parse(fromDateStr);
                    // get the requested start date (defaults to 00:00:00:000 for time)
                    cal1.setTime(fromDate);
                    String mmddyyyy = (cal1.get(Calendar.MONTH) < 9 ? "0":"") + (cal1.get(Calendar.MONTH)+1);
                    mmddyyyy += "/"+(cal1.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (cal1.get(Calendar.DAY_OF_MONTH));
                    mmddyyyy += "/"+cal1.get(Calendar.YEAR);
                    if(!mmddyyyy.equals(fromDateStr)) {
                        // This should not arise since date input has been validated using javascript.
                        // If this does occur, ignore dates in search criteria and log a WARNING
                        log.warn("From date must be a date in MM/DD/YYYY format, not '"+fromDateStr+"'. Dates will be ignored.");
                        fromDate = null;
                    }
                    toDate = df.parse(toDateStr);
                    cal2.setTime(toDate);
                    mmddyyyy = (cal2.get(Calendar.MONTH) < 9 ? "0":"") + (cal2.get(Calendar.MONTH)+1);
                    mmddyyyy += "/"+(cal2.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (cal2.get(Calendar.DAY_OF_MONTH));
                    mmddyyyy += "/"+cal2.get(Calendar.YEAR);
                    if(!mmddyyyy.equals(toDateStr)) {
                        // This should not arise since date input has been validated using javascript.
                        // If this does occur, ignore to date in search criteria and log a WARNING
                        log.warn("To date must be a date in MM/DD/YYYY format, not "+toDateStr+"'. Dates will be ignored.");
                        toDate = null;
                    } else {
                        // get the requested end date - Note: must set time to end of day
                        cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
                        cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
                        cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
                        cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));
                        toDate = cal2.getTime();
                    }
                } catch (ParseException e) {
                    // Should not occur since date input has been validated using javascript.
                    // If this does occur, ignore from and to dates and log a WARNING
                    log.warn("Error parsing input dates.  Dates will be ignored.", e);
                }
                if(fromDate == null || toDate == null) {
                    fromDate = toDate = null;
                }
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, fromDate, toDate, iStartResult, Integer.valueOf(iMaxResult.intValue()-1));
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", Integer.valueOf(matchingItems.getLineCount()));
            }
            renderRequest.setAttribute("ignoreDates", Boolean.valueOf(ignoreDates));
View Full Code Here

        Map products = new LinkedHashMap();
        String chosen = renderRequest.getParameter("selectedContainer");
        if(chosen != null) { // Carry on to render the results with the right selection
            renderRequest.setAttribute("selectedContainer", chosen);
        }
        WebAccessLog chosenLog = null;
        if(managers != null) {
            for (int i = 0; i < managers.length; i++) {
                WebManager manager = managers[i];
                AbstractName managerName = PortletManager.getNameFor(renderRequest, manager);
                WebContainer[] containers = (WebContainer[]) manager.getContainers();
                if (containers != null) {
                    for (int j = 0; j < containers.length; j++) {
                        WebContainer container = containers[j];
                        AbstractName containerName = PortletManager.getNameFor(renderRequest, container);
                        String combined = managerName+"%"+containerName;
                        if(containers.length == 1) {
                            products.put(manager.getProductName(), combined);
                        } else {
                            products.put(manager.getProductName()+" ("+containerName.getName().get(NameFactory.J2EE_NAME)+")", combined);
                        }
                        if(chosenLog == null) { // will pick the correct match, or the first if no selection is specified
                            if(chosen == null || chosen.equals(combined)) {
                                chosenLog = PortletManager.getWebAccessLog(renderRequest, managerName, containerName);
                            }
                        }
                    }
                } else {
                    log.error("No web containers found for manager "+manager.getProductName());
                }
            }
        } else {
            log.error("No web managers found!");
        }
        renderRequest.setAttribute("webContainers", products);
        final String[] logNames = chosenLog.getLogNames();
        renderRequest.setAttribute("webLogs", logNames);
        String logToSearch = renderRequest.getParameter("selectedLog");
        if(logToSearch == null) {
            logToSearch = logNames[0];
        } else { //what if the log options for Jetty were showing, but the user picked Tomcat to search?  todo: fix this with some AJAX to repopulate the form when container is changed
            boolean found = false;
            for (int i = 0; i < logNames.length; i++) {
                String test = logNames[i];
                if(test.equals(logToSearch)) {
                    found = true;
                    break;
                }
            }
            if(!found) { // Must has been for the other container -- make it work.
                logToSearch = logNames[0];
            }
        }

        String action = renderRequest.getParameter("action");
        if (criteria == null || (action != null && !"refresh".equals(action))) {
            if(criteria == null)
                criteria = new Criteria();
           
            String fromDate = renderRequest.getParameter("fromDate");
            String toDate = renderRequest.getParameter("toDate");
            String requestHost = renderRequest.getParameter("requestHost");
            String authUser = renderRequest.getParameter("authUser");
            String method = renderRequest.getParameter("requestMethod");
            String uri = renderRequest.getParameter("requestedURI");
            String result = renderRequest.getParameter("startResult");
            Integer max = criteria.maxResult;
            try{
                max = Integer.parseInt(renderRequest.getParameter("maxResult"));
            }catch(NumberFormatException e){
            //ignore
            }
            String ignoreDates = renderRequest.getParameter("ignoreDates");
           
            criteria.fromDate = fromDate == null || fromDate.equals("") ? null : fromDate;
            criteria.toDate = toDate == null || toDate.equals("") ? null : toDate;
            criteria.requestHost = requestHost == null || requestHost.equals("") ? null : requestHost;
            criteria.authUser = authUser == null || authUser.equals("") ? null : authUser;
            criteria.requestMethod = method == null || method.equals("") ? null : method;
            criteria.requestedURI = uri == null || uri.equals("") ? null : uri;
            criteria.startResult = result == null || result.equals("") ? null : result;
            criteria.maxResult = max;
            criteria.ignoreDates = ignoreDates != null && !ignoreDates.equals("")
        }
        String fromDateStr = criteria.fromDate;
        String toDateStr = criteria.toDate;

        Calendar cal1 = Calendar.getInstance(), cal2 = Calendar.getInstance();
        // If not all dates were passed and ignoreDates is not enabled, filter on the current date.
        // Note: This happens only when the portlet is loaded for the first time. Subsequent invocation (other than
        // using "Refresh") will have either ignoreDates enabled or both the dates non null.
        if((fromDateStr == null || toDateStr == null) && !criteria.ignoreDates) {
            // just keep the month date and year
            cal1.set(Calendar.MILLISECOND, 0);
            cal1.set(Calendar.MINUTE, 0);
            cal1.set(Calendar.SECOND, 0);
            cal1.set(Calendar.HOUR_OF_DAY, 0);

            cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
            cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
            cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
            cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));

            WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                        null, null, null, null, cal1.getTime(), cal2.getTime(), null, Integer.valueOf(criteria.maxResult.intValue()-1));
            renderRequest.setAttribute("logs", matchingItems.getResults());
            renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            renderRequest.setAttribute("maxResult", criteria.maxResult);
            renderRequest.setAttribute("ignoreDates", Boolean.valueOf(criteria.ignoreDates));
           
        } else {
            // Get other search criteria
            String requestHost = criteria.requestHost;
            String authUser = criteria.authUser;
            String requestMethod = criteria.requestMethod;
            String requestedURI = criteria.requestedURI;
            String startResult = criteria.startResult;
            Integer iStartResult = null;
            Integer iMaxResult = criteria.maxResult;
            try{
                iStartResult = Integer.valueOf(startResult);
            }catch(NumberFormatException e){
                //ignore
            }
           
            boolean ignoreDates = criteria.ignoreDates;
            if (ignoreDates) {
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, null, null, iStartResult, Integer.valueOf(iMaxResult.intValue()-1));
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            } else {
                Date fromDate = null, toDate = null;
                // Check if the from and to date format is MM/DD/YYYY
                DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
                try {
                    fromDate = df.parse(fromDateStr);
                    // get the requested start date (defaults to 00:00:00:000 for time)
                    cal1.setTime(fromDate);
                    String mmddyyyy = (cal1.get(Calendar.MONTH) < 9 ? "0":"") + (cal1.get(Calendar.MONTH)+1);
                    mmddyyyy += "/"+(cal1.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (cal1.get(Calendar.DAY_OF_MONTH));
                    mmddyyyy += "/"+cal1.get(Calendar.YEAR);
                    if(!mmddyyyy.equals(fromDateStr)) {
                        // This should not arise since date input has been validated using javascript.
                        // If this does occur, ignore dates in search criteria and log a WARNING
                        log.warn("From date must be a date in MM/DD/YYYY format, not '"+fromDateStr+"'. Dates will be ignored.");
                        fromDate = null;
                    }
                    toDate = df.parse(toDateStr);
                    cal2.setTime(toDate);
                    mmddyyyy = (cal2.get(Calendar.MONTH) < 9 ? "0":"") + (cal2.get(Calendar.MONTH)+1);
                    mmddyyyy += "/"+(cal2.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (cal2.get(Calendar.DAY_OF_MONTH));
                    mmddyyyy += "/"+cal2.get(Calendar.YEAR);
                    if(!mmddyyyy.equals(toDateStr)) {
                        // This should not arise since date input has been validated using javascript.
                        // If this does occur, ignore to date in search criteria and log a WARNING
                        log.warn("To date must be a date in MM/DD/YYYY format, not "+toDateStr+"'. Dates will be ignored.");
                        toDate = null;
                    } else {
                        // get the requested end date - Note: must set time to end of day
                        cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
                        cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
                        cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
                        cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));
                        toDate = cal2.getTime();
                    }
                } catch (ParseException e) {
                    // Should not occur since date input has been validated using javascript.
                    // If this does occur, ignore from and to dates and log a WARNING
                    log.warn("Error parsing input dates.  Dates will be ignored.", e);
                }
                if(fromDate == null || toDate == null) {
                    fromDate = toDate = null;
                }
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, fromDate, toDate, iStartResult, Integer.valueOf(iMaxResult.intValue()-1));
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            }
            renderRequest.setAttribute("ignoreDates", new Boolean(ignoreDates));
View Full Code Here

        Map products = new LinkedHashMap();
        String chosen = renderRequest.getParameter("selectedContainer");
        if(chosen != null) { // Carry on to render the results with the right selection
            renderRequest.setAttribute("selectedContainer", chosen);
        }
        WebAccessLog chosenLog = null;
        if(managers != null) {
            for (int i = 0; i < managers.length; i++) {
                WebManager manager = managers[i];
                AbstractName managerName = PortletManager.getNameFor(renderRequest, manager);
                WebContainer[] containers = (WebContainer[]) manager.getContainers();
                if (containers != null) {
                    for (int j = 0; j < containers.length; j++) {
                        WebContainer container = containers[j];
                        AbstractName containerName = PortletManager.getNameFor(renderRequest, container);
                        String combined = managerName+"%"+containerName;
                        if(containers.length == 1) {
                            products.put(manager.getProductName(), combined);
                        } else {
                            products.put(manager.getProductName()+" ("+containerName.getName().get(NameFactory.J2EE_NAME)+")", combined);
                        }
                        if(chosenLog == null) { // will pick the correct match, or the first if no selection is specified
                            if(chosen == null || chosen.equals(combined)) {
                                chosenLog = PortletManager.getWebAccessLog(renderRequest, managerName, containerName);
                            }
                        }
                    }
                } else {
                    log.error("No web containers found for manager "+manager.getProductName());
                }
            }
        } else {
            log.error("No web managers found!");
        }
        renderRequest.setAttribute("webContainers", products);
        final String[] logNames = chosenLog.getLogNames();
        renderRequest.setAttribute("webLogs", logNames);
        String logToSearch = renderRequest.getParameter("selectedLog");
        if(logToSearch == null) {
            logToSearch = logNames[0];
        } else { //what if the log options for Jetty were showing, but the user picked Tomcat to search?  todo: fix this with some AJAX to repopulate the form when container is changed
            boolean found = false;
            for (int i = 0; i < logNames.length; i++) {
                String test = logNames[i];
                if(test.equals(logToSearch)) {
                    found = true;
                    break;
                }
            }
            if(!found) { // Must has been for the other container -- make it work.
                logToSearch = logNames[0];
            }
        }

        String action = renderRequest.getParameter("action");
        if (criteria == null || (action != null && !"refresh".equals(action))) {
            if(criteria == null)
                criteria = new Criteria();
           
            String fromDate = renderRequest.getParameter("fromDate");
            String toDate = renderRequest.getParameter("toDate");
            String requestHost = renderRequest.getParameter("requestHost");
            String authUser = renderRequest.getParameter("authUser");
            String method = renderRequest.getParameter("requestMethod");
            String uri = renderRequest.getParameter("requestedURI");
            String result = renderRequest.getParameter("startResult");
            Integer max = criteria.maxResult;
            try{
                max = Integer.parseInt(renderRequest.getParameter("maxResult"));
            }catch(NumberFormatException e){
            //ignore
            }
            String ignoreDates = renderRequest.getParameter("ignoreDates");
           
            criteria.fromDate = fromDate == null || fromDate.equals("") ? null : fromDate;
            criteria.toDate = toDate == null || toDate.equals("") ? null : toDate;
            criteria.requestHost = requestHost == null || requestHost.equals("") ? null : requestHost;
            criteria.authUser = authUser == null || authUser.equals("") ? null : authUser;
            criteria.requestMethod = method == null || method.equals("") ? null : method;
            criteria.requestedURI = uri == null || uri.equals("") ? null : uri;
            criteria.startResult = result == null || result.equals("") ? null : result;
            criteria.maxResult = max;
            criteria.ignoreDates = ignoreDates != null && !ignoreDates.equals("")
        }
        String fromDateStr = criteria.fromDate;
        String toDateStr = criteria.toDate;

        Calendar cal1 = Calendar.getInstance(), cal2 = Calendar.getInstance();
        // If not all dates were passed we assume than no fields were passed and just
        // filter on the current date.
        if(fromDateStr == null || toDateStr == null) {
            // just keep the month date and year
            cal1.set(Calendar.MILLISECOND, 0);
            cal1.set(Calendar.MINUTE, 0);
            cal1.set(Calendar.SECOND, 0);
            cal1.set(Calendar.HOUR_OF_DAY, 0);

            cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
            cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
            cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
            cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));

            WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                        null, null, null, null, cal1.getTime(), cal2.getTime(), null, Integer.valueOf(criteria.maxResult.intValue()-1));
            renderRequest.setAttribute("logs", matchingItems.getResults());
            renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            renderRequest.setAttribute("maxResult", criteria.maxResult);
            renderRequest.setAttribute("ignoreDates", Boolean.valueOf(criteria.ignoreDates));
           
        } else {
            // Get other search criteria
            String requestHost = criteria.requestHost;
            String authUser = criteria.authUser;
            String requestMethod = criteria.requestMethod;
            String requestedURI = criteria.requestedURI;
            String startResult = criteria.startResult;
            Integer iStartResult = null;
            Integer iMaxResult = criteria.maxResult;
            try{
                iStartResult = Integer.valueOf(startResult);
            }catch(NumberFormatException e){
                //ignore
            }
           
            boolean ignoreDates = criteria.ignoreDates;
            if (ignoreDates) {
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, null, null, iStartResult, Integer.valueOf(iMaxResult.intValue()-1));
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            } else {
                Date fromDate = null, toDate = null;
                // Check if the from and to date format is MM/DD/YYYY
                DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
                try {
                    fromDate = df.parse(fromDateStr);
                    // get the requested start date (defaults to 00:00:00:000 for time)
                    cal1.setTime(fromDate);
                    String mmddyyyy = (cal1.get(Calendar.MONTH) < 9 ? "0":"") + (cal1.get(Calendar.MONTH)+1);
                    mmddyyyy += "/"+(cal1.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (cal1.get(Calendar.DAY_OF_MONTH));
                    mmddyyyy += "/"+cal1.get(Calendar.YEAR);
                    if(!mmddyyyy.equals(fromDateStr)) {
                        // This should not arise since date input has been validated using javascript.
                        // If this does occur, ignore dates in search criteria and log a WARNING
                        log.warn("From date must be a date in MM/DD/YYYY format, not '"+fromDateStr+"'. Dates will be ignored.");
                        fromDate = null;
                    }
                    toDate = df.parse(toDateStr);
                    cal2.setTime(toDate);
                    mmddyyyy = (cal2.get(Calendar.MONTH) < 9 ? "0":"") + (cal2.get(Calendar.MONTH)+1);
                    mmddyyyy += "/"+(cal2.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (cal2.get(Calendar.DAY_OF_MONTH));
                    mmddyyyy += "/"+cal2.get(Calendar.YEAR);
                    if(!mmddyyyy.equals(toDateStr)) {
                        // This should not arise since date input has been validated using javascript.
                        // If this does occur, ignore to date in search criteria and log a WARNING
                        log.warn("To date must be a date in MM/DD/YYYY format, not "+toDateStr+"'. Dates will be ignored.");
                        toDate = null;
                    } else {
                        // get the requested end date - Note: must set time to end of day
                        cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
                        cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
                        cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
                        cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));
                        toDate = cal2.getTime();
                    }
                } catch (ParseException e) {
                    // Should not occur since date input has been validated using javascript.
                    // If this does occur, ignore from and to dates and log a WARNING
                    log.warn("Error parsing input dates.  Dates will be ignored.", e);
                }
                if(fromDate == null || toDate == null) {
                    fromDate = toDate = null;
                }
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, fromDate, toDate, iStartResult, Integer.valueOf(iMaxResult.intValue()-1));
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            }
            renderRequest.setAttribute("ignoreDates", new Boolean(ignoreDates));
View Full Code Here

        Map products = new LinkedHashMap();
        String chosen = renderRequest.getParameter("selectedContainer");
        if(chosen != null) { // Carry on to render the results with the right selection
            renderRequest.setAttribute("selectedContainer", chosen);
        }
        WebAccessLog chosenLog = null;
        if(managers != null) {
            for (int i = 0; i < managers.length; i++) {
                WebManager manager = managers[i];
                AbstractName managerName = PortletManager.getNameFor(renderRequest, manager);
                WebContainer[] containers = (WebContainer[]) manager.getContainers();
                if (containers != null) {
                    for (int j = 0; j < containers.length; j++) {
                        WebContainer container = containers[j];
                        AbstractName containerName = PortletManager.getNameFor(renderRequest, container);
                        String combined = managerName+"%"+containerName;
                        if(containers.length == 1) {
                            products.put(manager.getProductName(), combined);
                        } else {
                            products.put(manager.getProductName()+" ("+containerName.getName().get(NameFactory.J2EE_NAME)+")", combined);
                        }
                        if(chosenLog == null) { // will pick the correct match, or the first if no selection is specified
                            if(chosen == null || chosen.equals(combined)) {
                                chosenLog = PortletManager.getWebAccessLog(renderRequest, managerName, containerName);
                            }
                        }
                    }
                } else {
                    log.error("No web containers found for manager "+manager.getProductName());
                }
            }
        } else {
            log.error("No web managers found!");
        }
        renderRequest.setAttribute("webContainers", products);
        final String[] logNames = chosenLog.getLogNames();
        renderRequest.setAttribute("webLogs", logNames);
        String logToSearch = renderRequest.getParameter("selectedLog");
        if(logToSearch == null) {
            logToSearch = logNames[0];
        } else { //what if the log options for Jetty were showing, but the user picked Tomcat to search?  todo: fix this with some AJAX to repopulate the form when container is changed
            boolean found = false;
            for (int i = 0; i < logNames.length; i++) {
                String test = logNames[i];
                if(test.equals(logToSearch)) {
                    found = true;
                    break;
                }
            }
            if(!found) { // Must has been for the other container -- make it work.
                logToSearch = logNames[0];
            }
        }

        String action = renderRequest.getParameter("action");
        if (criteria == null || (action != null && !"refresh".equals(action))) {
            if(criteria == null)
                criteria = new Criteria();
           
            String fromDate = renderRequest.getParameter("fromDate");
            String toDate = renderRequest.getParameter("toDate");
            String requestHost = renderRequest.getParameter("requestHost");
            String authUser = renderRequest.getParameter("authUser");
            String method = renderRequest.getParameter("requestMethod");
            String uri = renderRequest.getParameter("requestedURI");
            String result = renderRequest.getParameter("startResult");
            Integer max = criteria.maxResult;
            try{
                max = Integer.parseInt(renderRequest.getParameter("maxResult"));
            }catch(NumberFormatException e){
            //ignore
            }
            String ignoreDates = renderRequest.getParameter("ignoreDates");
           
            criteria.fromDate = fromDate == null || fromDate.equals("") ? null : fromDate;
            criteria.toDate = toDate == null || toDate.equals("") ? null : toDate;
            criteria.requestHost = requestHost == null || requestHost.equals("") ? null : requestHost;
            criteria.authUser = authUser == null || authUser.equals("") ? null : authUser;
            criteria.requestMethod = method == null || method.equals("") ? null : method;
            criteria.requestedURI = uri == null || uri.equals("") ? null : uri;
            criteria.startResult = result == null || result.equals("") ? null : result;
            criteria.maxResult = max;
            criteria.ignoreDates = ignoreDates != null && !ignoreDates.equals("")
        }
        String fromDateStr = criteria.fromDate;
        String toDateStr = criteria.toDate;

        Calendar cal1 = Calendar.getInstance(), cal2 = Calendar.getInstance();
        // If not all dates were passed we assume than no fields were passed and just
        // filter on the current date.
        if(fromDateStr == null || toDateStr == null) {
            // just keep the month date and year
            cal1.set(Calendar.MILLISECOND, 0);
            cal1.set(Calendar.MINUTE, 0);
            cal1.set(Calendar.SECOND, 0);
            cal1.set(Calendar.HOUR_OF_DAY, 0);

            cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
            cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
            cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
            cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));

            WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                        null, null, null, null, cal1.getTime(), cal2.getTime(), null, Integer.valueOf(criteria.maxResult.intValue()-1));
            renderRequest.setAttribute("logs", matchingItems.getResults());
            renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            renderRequest.setAttribute("maxResult", criteria.maxResult);
            renderRequest.setAttribute("ignoreDates", Boolean.valueOf(criteria.ignoreDates));
           
        } else {
            // Get other search criteria
            String requestHost = criteria.requestHost;
            String authUser = criteria.authUser;
            String requestMethod = criteria.requestMethod;
            String requestedURI = criteria.requestedURI;
            String startResult = criteria.startResult;
            Integer iStartResult = null;
            Integer iMaxResult = criteria.maxResult;
            try{
                iStartResult = Integer.valueOf(startResult);
            }catch(NumberFormatException e){
                //ignore
            }
           
            boolean ignoreDates = criteria.ignoreDates;
            if (ignoreDates) {
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, null, null, iStartResult, Integer.valueOf(iMaxResult.intValue()-1));
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            } else {
                Date fromDate = null, toDate = null;
                // Check if the from and to date format is MM/DD/YYYY
                DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
                try {
                    fromDate = df.parse(fromDateStr);
                    // get the requested start date (defaults to 00:00:00:000 for time)
                    cal1.setTime(fromDate);
                    String mmddyyyy = (cal1.get(Calendar.MONTH) < 9 ? "0":"") + (cal1.get(Calendar.MONTH)+1);
                    mmddyyyy += "/"+(cal1.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (cal1.get(Calendar.DAY_OF_MONTH));
                    mmddyyyy += "/"+cal1.get(Calendar.YEAR);
                    if(!mmddyyyy.equals(fromDateStr)) {
                        // This should not arise since date input has been validated using javascript.
                        // If this does occur, ignore dates in search criteria and log a WARNING
                        log.warn("From date must be a date in MM/DD/YYYY format, not '"+fromDateStr+"'. Dates will be ignored.");
                        fromDate = null;
                    }
                    toDate = df.parse(toDateStr);
                    cal2.setTime(toDate);
                    mmddyyyy = (cal2.get(Calendar.MONTH) < 9 ? "0":"") + (cal2.get(Calendar.MONTH)+1);
                    mmddyyyy += "/"+(cal2.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (cal2.get(Calendar.DAY_OF_MONTH));
                    mmddyyyy += "/"+cal2.get(Calendar.YEAR);
                    if(!mmddyyyy.equals(toDateStr)) {
                        // This should not arise since date input has been validated using javascript.
                        // If this does occur, ignore to date in search criteria and log a WARNING
                        log.warn("To date must be a date in MM/DD/YYYY format, not "+toDateStr+"'. Dates will be ignored.");
                        toDate = null;
                    } else {
                        // get the requested end date - Note: must set time to end of day
                        cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
                        cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
                        cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
                        cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));
                        toDate = cal2.getTime();
                    }
                } catch (ParseException e) {
                    // Should not occur since date input has been validated using javascript.
                    // If this does occur, ignore from and to dates and log a WARNING
                    log.warn("Error parsing input dates.  Dates will be ignored.", e);
                }
                if(fromDate == null || toDate == null) {
                    fromDate = toDate = null;
                }
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, fromDate, toDate, iStartResult, Integer.valueOf(iMaxResult.intValue()-1));
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            }
            renderRequest.setAttribute("ignoreDates", new Boolean(ignoreDates));
View Full Code Here

        Map products = new LinkedHashMap();
        String chosen = renderRequest.getParameter("selectedContainer");
        if(chosen != null) { // Carry on to render the results with the right selection
            renderRequest.setAttribute("selectedContainer", chosen);
        }
        WebAccessLog chosenLog = null;
        if(managers != null) {
            for (int i = 0; i < managers.length; i++) {
                WebManager manager = managers[i];
                AbstractName managerName = PortletManager.getNameFor(renderRequest, manager);
                WebContainer[] containers = (WebContainer[]) manager.getContainers();
                if (containers != null) {
                    for (int j = 0; j < containers.length; j++) {
                        WebContainer container = containers[j];
                        AbstractName containerName = PortletManager.getNameFor(renderRequest, container);
                        String combined = managerName+"%"+containerName;
                        if(containers.length == 1) {
                            products.put(manager.getProductName(), combined);
                        } else {
                            products.put(manager.getProductName()+" ("+containerName.getName().get(NameFactory.J2EE_NAME)+")", combined);
                        }
                        if(chosenLog == null) { // will pick the correct match, or the first if no selection is specified
                            if(chosen == null || chosen.equals(combined)) {
                                chosenLog = PortletManager.getWebAccessLog(renderRequest, managerName, containerName);
                            }
                        }
                    }
                } else {
                    log.error("No web containers found for manager "+manager.getProductName());
                }
            }
        } else {
            log.error("No web managers found!");
        }
        renderRequest.setAttribute("webContainers", products);
        final String[] logNames = chosenLog.getLogNames();
        renderRequest.setAttribute("webLogs", logNames);
        String logToSearch = renderRequest.getParameter("selectedLog");
        if(logToSearch == null) {
            logToSearch = logNames[0];
        } else { //what if the log options for Jetty were showing, but the user picked Tomcat to search?  todo: fix this with some AJAX to repopulate the form when container is changed
            boolean found = false;
            for (int i = 0; i < logNames.length; i++) {
                String test = logNames[i];
                if(test.equals(logToSearch)) {
                    found = true;
                    break;
                }
            }
            if(!found) { // Must has been for the other container -- make it work.
                logToSearch = logNames[0];
            }
        }

        String action = renderRequest.getParameter("action");
        if ("refresh".equals(action)) {
            //todo: currently refreshes on every request; that's pretty slow.
        }


        //todo: completely revamp this argument processing
        String startDate = (String) renderRequest.getParameter("startDate");
        String startMonth = (String) renderRequest.getParameter("startMonth");
        String startYear = (String) renderRequest.getParameter("startYear");
        String endDate = (String) renderRequest.getParameter("endDate");
        String endMonth = (String) renderRequest.getParameter("endMonth");
        String endYear = (String) renderRequest.getParameter("endYear");

        Calendar cal1 = Calendar.getInstance(), cal2 = Calendar.getInstance();
        // If not all dates were passed we assume than no fields were passed and just
        // filter on the current date.
        if (startDate == null || startMonth == null || startYear == null
                || endDate == null || endMonth == null || endYear == null) {
            // just keep the month date and year
            cal1.set(Calendar.MILLISECOND, 0);
            cal1.set(Calendar.MINUTE, 0);
            cal1.set(Calendar.SECOND, 0);
            cal1.set(Calendar.HOUR_OF_DAY, 0);

            cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
            cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
            cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
            cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));

            WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                        null, null, null, null, cal1.getTime(), cal2.getTime(), null, null);
            renderRequest.setAttribute("logs", matchingItems.getResults());
            renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
        } else {
            cal1.clear();
            cal2.clear();
            // get the requested start date (defaults to 00:00:00:000 for time
            cal1.set(Calendar.DATE, Integer.parseInt(startDate));
            cal1.set(Calendar.MONTH, Integer.parseInt(startMonth));
            cal1.set(Calendar.YEAR, Integer.parseInt(startYear));
            // get the requested end date - Note: must set time to end of day
            cal2.set(Calendar.DATE, Integer.parseInt(endDate));
            cal2.set(Calendar.MONTH, Integer.parseInt(endMonth));
            cal2.set(Calendar.YEAR, Integer.parseInt(endYear));
            cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
            cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
            cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
            cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));
            // Get other search criteria
            String requestHost = (String) renderRequest.getParameter("requestHost");
            String authUser = (String) renderRequest.getParameter("authUser");
            String requestMethod = (String) renderRequest.getParameter("requestMethod");
            String requestedURI = (String) renderRequest.getParameter("requestedURI");
            boolean ignoreDates = renderRequest.getParameter("ignoreDates") != null;
            if (ignoreDates) {
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, null, null, null, null);
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            } else {
                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
                                                requestHost, authUser, requestMethod, requestedURI, cal1.getTime(), cal2.getTime(), null, null);
                renderRequest.setAttribute("logs", matchingItems.getResults());
                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
            }
            if (ignoreDates) renderRequest.setAttribute("ignoreDates", new Boolean(ignoreDates));
View Full Code Here

TOP

Related Classes of org.apache.geronimo.management.geronimo.WebAccessLog$LogMessage

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.