Skip to content

Commit

Permalink
[GEOS-9065] Better error reporting when specifying a non existing att…
Browse files Browse the repository at this point in the history
…ribute in classify resource of sldService
  • Loading branch information
aaime committed Dec 16, 2018
1 parent 2610613 commit 46a35b7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.Polygon;
import org.opengis.feature.type.FeatureType;
import org.opengis.feature.type.PropertyDescriptor;
import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory2;
import org.opengis.filter.spatial.BBOX;
Expand Down Expand Up @@ -504,7 +505,19 @@ private List<Rule> getVectorRules(
}

List<Rule> rules = null;
Class<?> propertyType = ftType.getDescriptor(property).getType().getBinding();
final PropertyDescriptor pd = ftType.getDescriptor(property);
if (pd == null) {
throw new RestException(
"Could not find property "
+ property
+ ", available attributes are: "
+ ftType.getDescriptors()
.stream()
.map(p -> p.getName().getLocalPart())
.collect(Collectors.joining(", ")),
HttpStatus.BAD_REQUEST);
}
Class<?> propertyType = pd.getType().getBinding();

if (customClasses.isEmpty()) {
if ("equalInterval".equals(method)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.geoserver.sldservice.rest;

import static org.geoserver.sldservice.utils.classifier.RasterSymbolizerBuilder.DEFAULT_MAX_PIXELS;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -221,6 +222,23 @@ public void testClassifyForFeatureDefault() throws Exception {
assertFalse(resultXml.indexOf("StyledLayerDescriptor") != -1);
}

@Test
public void testClassifyWrongAttribute() throws Exception {
final String restPath =
RestBaseController.ROOT_PATH
+ "/sldservice/cite:ClassificationPoints/"
+ getServiceUrl()
+ ".xml?"
+ "attribute=foobar";
MockHttpServletResponse response = getAsServletResponse(restPath);
assertEquals(400, response.getStatus());
final String xml = response.getContentAsString();
assertThat(
xml,
containsString(
"Could not find property foobar, available attributes are: id, name, foo, bar, geom, group"));
}

@Test
public void testCustomStroke() throws Exception {
final String restPath =
Expand Down

0 comments on commit 46a35b7

Please sign in to comment.