Description:
|
I created a new WPS process with some validation methods.
package ca.gc.nrcan.egp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import org.geoserver.wps.WPSException;
import org.geoserver.wps.gs.GeoServerProcess;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.geotools.process.ProcessException;
import org.geotools.process.factory.DescribeParameter;
import org.geotools.process.factory.DescribeProcess;
import org.geotools.process.factory.DescribeResult;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;
@DescribeProcess(title="VectorExtractionWPS", description="Extraction service for vector data")
public class VectorExtractionWPS implements GeoServerProcess {
private static Logger log = Logger.getLogger(VectorExtractionWPS.class.getName());
@DescribeResult(name="result", description="output result")
public String execute(
@DescribeParameter(name="layers", description="name of the layers to clip") String layers,
@DescribeParameter(name="outputFormat", description="output format of the spatial dataset") String outputFormat,
@DescribeParameter(name="delineation", description="outline used for clipping") String delineation,
@DescribeParameter(name="email", description="email address") String email)
{
validateEmail(email);
validateWKT(delineation);
validateLayers(layers);
validateOutputFormat(outputFormat);
return SubmitToLSF.BSUBvector(layers, outputFormat, delineation, email);
}
static void validateWKT(String wkt) {
Double maxArea = new Double(50.00);
GeometryFactory geoFac = JTSFactoryFinder.getGeometryFactory(null);
WKTReader reader = new WKTReader(geoFac);
try {
Polygon polygon = (Polygon) reader.read(wkt);
if (polygon.isEmpty()) {
throw new WPSException("empty polygon", "InvalidParameterValue", "delineation");
}
if (!polygon.isValid()) {
throw new WPSException("invalid polygon", "InvalidParameterValue", "delineation");
}else {
Double area = polygon.getArea();
if (area > maxArea) {
throw new WPSException("polygon to big", "InvalidParameterValue", "delineation");
}
}
}catch (ParseException e) {
log.info("validationWKT exception : " + e.getMessage());
}
}
static void validateEmail(String email) {
try {
InternetAddress emailAddr = new InternetAddress(email);
emailAddr.validate();
}catch(AddressException e) {
log.info("validateEmail exception : " + e.getMessage());
throw new WPSException(e.getMessage(), "InvalidParameterValue", "email");
}
}
static void validateLayers(String layers) {
ArrayList<String> layerList = new ArrayList<String>(Arrays.asList("bs", "en", "fo", "hd", "ic", "la", "li", "lx", "ss", "to", "tr", "ve"));
List<String> layerError = new ArrayList<String>();
String[] ll = layers.split(",");
for (int i = 0; i < ll.length; i += 1) {
if (!layerList.contains(ll[i].toLowerCase())) {
layerError.add(ll[i]);
}
}
throw new WPSException("invalid layer(s)", "InvalidParameterValue", layerError.toString());
}
static void validateOutputFormat(String outputFormat) {
ArrayList<String> formatList = new ArrayList<String>(Arrays.asList("geodatabase_file", "shape", "geojson", "gml2"));
if (!formatList.contains(outputFormat.toLowerCase())) {
log.info("validateOutputFormat exception : invalid output format " );
throw new WPSException("invalid output format", "InvalidParameterValue", outputFormat);
}
}
}
The validation methods throw a WPSException when there’s an invalid parameter. I’m setting the exceptionCode and locator value on the WPSException, but when I call the service with any type of error I always receive this message (the only thing that changes is the text in ows:ExceptionText which is always doubled!):
<?xml version="1.0" encoding="UTF-8"?>
<wps:ExecuteResponse xml:lang="en" service="WPS" serviceInstance="http://localhost:8080/geoserver/ows?" version="1.0.0">
<wps:Process wps:processVersion="1.0.0">
<ows:Identifier>gs:VectorExtractionWPS</ows:Identifier>
<ows:Title>VectorExtractionWPS</ows:Title>
<ows:Abstract>Extraction service for vector data</ows:Abstract>
</wps:Process>
<wps:Status creationTime="2012-10-30T15:35:54.335Z">
<wps:ProcessFailed>
<ows:ExceptionReport version="1.1.0">
<ows:Exception exceptionCode="NoApplicableCode">
<ows:ExceptionText>Process failed during execution org.geoserver.wps.WPSException: Invalid email address Invalid email address</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>
</wps:ProcessFailed>
</wps:Status>
</wps:ExecuteResponse>
Is this a bug or am I missing something in my code?
Thanks for any help,
Mark
|