Source:
<code>private void proxyWmsRequest(HttpServletRequest request, HttpServletResponse response, String layerParameter) throws ServletException, IOException { LayerDescriptor layerDescriptor = new LayerDescriptor(request.getParameter(layerParameter)); String time = request.getParameter("TIME"); String wmsUrlStr = getWmsUrl(layerDescriptor, time); try { @SuppressWarnings("unchecked") Map<String, String[]> wmsParameters = new HashMap<String, String[]>(request.getParameterMap()); if (isCollectionWithTimeMismatch(layerDescriptor.geoserverName())) { wmsParameters.remove("TIME"); } wmsParameters.put("VERSION", new String[] { wmsVersion }); wmsParameters.put(layerParameter, new String[] { layerDescriptor.getNetCDFVariableName() }); if (wmsParameters.containsKey("QUERY_LAYERS")) { wmsParameters.put("QUERY_LAYERS", new String[]{layerDescriptor.getNetCDFVariableName() }); } String queryString = encodeMapForRequest(wmsParameters); URL wmsUrl = new URL(wmsUrlStr + "?" + queryString); HttpURLConnection connection = (HttpURLConnection)wmsUrl.openConnection(); <START> if (connection.getResponseCode() != 200 ) { <END> String ret = String.format("ERROR proxying URL '%s' - %s", wmsUrl, connection.getResponseMessage()); response.sendError(connection.getResponseCode(), ret); LOGGER.log(Level.SEVERE, ret); } else { response.setStatus(connection.getResponseCode()); response.setContentType(connection.getContentType()); response.setContentLength(connection.getContentLength()); IOUtils.copy(connection.getInputStream(), response.getOutputStream()); } } catch (Exception e) { String ret = String.format("Problem while proxying URL '%s' - %s", wmsUrlStr, e.getMessage()); response.sendError(500, e.getMessage()); LOGGER.log(Level.SEVERE, ret); e.printStackTrace(); } }</code><technical_language>good @pmbohm. wondering if is issue connection closed, if code throws exception</technical_language>

Target:
private void proxyWmsRequest(HttpServletRequest request, HttpServletResponse response, String layerParameter) throws ServletException, IOException { LayerDescriptor layerDescriptor = new LayerDescriptor(request.getParameter(layerParameter)); String time = request.getParameter("TIME"); String wmsUrlStr = getWmsUrl(layerDescriptor, time); try { @SuppressWarnings("unchecked") Map<String, String[]> wmsParameters = new HashMap<String, String[]>(request.getParameterMap()); if (isCollectionWithTimeMismatch(layerDescriptor.geoserverName())) { wmsParameters.remove("TIME"); } wmsParameters.put("VERSION", new String[] { wmsVersion }); wmsParameters.put(layerParameter, new String[] { layerDescriptor.getNetCDFVariableName() }); if (wmsParameters.containsKey("QUERY_LAYERS")) { wmsParameters.put("QUERY_LAYERS", new String[]{layerDescriptor.getNetCDFVariableName() }); } String queryString = encodeMapForRequest(wmsParameters); URL wmsUrl = new URL(wmsUrlStr + "?" + queryString); HttpURLConnection connection = (HttpURLConnection)wmsUrl.openConnection(); if (connection.getResponseCode() != 200 ) { String ret = String.format("ERROR proxying URL '%s' - %s", wmsUrl, connection.getResponseMessage()); response.sendError(connection.getResponseCode(), ret); LOGGER.log(Level.SEVERE, ret); } else { response.setStatus(connection.getResponseCode()); response.setContentType(connection.getContentType()); response.setContentLength(connection.getContentLength()); try (InputStream is = connection.getInputStream()) { IOUtils.copy(is, response.getOutputStream()); } } } catch (Exception e) { String ret = String.format("Problem while proxying URL '%s' - %s", wmsUrlStr, e.getMessage()); response.sendError(500, e.getMessage()); LOGGER.log(Level.SEVERE, ret); e.printStackTrace(); } }