package uk.me.steev.java.heating.io.http.get;

import java.io.IOException;
import java.util.Map;

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

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import uk.me.steev.java.heating.controller.Heating;
import uk.me.steev.java.heating.io.temperature.BluetoothTemperatureSensor;

public class CurrentTempServlet extends GetServlet {
  private static final long serialVersionUID = -2479268631077208608L;
  static final Logger logger = LogManager.getLogger(CurrentTempServlet.class.getName());
  
  public CurrentTempServlet(Heating heating) {
    super(heating);
  }
  
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setStatus(HttpServletResponse.SC_NOT_FOUND);

    String pathInfo = request.getPathInfo().replaceFirst("/", "").toUpperCase();
    Map<String, BluetoothTemperatureSensor> sensors = heating.getSensors();
    if (sensors.containsKey(pathInfo)) {
      Float temperature = sensors.get(pathInfo).getCurrentTemperature();
      response.setContentType("text/plain");
      response.setStatus(HttpServletResponse.SC_OK);
      response.getWriter().println(temperature);
      logger.debug("Request for " + pathInfo + ", sent " + temperature);
    }
  }
}

@@ -1407,15 +1407,445 @@
 );%0A    %7D
+%0A%0A    for (BluetoothTemperatureSensor sensor : sensors.values()) %7B%0A      if (sensor.getName().equals(pathInfo)) %7B%0A        Float temperature = sensor.getCurrentTemperature();%0A        response.setContentType(%22text/plain%22);%0A        response.setStatus(HttpServletResponse.SC_OK);%0A        response.getWriter().println(temperature);%0A        logger.debug(%22Request for %22 + pathInfo + %22, sent %22 + temperature);%0A        break;%0A      %7D%0A    %7D
 %0A  %7D%0A%7D%0A

Support getting temperatures by name