Package org.geoserver.rest

Examples of org.geoserver.rest.RestletException


        // any of these conditions mean the layer is not currently
        // advertised in the capabilities document
        if (layer == null || !layer.isEnabled()
                || !(layer.getResource() instanceof FeatureTypeInfo)) {
            throw new RestletException("No such layer: " + layerName, Status.CLIENT_ERROR_NOT_FOUND);
        }

        // build the feature collection and wrap it in a resource
        final FeatureTypeInfo resource = (FeatureTypeInfo) layer.getResource();
        try {
            SimpleFeatureSource featureSource = (SimpleFeatureSource) resource.getFeatureSource(
                    null, null);
            Query query = buildQuery(request, featureSource.getSchema());
           
            // couple sanity checks
            final QueryCapabilities queryCapabilities = featureSource.getQueryCapabilities();
            if(!queryCapabilities.isOffsetSupported() && (query.getStartIndex() != null && query.getStartIndex() > 1)) {
                throw new RestletException("Offset is not supported on this data source", Status.SERVER_ERROR_INTERNAL);
            }
           
            SimpleFeatureCollection features = featureSource.getFeatures(query);

            Form form = request.getResourceRef().getQueryAsForm();
            String mode = form.getFirstValue("mode");

            if (mode == null || "features".equals(mode)) {
                return new FeatureCollectionResource(getContext(), request, response, features);
            } else if ("bounds".equals(mode)) {
                return new BoundsResource(getContext(), request, response, features.getBounds());
            } else if ("count".equals(mode)) {
                return new CountResource(getContext(), request, response, features.size());
            } else {
                throw new RestletException("Uknown mode '" + mode + "'",
                        Status.SERVER_ERROR_INTERNAL);
            }
        } catch (IOException e) {
            throw new RestletException("Internal error occurred while "
                    + "retrieving the features to be returned", Status.SERVER_ERROR_INTERNAL, e);
        }
    }
View Full Code Here


                query.setPropertyNames(properties);
            }

            // check if we have residual, unknown attributes
            if (attributes.size() > 0) {
                throw new RestletException(
                        "The following attributes are not known to this service: " + attributes,
                        Status.CLIENT_ERROR_BAD_REQUEST);
            }
        }
    }
View Full Code Here

            }

            // check directions and attributes are matched
            if (directions != null && directions.length != orderByAtts.length) {
                if (directions.length < orderByAtts.length) {
                    throw new RestletException("dir list has less entries than order_by",
                            Status.CLIENT_ERROR_BAD_REQUEST);
                } else {
                    throw new RestletException("dir list has more entries than order_by",
                            Status.CLIENT_ERROR_BAD_REQUEST);
                }
            }

            SortBy[] sortBy = new SortBy[orderByAtts.length];
            for (int i = 0; i < orderByAtts.length; i++) {
                String name = orderByAtts[i];
                SortOrder order = getSortOrder(directions, i);

                AttributeDescriptor descriptor = schema.getDescriptor(name);
                if (descriptor == null) {
                    throw new RestletException("Uknown order_by attribute " + name,
                            Status.CLIENT_ERROR_BAD_REQUEST);
                } else if (descriptor instanceof GeometryDescriptor) {
                    throw new RestletException("order_by attribute " + name + " is a geometry, "
                            + "cannot sort on it", Status.CLIENT_ERROR_BAD_REQUEST);
                }

                sortBy[i] = FF.sort(name, order);
            }
View Full Code Here

        String offset = form.getFirstValue("offset");
        if (offset != null) {
            try {
                query.setStartIndex(Integer.parseInt(offset));
            } catch (NumberFormatException e) {
                throw new RestletException("Invalid offset expression: " + offset,
                        Status.CLIENT_ERROR_BAD_REQUEST);
            }
        }
    }
View Full Code Here

        }
        if (limit != null) {
            try {
                query.setMaxFeatures(Integer.parseInt(limit));
            } catch (NumberFormatException e) {
                throw new RestletException("Invalid limit expression: " + limit,
                        Status.CLIENT_ERROR_BAD_REQUEST);
            }
        }
    }
