-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from opengeospatial/issue#cite-internal364
Limit requested features to prevent too large responses
- Loading branch information
Showing
5 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/org/opengis/cite/ogcapifeatures10/util/RequestLimitFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.opengis.cite.ogcapifeatures10.util; | ||
|
||
import io.restassured.filter.Filter; | ||
import io.restassured.filter.FilterContext; | ||
import io.restassured.response.Response; | ||
import io.restassured.specification.FilterableRequestSpecification; | ||
import io.restassured.specification.FilterableResponseSpecification; | ||
|
||
/** | ||
* @author Benjamin Pross (b.pross @52north.org) | ||
* | ||
* This class sets a limit for certain request to collection items. | ||
* If a limit parameter is already set, nothing is done. | ||
* | ||
*/ | ||
public class RequestLimitFilter implements Filter { | ||
|
||
private static String ITEMS = "items"; | ||
private static String LIMIT = "limit"; | ||
|
||
@Override | ||
public Response filter(FilterableRequestSpecification requestSpec, | ||
FilterableResponseSpecification responseSpec, | ||
FilterContext ctx) { | ||
//make sure that the limit is set only for requests to collection items | ||
if(requestSpec.getURI().endsWith(ITEMS) || requestSpec.getURI().endsWith(ITEMS + "/") | ||
|| requestSpec.getURI().contains(ITEMS + "?")){ | ||
//do nothing if a limit was already specified | ||
if(!(requestSpec.getQueryParams().containsKey(LIMIT) | ||
|| requestSpec.getRequestParams().containsKey(LIMIT))) { | ||
requestSpec.queryParam(LIMIT, 10); | ||
} | ||
} | ||
return ctx.next(requestSpec, responseSpec); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters