package edu.oakland.uPortalTesterWebapp.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

@Controller
public class Application {

    private static final Log log = LogFactory.getLog(Application.class);

    private Document getDocument(String url) {
        try {
            return Jsoup.connect(url).get();
        } catch(Exception e) {
            log.error("Exception: getDocument: ", e);
            log.error("Returning new Document to fail gracefully.");
            return new Document("");
        }
    }

    @RequestMapping(value="/", method=RequestMethod.GET)
    public ModelAndView home(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView home = new ModelAndView("home");
        home.addObject("running", getRunning(request));
        return home;
    }

    private boolean getRunning(HttpServletRequest request) {
        if(log.isDebugEnabled()) {
            String ipAddress = request.getRemoteAddr();
            log.debug("Request generated by: " + ipAddress);
        }

        Document document = getDocument("http://localhost:8080/uPortal");
        try {
            return (document.getElementById("portal").html() ).length() > 0 ? true : false;
        } catch (Exception e) {
            log.error(e);
            return false;
        }
    }
}

@@ -891,18 +891,19 @@
 urning n
-ew
+ull
  Documen
@@ -951,23 +951,11 @@
 rn n
-ew Document(%22%22)
+ull
 ;%0A  
@@ -1555,34 +1555,84 @@
 %22);%0A        
-try %7B%0A    
+if(document == null) %7B%0A            return false;%0A        %7D%0A%0A
         retu
@@ -1694,118 +1694,9 @@
  %3E 0
- ? true : false;%0A        %7D catch (Exception e) %7B%0A            log.error(e);%0A            return false;%0A        %7D
+;
 %0A   

Remove redundant Document object