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;
      }
    }
}

@@ -710,16 +710,17 @@
 ing url)
+ 
 %7B%0A      
@@ -724,16 +724,17 @@
      try
+ 
 %7B%0A      
@@ -781,16 +781,17 @@
        %7D
+ 
 catch(Ex
@@ -800,16 +800,17 @@
 ption e)
+ 
 %7B%0A      
@@ -1325,19 +1325,24 @@
 uest) %7B%0A
-%0A%09%09
+        
 if(log.i
@@ -1360,18 +1360,26 @@
 ed()) %7B%0A
-%09%09
+          
   String
@@ -1420,11 +1420,20 @@
 ();%0A
-%09%09%09
+            
 log.
@@ -1481,14 +1481,23 @@
 s);%0A
-%09%09%7D%0A%0A%09
+        %7D%0A%0A    
     
@@ -1564,30 +1564,36 @@
 al%22);%0A      
+ 
+ 
 try %7B%0A
+    
         retu
@@ -1670,24 +1670,26 @@
 alse;%0A      
+  
 %7D catch (Exc
@@ -1692,32 +1692,36 @@
 (Exception e) %7B%0A
+    
         log.erro
@@ -1730,24 +1730,28 @@
 e);%0A        
+    
 return false
@@ -1748,24 +1748,26 @@
 turn false;%0A
+  
       %7D%0A    

Fix whitespace