| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.student.common.ui.server.gwt; | 
  | 17 |  |   | 
  | 18 |  |  import java.io.IOException; | 
  | 19 |  |  import java.util.HashMap; | 
  | 20 |  |  import java.util.LinkedHashMap; | 
  | 21 |  |  import java.util.List; | 
  | 22 |  |  import java.util.Map; | 
  | 23 |  |   | 
  | 24 |  |  import javax.servlet.ServletConfig; | 
  | 25 |  |  import javax.servlet.ServletException; | 
  | 26 |  |   | 
  | 27 |  |  import org.apache.log4j.Logger; | 
  | 28 |  |  import org.kuali.rice.core.config.ConfigContext; | 
  | 29 |  |  import org.kuali.student.common.ui.client.service.ServerPropertiesRpcService; | 
  | 30 |  |  import org.kuali.student.common.util.ManifestInspector; | 
  | 31 |  |   | 
  | 32 |  |  import com.google.gwt.user.server.rpc.RemoteServiceServlet; | 
  | 33 |  |   | 
  | 34 |  |  @SuppressWarnings("serial") | 
  | 35 | 0 |  public class ServerPropertiesRpcGwtServlet extends RemoteServiceServlet implements ServerPropertiesRpcService { | 
  | 36 |  |   | 
  | 37 | 0 |          final Logger logger = Logger.getLogger(ServerPropertiesRpcGwtServlet.class); | 
  | 38 |  |   | 
  | 39 | 0 |          Map<String, String> properties = new HashMap<String, String>(); | 
  | 40 |  |   | 
  | 41 |  |          public Map<String, String> getProperties() { | 
  | 42 | 0 |                  return properties; | 
  | 43 |  |          } | 
  | 44 |  |   | 
  | 45 |  |          public void setProperties(Map<String, String> properties) { | 
  | 46 | 0 |                  this.properties = properties; | 
  | 47 | 0 |          } | 
  | 48 |  |   | 
  | 49 |  |          @Override | 
  | 50 |  |          public String get(String property) { | 
  | 51 | 0 |                  String value = properties.get(property); | 
  | 52 | 0 |                  logger.info("Getting property: " + property + " with value: " + value); | 
  | 53 | 0 |                  if (null == value) { | 
  | 54 | 0 |                          value = ConfigContext.getCurrentContextConfig().getProperty(property); | 
  | 55 | 0 |                          logger.info("Property not found, looking in Context: " + property + " with value: " + value); | 
  | 56 |  |                  } | 
  | 57 | 0 |                  return value; | 
  | 58 |  |          } | 
  | 59 |  |   | 
  | 60 |  |          @Override | 
  | 61 |  |          public Map<String, String> get(List<String> properties) { | 
  | 62 | 0 |                  Map<String, String> map = new LinkedHashMap<String, String>(); | 
  | 63 | 0 |                  for (String property : properties) { | 
  | 64 | 0 |                          map.put(property, get(property)); | 
  | 65 |  |                  } | 
  | 66 | 0 |                  return map; | 
  | 67 |  |          } | 
  | 68 |  |   | 
  | 69 |  |          @Override | 
  | 70 |  |          public String getContextPath(){ | 
  | 71 | 0 |                  String contextPath = this.getThreadLocalRequest().getContextPath(); | 
  | 72 | 0 |                  logger.info("Returning servlet path of [" + contextPath + "]");                 | 
  | 73 | 0 |                  return contextPath; | 
  | 74 |  |          } | 
  | 75 |  |   | 
  | 76 |  |          @Override | 
  | 77 |  |          public void init(ServletConfig config) throws ServletException { | 
  | 78 | 0 |                  super.init(config); | 
  | 79 |  |                  try { | 
  | 80 | 0 |                          logger.info("Obtaining build information from " + ManifestInspector.MANIFEST_LOCATION); | 
  | 81 | 0 |                          ManifestInspector inspector = new ManifestInspector(); | 
  | 82 | 0 |                          String buildInfo = inspector.getBuildInformationString(getServletConfig().getServletContext()); | 
  | 83 | 0 |                          logger.info("Build information: " + buildInfo); | 
  | 84 | 0 |                          properties.put("ks.application.version", buildInfo); | 
  | 85 | 0 |                  } catch (IOException e) { | 
  | 86 | 0 |                          throw new ServletException(e); | 
  | 87 | 0 |                  } | 
  | 88 | 0 |          } | 
  | 89 |  |  } |