package org.cloudfoundry.services; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletResponse; import javax.sql.DataSource; import com.mongodb.Mongo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; import org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; /** * Handles requests for the application home page. */ @Controller public class HomeController { @Autowired(required = false) DataSource dataSource; @Autowired(required = false) RedisConnectionFactory redisConnectionFactory; @Autowired(required = false) Mongo mongo; /** * Simply selects the home view to render by returning its name. */ @RequestMapping(value = "/", method = RequestMethod.GET) public String home(Model model) { List<String> services = new ArrayList<String>(); if (redisConnectionFactory != null) { services.add("Redis: " + ((JedisConnectionFactory) redisConnectionFactory).getHostName() + ":" + ((JedisConnectionFactory) redisConnectionFactory).getPort()); } if (mongo != null) { services.add("Mongo: " + mongo.getAddress()); } model.addAttribute("services", services); String environmentName = (System.getenv("VCAP_APPLICATION") != null) ? "Cloud" : "Local"; model.addAttribute("environmentName", environmentName); return "home"; } @RequestMapping("/env") public void env(HttpServletResponse response) throws IOException { response.setContentType("text/plain"); PrintWriter out = response.getWriter(); out.println("System Properties:"); for (Map.Entry<Object, Object> property : System.getProperties().entrySet()) { out.println(property.getKey() + ": " + property.getValue()); } out.println(); out.println("System Environment:"); for (Map.Entry<String, String> envvar : System.getenv().entrySet()) { out.println(envvar.getKey() + ": " + envvar.getValue()); } } }