Package org.vfny.geoserver.wfs

Examples of org.vfny.geoserver.wfs.WfsException


            LOGGER.finest("calling parse on " + requestSource);
            adapter.parse(requestSource);
            LOGGER.fine("just parsed: " + requestSource);
        } catch (SAXException e) {
            e.printStackTrace(System.out);
            throw new WfsException(e, "XML getFeature request SAX parsing error",
                XmlRequestReader.class.getName());
        } catch (IOException e) {
            throw new WfsException(e, "XML get feature request input error",
                XmlRequestReader.class.getName());
        } catch (ParserConfigurationException e) {
            throw new WfsException(e, "Some sort of issue creating parser",
                XmlRequestReader.class.getName());
        }

        Request r = contentHandler.getRequest(req);
View Full Code Here


        String outputFormat = request.getOutputFormat();

        try {
            delegate = GetNearestResponse.getDelegate(outputFormat);
        } catch (NoSuchElementException ex) {
            throw new WfsException("output format: " + outputFormat + " not "
                + "supported by geoserver", ex);
        }

        GetNearestResults results = new GetNearestResults(request);

        //
        // Optimization Idea
        //
        // We should be able to reduce this to a two pass opperations.
        //
        // Pass #1 execute
        // - Attempt to Locks Fids during the first pass
        // - Also collect Bounds information during the first pass
        //
        // Pass #2 writeTo
        // - Using the Bounds to describe our FeatureCollections
        // - Iterate through FeatureResults producing GML
        //
        // And allways remember to release locks if we are failing:
        // - if we fail to aquire all the locks we will need to fail and
        //   itterate through the the FeatureSources to release the locks
        //
        WFS wfs = request.getWFS();
        GeoServer config = wfs.getGeoServer();
        Data catalog = wfs.getData();
        FeatureTypeInfo meta = null;
        NameSpaceInfo namespace;
        Query query;

        FeatureSource source;
        Feature feature;
        String fid;
        FilterFactory filterFactory = FilterFactoryFinder.createFilterFactory();
        FidFilter fidFilter;

        try {
            for (Iterator it = request.getQueries().iterator(); it.hasNext();) {
                query = (Query) it.next();

                // the feature type name used in the content disposition response will match
                // the first feature type
                if (featureTypeName == null) {
                    featureTypeName = query.getTypeName();
                }

                meta = catalog.getFeatureTypeInfo(query.getTypeName());
                namespace = meta.getDataStoreInfo().getNameSpace();
                source = meta.getFeatureSource();

                List attrs = meta.getAttributes();

                List propNames = query.getPropertyNames(); // REAL LIST: be careful here :)
                List attributeNames = meta.getAttributeNames();

                for (Iterator iter = propNames.iterator(); iter.hasNext();) {
                    String propName = (String) iter.next();

                    if (!attributeNames.contains(propName)) {
                        String mesg = "Requested property: " + propName + " is "
                            + "not available for " + query.getTypeName() + ".  "
                            + "The possible propertyName values are: " + attributeNames;
                        throw new WfsException(mesg);
                    }
                   
                   
                }
View Full Code Here

        if (typeList.size() == 0) {
            typeList = getTypesFromFids(fidKvps);

            if (typeList.size() == 0) {
                throw new WfsException("The typename element is mandatory if "
                    + "no FEATUREID is present");
            }
        }

        int featureSize = typeList.size();

        // check for errors in the request
        if (((propertySize != featureSize) && (propertySize > 1))
                || ((filterSize != featureSize) && (filterSize > 1))) {
            throw new WfsException("Properties or filter sizes do not match"
                + " feature types.  Property size: " + propertySize + " Filter size: " + filterSize
                + " Feature size: " + featureSize);
        } else {
            // loops through feature types, and creates queries based on them
            LOGGER.finest("setting query request parameters");
View Full Code Here

        nl = verbose ? "\n" : "";
    }

    public void execute(Request req) throws WfsException {
        if (!(req instanceof LockRequest)) {
            throw new WfsException("bad request, expected LockRequest, got "
                + req);
        }
    if( (req.getWFS().getServiceLevel() & WFSDTO.SERVICE_LOCKING ) == 0 ){
       // could we catch this during the handler, rather than during execution?
       throw new WfsException("Locking support is not enabled");
    }
        request = (LockRequest) req;
        xmlResponse = getXmlResponse(request);
    }
View Full Code Here

    public void writeTo(OutputStream out) throws ServiceException {
        try {
            byte[] content = xmlResponse.getBytes();
            out.write(content);
        } catch (IOException ex) {
            throw new WfsException(ex, "", getClass().getName());
        }
    }
View Full Code Here

        LOGGER.finer("about to do Lock response on:" + request);

        List locks = request.getLocks();

        if (locks.size() == 0) {
            throw new WfsException("A LockFeature request must contain at "
                + "least one LOCK element");
        }

        LockRequest.Lock curLock = (LockRequest.Lock) locks.get(0);
        boolean lockAll = request.getLockAll();

        FeatureLock fLock = request.toFeatureLock();
        Set lockedFids = new HashSet();
        Set lockFailedFids = new HashSet();
        GeoServer config = request.getGeoServer();
        Data catalog = request.getWFS().getData();
        FilterFactory filterFactory = FilterFactory.createFilterFactory();
        LOGGER.info("locks size is " + locks.size());

        if (locks.size() == 0) {
            throw new WfsException("Lock Request must contain at least one "
                + " Lock element, your request is " + request);
        }

        for (int i = 0, n = locks.size(); i < n; i++) {
            curLock = (LockRequest.Lock) locks.get(i);
            LOGGER.info("curLock is " + curLock);

            String curTypeName = curLock.getFeatureType();
            Filter curFilter = curLock.getFilter();

            FeatureTypeInfo meta = catalog.getFeatureTypeInfo(curTypeName);
            NameSpaceInfo namespace = meta.getDataStoreInfo().getNameSpace();
            FeatureSource source = meta.getFeatureSource();
            FeatureResults features = source.getFeatures(curFilter);

            if( source instanceof FeatureLocking){
                ((FeatureLocking)source).setFeatureLock(fLock);
            }
            FeatureReader reader = null;

            try {
                for (reader = features.reader(); reader.hasNext();) {
                    Feature feature = reader.next();
                    String fid = feature.getID();
                    if( !(source instanceof FeatureLocking)){
                        LOGGER.fine("Lock " + fid +
                                " not supported by data store (authID:"
                                + fLock.getAuthorization() + ")");
                        lockFailedFids.add(fid);
                    }
                    else {
                        Filter fidFilter = filterFactory.createFidFilter(fid);

                        //DEFQuery is just some indirection, should be in the locking interface.
                        //int numberLocked = ((DEFQueryFeatureLocking)source).lockFeature(feature);
                        //HACK: Query.NO_NAMES isn't working in postgis right now,
                        //so we'll just use all.
                        Query query = new DefaultQuery(
                                meta.getTypeName(), fidFilter,
                                Query.DEFAULT_MAX, Query.ALL_NAMES,
                                curLock.getHandle());
                        int numberLocked = ((FeatureLocking)source).lockFeatures( query );

                        if (numberLocked == 1) {
                            LOGGER.fine("Lock " + fid + " (authID:"
                                + fLock.getAuthorization() + ")");
                            lockedFids.add(fid);
                        } else if (numberLocked == 0) {
                            LOGGER.fine("Lock " + fid + " conflict (authID:"
                                + fLock.getAuthorization() + ")");
                            lockFailedFids.add(fid);
                        } else {
                            LOGGER.warning("Lock " + numberLocked + " " + fid
                                + " (authID:" + fLock.getAuthorization()
                                + ") duplicated FeatureID!");
                            lockedFids.add(fid);
                        }
                    }
                }
            } catch (IllegalAttributeException e) {
                // TODO: JG - I really dont like this
                // reader says it will throw this if the attribtues do not match
                // the FeatureTypeInfo
                // I figure if this is thrown we are poorly configured or
                // the DataStoreInfo needs some quality control
                //
                // should rollback the lock as well :-(
                throw new WfsException("Lock request " + curFilter
                    + " did not match " + curTypeName);
            } finally {
                if (reader != null) {
                    reader.close();
                }
            }
        }

        if (lockAll && !lockFailedFids.isEmpty()) {
            // I think we need to release and fail when lockAll fails
            //
            // abort will release the locks
            throw new WfsException("Could not aquire locks for:"
                + lockFailedFids);
        }

        if (getXml) {
            return generateXml(fLock.getAuthorization(), lockAll,
View Full Code Here

        try {
            return performLock(request, true);
        } catch (IOException ioException) {
            ioException.printStackTrace(System.out);

            WfsException wfsException = new WfsException(
                    "Problem aquiring lock");
            wfsException.initCause(ioException);
            throw wfsException;
        }
    }
View Full Code Here

        String outputFormat = request.getOutputFormat();

        try {
            delegate = FeatureResponse.getDelegate(outputFormat);
        } catch (NoSuchElementException ex) {
            throw new WfsException("output format: " + outputFormat + " not "
                + "supported by geoserver", ex);
        }

        if (request instanceof FeatureWithLockRequest) {
            featureLock = ((FeatureWithLockRequest) request).toFeatureLock();

            String authorization = featureLock.getAuthorization();
            LOGGER.finest("FeatureWithLock using Lock:" + authorization);
        }

        GetFeatureResults results = new GetFeatureResults(request);
        results.setFeatureLock(featureLock);

        //
        // Optimization Idea
        //
        // We should be able to reduce this to a two pass opperations.
        //
        // Pass #1 execute
        // - Attempt to Locks Fids during the first pass
        // - Also collect Bounds information during the first pass
        //
        // Pass #2 writeTo
        // - Using the Bounds to describe our FeatureCollections
        // - Iterate through FeatureResults producing GML
        //
        // And allways remember to release locks if we are failing:
        // - if we fail to aquire all the locks we will need to fail and
        //   itterate through the the FeatureSources to release the locks
        //
        GeoServer config = request.getWFS().getGeoServer();
        Data catalog = request.getWFS().getData();
        FeatureTypeInfo meta = null;
        NameSpaceInfo namespace;
        Query query;
        int maxFeatures = request.getMaxFeatures();
        int serverMaxFeatures = config.getMaxFeatures();

        if (maxFeatures > serverMaxFeatures) {
            maxFeatures = serverMaxFeatures;
        }

        Set lockedFids = new HashSet();
        Set lockFailedFids = new HashSet();

        FeatureSource source;
        Feature feature;
        String fid;
        FilterFactory filterFactory = FilterFactory.createFilterFactory();
        FidFilter fidFilter;
        int numberLocked;

        try {
            for (Iterator it = request.getQueries().iterator();
                    it.hasNext() && (maxFeatures > 0);) {
                query = (Query) it.next();
                meta = catalog.getFeatureTypeInfo(query.getTypeName());
                namespace = meta.getDataStoreInfo().getNameSpace();
                source = meta.getFeatureSource();

                List attrs = meta.getAttributes();

                List propNames = query.getPropertyNames(); // REAL LIST: be careful here :)
                List attributeNames = meta.getAttributeNames();

                for (Iterator iter = propNames.iterator(); iter.hasNext();) {
                    String propName = (String) iter.next();

                    if (!attributeNames.contains(propName)) {
                        String mesg = "Requested property: " + propName
                            + " is " + "not available for "
                            + query.getTypeName() + ".  "
                            + "The possible propertyName values are: "
                            + attributeNames;
                        throw new WfsException(mesg);
                    }
                }

                if (propNames.size() != 0) {
                    Iterator ii = attrs.iterator();
                    List tmp = new LinkedList();

                    while (ii.hasNext()) {
                        AttributeTypeInfo ati = (AttributeTypeInfo) ii.next();

                        //String attName = (String) ii.next();
                        LOGGER.finer("checking to see if " + propNames
                            + " contains" + ati);

                        if (((ati.getMinOccurs() > 0)
                                && (ati.getMaxOccurs() != 0))
                                || propNames.contains(ati.getName())) {
                            tmp.add(ati.getName());
                        }
                    }

                    query.setPropertyNames(tmp);
                }

                // This doesn't seem to be working?
                // Run through features and record FeatureIDs
                // Lock FeatureIDs as required
                //}
                LOGGER.fine("Query is " + query + "\n To gt2: "
                    + query.toDataQuery(maxFeatures));

                //DJB: note if maxFeatures gets to 0 the while loop above takes care of this! (this is a subtle situation)
               
                FeatureResults features = source.getFeatures(query.toDataQuery(
                            maxFeatures));
                if (it.hasNext()) //DJB: dont calculate feature count if you dont have to. The MaxFeatureReader will take care of the last iteration
                  maxFeatures -= features.getCount();

                //GR: I don't know if the featuresults should be added here for later
                //encoding if it was a lock request. may be after ensuring the lock
                //succeed?
                results.addFeatures(meta, features);

                if (featureLock != null) {
                    // geotools2 locking code
                    if (source instanceof FeatureLocking) {
                        ((FeatureLocking) source).setFeatureLock(featureLock);
                    }

                    FeatureReader reader = null;

                    try {
                        for (reader = features.reader(); reader.hasNext();) {
                            feature = reader.next();
                            fid = feature.getID();

                            if (!(source instanceof FeatureLocking)) {
                                LOGGER.finest("Lock " + fid
                                    + " not supported by data store (authID:"
                                    + featureLock.getAuthorization() + ")");
                                lockFailedFids.add(fid);

                                continue; // locking is not supported!
                            } else {
                                fidFilter = filterFactory.createFidFilter(fid);
                                numberLocked = ((FeatureLocking) source)
                                    .lockFeatures(fidFilter);

                                if (numberLocked == 1) {
                                    LOGGER.finest("Lock " + fid + " (authID:"
                                        + featureLock.getAuthorization() + ")");
                                    lockedFids.add(fid);
                                } else if (numberLocked == 0) {
                                    LOGGER.finest("Lock " + fid
                                        + " conflict (authID:"
                                        + featureLock.getAuthorization() + ")");
                                    lockFailedFids.add(fid);
                                } else {
                                    LOGGER.warning("Lock " + numberLocked + " "
                                        + fid + " (authID:"
                                        + featureLock.getAuthorization()
                                        + ") duplicated FeatureID!");
                                    lockedFids.add(fid);
                                }
                            }
                        }
                    } finally {
                        if (reader != null) {
                            reader.close();
                        }
                    }

                    if (!lockedFids.isEmpty()) {
                        Transaction t = new DefaultTransaction();

                        try {
                            t.addAuthorization(featureLock.getAuthorization());
                            source.getDataStore().getLockingManager().refresh(featureLock
                                .getAuthorization(), t);
                        } finally {
                            t.commit();
                        }
                    }
                }
            }

            //end for
            //prepare to encode in the desired output format
            delegate.prepare(outputFormat, results);

            if ((featureLock != null) && !lockFailedFids.isEmpty()) {
                // I think we need to release and fail when lockAll fails
                //
                // abort will take care of releasing the locks
                throw new WfsException("Could not aquire locks for:"
                    + lockFailedFids);
            }
        } catch (IOException e) {
            throw new ServiceException(e, "problem with FeatureResults",
                request.getHandle());
View Full Code Here

            org.geotools.data.Query dsQuery = query.getDataSourceQuery(maxFeatures);

            features = data.getFeatures(dsQuery);
        } catch (IOException e) {
            throw new WfsException(e, "While getting features from datasource",
                getLocator(query));
        }

        LOGGER.finest("successfully retrieved collection");
View Full Code Here

     *
     * @throws WfsException For any problems making the xml response.
     */
    public void execute(Request request) throws WfsException {
        if (!(request instanceof DescribeRequest)) {
            throw new WfsException(
                "illegal request type, expected DescribeRequest, got "
                + request);
        }

        DescribeRequest wfsRequest = (DescribeRequest) request;
        this.request = wfsRequest;
        LOGGER.finer("processing describe request" + wfsRequest);

        String outputFormat = wfsRequest.getOutputFormat();

        if (!outputFormat.equalsIgnoreCase("XMLSCHEMA")) {
            throw new WfsException("output format: " + outputFormat + " not "
                + "supported by geoserver");
        }

        // generates response, using general function
        xmlResponse = generateTypes(wfsRequest);
View Full Code Here

TOP

Related Classes of org.vfny.geoserver.wfs.WfsException

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.