View Full Code Here

            if (queryable != null) {
                String[] attributes = queryable.split("\\s*,\\s*");
                for (String name : attributes) {
                    AttributeDescriptor ad = schema.getDescriptor(name);
                    if (ad == null) {
                        throw new RestletException("Uknown queryable attribute " + name,
                                Status.CLIENT_ERROR_BAD_REQUEST);
                    } else if (ad instanceof GeometryDescriptor) {
                        throw new RestletException("queryable attribute " + name
                                + " is a geometry, " + "cannot perform non spatial filters on it",
                                Status.CLIENT_ERROR_BAD_REQUEST);
                    }

                    final PropertyName property = FF.property(name);
                    final String prefix = name + "__";
                    for (String paramName : form.getNames()) {
                        if (paramName.startsWith(prefix)) {
                            Literal value = FF.literal(form.getFirstValue(paramName));
                            String op = paramName.substring(prefix.length());
                            if ("eq".equals(op)) {
                                filters.add(FF.equals(property, value));
                            } else if ("ne".equals(op)) {
                                filters.add(FF.notEqual(property, value));
                            } else if ("lt".equals(op)) {
                                filters.add(FF.less(property, value));
                            } else if ("lte".equals(op)) {
                                filters.add(FF.lessOrEqual(property, value));
                            } else if ("ge".equals(op)) {
                                filters.add(FF.greater(property, value));
                            } else if ("gte".equals(op)) {
                                filters.add(FF.greaterOrEqual(property, value));
                            } else if ("like".equals(op)) {
                                String pattern = form.getFirstValue(paramName);
                                filters.add(FF.like(property, pattern, "%", "_", "\\", true));
                            } else if ("ilike".equals(op)) {
                                String pattern = form.getFirstValue(paramName);
                                filters.add(FF.like(property, pattern, "%", "_", "\\", false));
                            } else {
                                throw new RestletException("Uknown query operand '" + op + "'",
                                        Status.CLIENT_ERROR_BAD_REQUEST);
                            }
                        }
                    }
                }
            }

            if (filters.size() > 0) {
                // summarize all the filters
                Filter result = FF.and(filters);
                SimplifyingFilterVisitor simplifier = new SimplifyingFilterVisitor();
                result = (Filter) result.accept(simplifier, null);

                // if necessary, reproject the filters
                String crs = form.getFirstValue("crs");
                if (crs == null) {
                    crs = form.getFirstValue("epsg");
                }
                if (crs != null) {
                    try {
                        // apply the default srs into the spatial filters
                        CoordinateReferenceSystem sourceCrs = CRS.decode("EPSG:" + crs, true);
                        DefaultCRSFilterVisitor crsForcer = new DefaultCRSFilterVisitor(FF,
                                sourceCrs);
                        result = (Filter) result.accept(crsForcer, null);
                    } catch (Exception e) {
                        throw new RestletException("Uknown EPSG code '" + crs + "'",
                                Status.CLIENT_ERROR_BAD_REQUEST);
                    }
                }

                query.setFilter(result);
View Full Code Here

    private double getTolerance(Form form) {
        String tolerance = form.getFirstValue("tolerance");
        if(tolerance != null) {
            double tolValue = parseDouble(tolerance, "tolerance");
            if(tolValue < 0) {
                throw new RestletException("Invalid tolerance, it should be zero or positive: " + tolValue ,
                        Status.CLIENT_ERROR_BAD_REQUEST);
            }
            return tolValue;
        } else {
            return 0d;
View Full Code Here

        String y = form.getFirstValue("lat");
        if (x == null && y == null) {
            return Filter.INCLUDE;
        }
        if (x == null || y == null) {
            throw new RestletException(
                    "Incomplete x/y specification, must provide both values",
                    Status.CLIENT_ERROR_BAD_REQUEST);
        }
        double ordx = parseDouble(x, "x");
        double ordy = parseDouble(y, "y");
View Full Code Here

    double parseDouble(String value, String name) {
        try {
            return Double.parseDouble(value);
        } catch (NumberFormatException e) {
            throw new RestletException("Expected a number for " + name + " but got " + value,
                    Status.CLIENT_ERROR_BAD_REQUEST);
        }
    }
View Full Code Here

                    maxx += tolerance;
                    maxy += tolerance;
                }
                return FF.bbox(defaultGeomName, minx, miny, maxx, maxy, null);
            } catch (Exception e) {
                throw new RestletException("Could not parse the bbox: " + e.getMessage(),
                        Status.CLIENT_ERROR_BAD_REQUEST);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.geoserver.rest.RestletException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.