Commit f4cbb4e7 authored by Andrea Aime's avatar Andrea Aime
Browse files

[GEOS-3432] RESTConfig styles list does not get generated if a style is...

[GEOS-3432] RESTConfig styles list does not get generated if a style is missing its associated sld file
parent b15880ca
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
......@@ -285,7 +285,13 @@ public class ReflectiveHTMLFormat extends DataFormat {
ClassProperties cp = OwsUtils.getClassProperties(clazz);
for ( String p : cp.properties() ) {
if ( "Class".equals( p ) ) continue;
Object value = OwsUtils.get(object, p);
Object value = null;
try {
value = OwsUtils.get(object, p);
} catch(Exception e) {
LOGGER.log(Level.WARNING, "Could not resolve property " + p + " of bean " + object, e);
value = "** Failed to retrieve value of property " + p + ". Error message is: " + e.getMessage() + "**";
}
if ( value == null ) {
value = "null";
}
......
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.rest.format;
import junit.framework.TestCase;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
import java.io.ByteArrayOutputStream;
import org.geoserver.rest.Foo;
import org.restlet.data.Request;
import org.restlet.resource.Representation;
import junit.framework.TestCase;
public class ReflectiveHTMLFormatTest extends TestCase {
public void test() throws Exception {
......@@ -21,6 +26,33 @@ public class ReflectiveHTMLFormatTest extends TestCase {
ReflectiveHTMLFormat fmt = new ReflectiveHTMLFormat(Foo.class,request,null,null);
Representation rep = fmt.toRepresentation(new Foo("one",2,3.0));
rep.write(System.out);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
rep.write(bos);
String value = bos.toString();
assertThat(value, containsString("prop2: 2"));
assertThat(value, containsString("prop1: one"));
assertThat(value, containsString("prop3: 3"));
}
public void testExceptionProperty() throws Exception {
Request request = new Request();
request.setResourceRef( "http://localhost/rest/foo.html");
request.getResourceRef().setBaseRef( "http://localhost/rest");
ReflectiveHTMLFormat fmt = new ReflectiveHTMLFormat(ExceptionBean.class,request,null,null);
Representation rep = fmt.toRepresentation(new ExceptionBean());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
rep.write(bos);
String value = bos.toString();
assertThat(value, containsString("Failed to retrieve value of property Exception. Error message is: "));
}
static final class ExceptionBean {
public void getException() {
throw new RuntimeException("Busted!");
}
}
}
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