String layerId = parseLayerId(request);
WmsLayer layer = getLayer(layerId);
if (layer == null) {
throw new LayerException(ExceptionCode.LAYER_NOT_FOUND, layerId);
}
RasterLayerInfo layerInfo = layer.getLayerInfo();
String url = layer.getBaseWmsUrl() + "?" + request.getQueryString();
InputStream stream = null;
try {
response.setContentType(layer.getFormat());
stream = httpService.getStream(url, layer.getAuthentication());
ServletOutputStream out = response.getOutputStream();
int b;
while ((b = stream.read()) >= 0 ) {
out.write(b);
}
} catch (Exception e) {
log.error("Cannot get original WMS image", e);
// Create an error image to make the reason for the error visible:
byte[] b = createErrorImage(layerInfo.getTileWidth(), layerInfo.getTileHeight(), e);
response.setContentType("image/png");
response.getOutputStream().write(b);
} finally {
if (null != stream) {
try {