Skip to content

Commit

Permalink
Fix IllegalStateException in IconServlet (openhab#2577)
Browse files Browse the repository at this point in the history
Fixes openhab#2529

Signed-off-by: Wouter Born <github@maindrain.net>
GitOrigin-RevId: 8c1fe60
  • Loading branch information
wborn authored and splatch committed Jul 12, 2023
1 parent ef17b3e commit 71c0040
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@

import java.io.IOException;
import java.io.InputStream;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

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

Expand Down Expand Up @@ -143,20 +142,16 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
return;
}

if (Format.SVG.equals(format)) {
resp.setContentType("image/svg+xml");
} else {
resp.setContentType("image/png");
}
resp.setDateHeader("Last-Modified", new Date().getTime());
ServletOutputStream os = resp.getOutputStream();
try (InputStream is = provider.getIcon(category, iconSetId, state, format)) {
if (is == null) {
logger.debug("Requested icon category {} provided by no icon provider", category);
resp.sendError(404);
return;
}
is.transferTo(os);

resp.setContentType(Format.SVG.equals(format) ? "image/svg+xml" : "image/png");
resp.setDateHeader("Last-Modified", Instant.now().toEpochMilli());
is.transferTo(resp.getOutputStream());
resp.flushBuffer();
} catch (IOException e) {
logger.error("Failed sending the icon byte stream as a response: {}", e.getMessage());
Expand Down

0 comments on commit 71c0040

Please sign in to comment.