    public void execute(Request req) throws ServiceException {
        GetMapRequest request = (GetMapRequest) req;
        final String outputFormat = request.getFormat();
        this.delegate = getDelegate(outputFormat, wms);
		final MapLayerInfo[] layers = request.getLayers();
		final Style[] styles = (Style[]) request.getStyles().toArray(
				new Style[] {});
		final Filter[] filters = (request.getFilters() != null ? (Filter[]) request.getFilters().toArray(
				new Filter[] {}) : null); 
        map = new WMSMapContext(request);
		final Envelope env = request.getBbox();
		if (env.isNull() || (env.getWidth() <= 0) || (env.getHeight() <= 0)) {
			throw new WmsException(new StringBuffer(
					"The request bounding box has zero area: ").append(env)
					.toString());
		}
		final CoordinateReferenceSystem mapcrs = request.getCrs();
		if (mapcrs != null)
			map.setAreaOfInterest(env, mapcrs);
		else
			map.setAreaOfInterest(env, DefaultGeographicCRS.WGS84);
		map.setMapWidth(request.getWidth());
		map.setMapHeight(request.getHeight());
		map.setBgColor(request.getBgColor());
		map.setTransparent(request.isTransparent());
		if (request.getWidth() <= 0 || request.getHeight() <= 0
				|| map.getAreaOfInterest().getLength(0) <= 0
				|| map.getAreaOfInterest().getLength(1) <= 0) {
			if (LOGGER.isLoggable(Level.FINE))
				LOGGER
						.fine("We are not going to render anything because either the are is null ar the dimensions are not positive.");
			return;
		}
		if (LOGGER.isLoggable(Level.FINE)) {
			LOGGER.fine("setting up map");
		}
		try { 
			MapLayer layer;
			boolean cachingPossible = request.getHttpServletRequest()
					.getMethod().equals("GET");
			int maxAge = Integer.MAX_VALUE;
			FeatureSource source;
			AbstractGridCoverage2DReader reader;
			Style style;
			Filter definitionFilter, optionalFilter;
			Query definitionQuery;
			int nma;
			final int length = layers.length;
			for (int i = 0; i < length; i++) {
				style = styles[i];
				try {
					optionalFilter = filters[i];
				} catch (Exception e) {
					optionalFilter = null;
				}
				if (layers[i].getType() == MapLayerInfo.TYPE_VECTOR) {
					if (cachingPossible) {
						if (layers[i].getFeature().isCachingEnabled()) {
							nma = Integer.parseInt(layers[i].getFeature()
									.getCacheMaxAge());
							if (nma < maxAge)
								maxAge = nma;
						} else {
							cachingPossible = false;
						}
					}
					try {
						source = layers[i].getFeature().getFeatureSource();
						if (layers[i].getBoundingBox() instanceof ReferencedEnvelope) {
							final ReferencedEnvelope bbox = (ReferencedEnvelope) layers[i].getBoundingBox();
							if(CRS.equalsIgnoreMetadata(bbox.getCoordinateReferenceSystem(), mapcrs)) {
								if (!layers[i].getBoundingBox().intersects(env)) {
									continue;
								}
							} else {
								ReferencedEnvelope prjEnv = new ReferencedEnvelope(env, mapcrs).transform(bbox.getCoordinateReferenceSystem(), true);
								if (!layers[i].getBoundingBox().intersects(prjEnv)) {
									continue;
								}
							}						
						}
					} catch (IOException exp) {
						if (LOGGER.isLoggable(Level.SEVERE)) {
							LOGGER.log(Level.SEVERE, new StringBuffer(
									"Getting feature source: ").append(
									exp.getMessage()).toString(), exp);
						}
						throw new WmsException(null, new StringBuffer(
								"Internal error : ").append(exp.getMessage())
								.toString());
					} catch (FactoryException exp) {
						if (LOGGER.isLoggable(Level.SEVERE)) {
							LOGGER.log(Level.SEVERE, new StringBuffer(
									"Getting feature source: ").append(
									exp.getMessage()).toString(), exp);
						}
						throw new WmsException(null, new StringBuffer(
								"Internal error : ").append(exp.getMessage())
								.toString());
					}
					layer = new DefaultMapLayer(source, style);
					layer.setTitle(layers[i].getName());
					definitionFilter = layers[i].getFeature().getDefinitionQuery();
					if (definitionFilter != null) {
						definitionQuery = new DefaultQuery(source.getSchema()
								.getTypeName(), definitionFilter);
						layer.setQuery(definitionQuery);
					} else if (optionalFilter != null) {
						definitionQuery = new DefaultQuery(source.getSchema().getTypeName(), optionalFilter);
						layer.setQuery(definitionQuery);
					}
					map.addLayer(layer);
				} else if (layers[i].getType() == MapLayerInfo.TYPE_RASTER) {
					reader = (AbstractGridCoverage2DReader) layers[i]
							.getCoverage().getReader();
					if (reader != null) {
						final ParameterValueGroup params = reader.getFormat().getReadParameters();
						layer = new DefaultMapLayer(DataUtilities.wrapGcReader(reader, CoverageUtils.getParameters(params, layers[i].getCoverage().getParameters())), style); 
						layer.setTitle(layers[i].getName());
						layer.setQuery(Query.ALL);
						map.addLayer(layer);
					} else
						throw new WmsException(
								null,
								new StringBuffer(
										"Internal error : unable to get reader for this coverage layer ")
										.append(layers[i].toString())
										.toString());
				}
			}
			this.delegate.produceMap(map);
			if (cachingPossible)
				responseHeaders.put("Cache-Control: max-age", maxAge + "s");
			String contentDisposition = this.delegate.getContentDisposition();
	        if (contentDisposition != null) {
	        	this.headerContentDisposition = contentDisposition;
	        }
		} catch (ClassCastException e) {
			if (LOGGER.isLoggable(Level.WARNING)) {
				LOGGER.log(Level.SEVERE, new StringBuffer(
						"Getting feature source: ").append(e.getMessage())
						.toString(), e);
			}
			throw new WmsException(e, new StringBuffer("Internal error : ")
					.append(e.getMessage()).toString(), "");
		} catch (TransformException e) {
			throw new WmsException(e, new StringBuffer("Internal error : ")
					.append(e.getMessage()).toString(), "");
		} catch (FactoryConfigurationError e) {
			throw new WmsException(e, new StringBuffer("Internal error : ")
					.append(e.getMessage()).toString(), "");
		} catch (SchemaException e) {
			throw new WmsException(e, new StringBuffer("Internal error : ")
					.append(e.getMessage()).toString(), "");
		} catch (IllegalAttributeException e) {
			throw new WmsException(e, new StringBuffer("Internal error : ")
					.append(e.getMessage()).toString(), "");
		} finally {
			try {
			} catch (Exception e) 
			{
				if (LOGGER.isLoggable(Level.SEVERE)) {
					LOGGER.log(Level.SEVERE, new StringBuffer(
							"Getting feature source: ").append(e.getMessage())
							.toString(), e);
				}
			}
		}
	}

    public void execute(Request req) throws ServiceException {
        GetMapRequest request = (GetMapRequest) req;
        final String outputFormat = request.getFormat();
        this.delegate = getDelegate(outputFormat, wms);
		final MapLayerInfo[] layers = request.getLayers();
		final Style[] styles = (Style[]) request.getStyles().toArray(
				new Style[] {});
		final Filter[] filters = (request.getFilters() != null ? (Filter[]) request.getFilters().toArray(
				new Filter[] {}) : null); 
        map = new WMSMapContext(request);
		final Envelope env = request.getBbox();
		if (env.isNull() || (env.getWidth() <= 0) || (env.getHeight() <= 0)) {
			throw new WmsException(new StringBuffer(
					"The request bounding box has zero area: ").append(env)
					.toString());
		}
		final CoordinateReferenceSystem mapcrs = request.getCrs();
		if (mapcrs != null)
			map.setAreaOfInterest(env, mapcrs);
		else
			map.setAreaOfInterest(env, DefaultGeographicCRS.WGS84);
		map.setMapWidth(request.getWidth());
		map.setMapHeight(request.getHeight());
		map.setBgColor(request.getBgColor());
		map.setTransparent(request.isTransparent());
		if (request.getWidth() <= 0 || request.getHeight() <= 0
				|| map.getAreaOfInterest().getLength(0) <= 0
				|| map.getAreaOfInterest().getLength(1) <= 0) {
			if (LOGGER.isLoggable(Level.FINE))
				LOGGER
						.fine("We are not going to render anything because either the are is null ar the dimensions are not positive.");
			return;
		}
		if (LOGGER.isLoggable(Level.FINE)) {
			LOGGER.fine("setting up map");
		}
		try { 
			MapLayer layer;
			boolean cachingPossible = request.getHttpServletRequest()
					.getMethod().equals("GET");
			int maxAge = Integer.MAX_VALUE;
			FeatureSource source;
			AbstractGridCoverage2DReader reader;
			Style style;
			Filter definitionFilter, optionalFilter;
			Query definitionQuery;
			int nma;
			final int length = layers.length;
			for (int i = 0; i < length; i++) {
				style = styles[i];
				try {
					optionalFilter = filters[i];
				} catch (Exception e) {
					optionalFilter = null;
				}
				if (layers[i].getType() == MapLayerInfo.TYPE_VECTOR) {
					if (cachingPossible) {
						if (layers[i].getFeature().isCachingEnabled()) {
							nma = Integer.parseInt(layers[i].getFeature()
									.getCacheMaxAge());
							if (nma < maxAge)
								maxAge = nma;
						} else {
							cachingPossible = false;
						}
					}
					try {
						source = layers[i].getFeature().getFeatureSource();
					} catch (IOException exp) {
						if (LOGGER.isLoggable(Level.SEVERE)) {
							LOGGER.log(Level.SEVERE, new StringBuffer(
									"Getting feature source: ").append(
									exp.getMessage()).toString(), exp);
						}
						throw new WmsException(null, new StringBuffer(
								"Internal error : ").append(exp.getMessage())
								.toString());
                    }
					layer = new DefaultMapLayer(source, style);
					layer.setTitle(layers[i].getName());
					definitionFilter = layers[i].getFeature().getDefinitionQuery();
					if (definitionFilter != null) {
						definitionQuery = new DefaultQuery(source.getSchema()
								.getTypeName(), definitionFilter);
						layer.setQuery(definitionQuery);
					} else if (optionalFilter != null) {
						definitionQuery = new DefaultQuery(source.getSchema().getTypeName(), optionalFilter);
						layer.setQuery(definitionQuery);
					}
					map.addLayer(layer);
				} else if (layers[i].getType() == MapLayerInfo.TYPE_RASTER) {
					reader = (AbstractGridCoverage2DReader) layers[i]
							.getCoverage().getReader();
					if (reader != null) {
						final ParameterValueGroup params = reader.getFormat().getReadParameters();
						layer = new DefaultMapLayer(DataUtilities.wrapGcReader(reader, CoverageUtils.getParameters(params, layers[i].getCoverage().getParameters())), style); 
						layer.setTitle(layers[i].getName());
						layer.setQuery(Query.ALL);
						map.addLayer(layer);
					} else
						throw new WmsException(
								null,
								new StringBuffer(
										"Internal error : unable to get reader for this coverage layer ")
										.append(layers[i].toString())
										.toString());
				}
			}
			this.delegate.produceMap(map);
			if (cachingPossible)
				responseHeaders.put("Cache-Control: max-age", maxAge + "s");
			String contentDisposition = this.delegate.getContentDisposition();
	        if (contentDisposition != null) {
	        	this.headerContentDisposition = contentDisposition;
	        }
		} catch (ClassCastException e) {
			if (LOGGER.isLoggable(Level.WARNING)) {
				LOGGER.log(Level.SEVERE, new StringBuffer(
						"Getting feature source: ").append(e.getMessage())
						.toString(), e);
			}
			throw new WmsException(e, new StringBuffer("Internal error : ")
					.append(e.getMessage()).toString(), "");
		} catch (TransformException e) {
			throw new WmsException(e, new StringBuffer("Internal error : ")
					.append(e.getMessage()).toString(), "");
		} catch (FactoryConfigurationError e) {
			throw new WmsException(e, new StringBuffer("Internal error : ")
					.append(e.getMessage()).toString(), "");
		} catch (SchemaException e) {
			throw new WmsException(e, new StringBuffer("Internal error : ")
					.append(e.getMessage()).toString(), "");
		} catch (IllegalAttributeException e) {
			throw new WmsException(e, new StringBuffer("Internal error : ")
					.append(e.getMessage()).toString(), "");
		} finally {
			try {
			} catch (Exception e) 
			{
				if (LOGGER.isLoggable(Level.SEVERE)) {
					LOGGER.log(Level.SEVERE, new StringBuffer(
							"Getting feature source: ").append(e.getMessage())
							.toString(), e);
				}
			}
		}
	}
