Commit d2f9c208 authored by n-lagomarsini's avatar n-lagomarsini
Browse files

[GEOS-6979] GWC caching with CQL_FILTER returns no parameter filter exists for FILTER

parent 54d73d78
......@@ -835,7 +835,8 @@ public class GWC implements DisposableBean, InitializingBean, ApplicationContext
if (null != request.getFilter() && !request.getFilter().isEmpty()) {
if (!filterApplies(filters, request, "FILTER", requestMistmatchTarget)) {
boolean sameFilters = checkFilter(request.getFilter(), request.getCQLFilter(), filters);
if (!sameFilters && !filterApplies(filters, request, "FILTER", requestMistmatchTarget)) {
return false;
......@@ -887,6 +888,41 @@ public class GWC implements DisposableBean, InitializingBean, ApplicationContext
return true;
* Method for checking if CQL_FILTER list and FILTER lists are equals
* @param filter
* @param cqlFilter
* @param filters
* @return
private boolean checkFilter(List filter, List cqlFilter, Map<String, ParameterFilter> filters) {
// Check if the two filters are equals and the FILTER parameter is not a ParameterFilter
// Check is done only if the FILTER parameter is not present
if (!filters.containsKey("FILTER")) {
// Check if the filter List and cqlFilter lists are not null and not empty
boolean hasFilter = filter != null && !filter.isEmpty();
boolean hasCQLFilter = cqlFilter != null && !cqlFilter.isEmpty();
// If the filters are present, check if they are equals.
// In this case the Filter List has been taken from the CQL_FILTER list
if (hasCQLFilter && hasFilter) {
// First check on the size
int size = filter.size();
if (size == cqlFilter.size()) {
// Check same elements
boolean equals = true;
// Loop on the elements
for (int i = 0; i < size; i++) {
equals &= filter.get(i).equals(cqlFilter.get(i));
return equals;
// By default return false
return false;
private boolean filterApplies(Map<String, ParameterFilter> filters, GetMapRequest request,
String key, StringBuilder requestMistmatchTarget) {
......@@ -19,6 +19,7 @@ import static org.mockito.Mockito.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
......@@ -40,8 +41,14 @@ import org.geoserver.gwc.layer.GeoServerTileLayerInfo;
import org.geoserver.gwc.layer.TileLayerInfoUtil;
import org.geoserver.ows.Dispatcher;
import org.geoserver.ows.util.CaseInsensitiveMap;
import org.geoserver.platform.GeoServerExtensions;
import org.geoserver.wms.GetMapRequest;
import org.geoserver.wms.WMS;
import org.geoserver.wms.kvp.PaletteManager;
import org.geotools.filter.identity.FeatureIdImpl;
import org.geotools.filter.text.cql2.CQL;
import org.geotools.geometry.jts.ReferencedEnvelope;
......@@ -60,6 +67,7 @@ import org.geowebcache.grid.GridSet;
import org.geowebcache.grid.GridSetBroker;
import org.geowebcache.grid.GridSubset;
import org.geowebcache.grid.SRS;
import org.geowebcache.layer.TileLayer;
import org.geowebcache.layer.TileLayerDispatcher;
import org.geowebcache.mime.MimeType;
......@@ -75,6 +83,7 @@ import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.opengis.filter.Filter;
......@@ -919,6 +928,49 @@ public class GWCTest {
assertEquals(0, target.length());
* Since GeoServer sets a new FILTER parameter equal to an input CQL_FILTER parameter (if present) for each WMS requests (using direct WMS
* integration), this may result in a caching error. This test ensures that no error is thrown and caching is allowed.
public void testCQLFILTERParameters() throws Exception {
// Define a CQL_FILTER
TileLayerInfoUtil.updateAcceptAllRegExParameterFilter(tileLayerInfo, "CQL_FILTER", true);
tileLayer = new GeoServerTileLayer(layer, gridSetBroker, tileLayerInfo);
// Create the new GetMapRequest
GetMapRequest request = new GetMapRequest();
Map<String, String> rawKvp = new CaseInsensitiveMap(new HashMap<String, String>());
rawKvp.put("CQL_FILTER", "include");
StringBuilder target = new StringBuilder();
// Setting CQL FILTER
List<Filter> cqlFilters = Arrays.asList(CQL.toFilter("include"));
// Checking if caching is possible
assertTrue(mediator.isCachingPossible(tileLayer, request, target));
// Ensure No error is logged
assertEquals(0, target.length());
// Setting FILTER parameter equal to CQL FILTER (GeoServer does it internally)
// Checking if caching is possible
assertTrue(mediator.isCachingPossible(tileLayer, request, target));
// Ensure No error is logged
assertEquals(0, target.length());
// Ensure that if another filter is set an error is thrown
List filters = new ArrayList(cqlFilters);
// Ensuring caching is not possible
assertFalse(mediator.isCachingPossible(tileLayer, request, target));
// Ensure No error is logged
assertFalse(0 == target.length());
private void assertDispatchMismatch(GetMapRequest request, String expectedReason) {
StringBuilder target = new StringBuilder();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment