Package org.geoserver.rest

Examples of org.geoserver.rest.RestletException


        }
        else {
            NamespaceInfo original = catalog.getNamespaceByPrefix( ns );
            //ensure this is not a prefix change
            if ( namespace.getPrefix() != null && !namespace.getPrefix().equals( original.getPrefix() ) ) {
                throw new RestletException( "Can't change the prefix of a namespace.", Status.CLIENT_ERROR_FORBIDDEN );
            }

            new CatalogBuilder(catalog).updateNamespace( original, namespace );
            catalog.save( original );
        }
View Full Code Here


    protected void handleObjectDelete() throws Exception {
        String namespace = (String) getRequest().getAttributes().get( "namespace");
        NamespaceInfo ns = catalog.getNamespaceByPrefix( namespace );
       
        if ( !catalog.getResourcesByNamespace(ns, ResourceInfo.class).isEmpty() ) {
            throw new RestletException( "Namespace not empty", Status.CLIENT_ERROR_UNAUTHORIZED );
        }
       
        catalog.remove( ns );
       
        LOGGER.info( "DELETE namespace " + namespace);
View Full Code Here

       
        if ( datastore != null ) {
            String factoryClassName = formatToDataStoreFactory.get( format );
           
            if ( factoryClassName == null ) {
                throw new RestletException( "Unsupported format: " + format, Status.CLIENT_ERROR_BAD_REQUEST );
            }
           
            DataStoreFactorySpi factory;
            try {
                Class factoryClass = Class.forName( factoryClassName );
                factory = (DataStoreFactorySpi) factoryClass.newInstance();
            }
            catch ( Exception e ) {
                throw new RestletException( "Datastore format unavailable: " + factoryClassName, Status.SERVER_ERROR_INTERNAL );
            }
           
            return new DataStoreFileResource(request,response,factory,catalog);
        }
        else {
            String coverageFormatName = formatToCoverageStoreFormat.get( format );
           
            if ( coverageFormatName == null ) {
                throw new RestletException( "Unsupported format: " + format, Status.CLIENT_ERROR_BAD_REQUEST );
            }
           
            Format coverageFormat = null;
            try {
                coverageFormat = CoverageStoreUtils.acquireFormat( coverageFormatName );
            }
            catch( Exception e ) {
                throw new RestletException( "Coveragestore format unavailable: " + coverageFormatName, Status.SERVER_ERROR_INTERNAL );
            }
           
            return new CoverageStoreFileResource(request,response,coverageFormat,catalog);
        }
       
View Full Code Here

        String workspace = (String) getRequest().getAttributes().get( "workspace" );
        String datastore = (String) getRequest().getAttributes().get( "datastore" );
       
        DataStoreInfo info = catalog.getDataStoreByName( workspace, datastore );
        if ( info == null ) {
            throw new RestletException( "No such datastore: " + datastore, Status.CLIENT_ERROR_NOT_FOUND );
        }
       
        //list of available feature types
        List<String> available = new ArrayList<String>();
        try {
            DataStore ds = (DataStore) info.getDataStore(null);
           
            String[] featureTypeNames = ds.getTypeNames();
            for ( String featureTypeName : featureTypeNames ) {
                FeatureTypeInfo ftinfo = catalog.getFeatureTypeByDataStore(info, featureTypeName);
                if (ftinfo == null ) {
                    //not in catalog, add it
                    available.add( featureTypeName );
                }
            }
        }
        catch (IOException e) {
            throw new RestletException( "Could not load datastore: " + datastore, Status.SERVER_ERROR_INTERNAL, e );
        }
       
        return available;
    }
View Full Code Here

        DataStoreInfo ds = (DataStoreInfo) object;
        if ( ds.getWorkspace() != null ) {
             //ensure the specifried workspace matches the one dictated by the uri
             WorkspaceInfo ws = (WorkspaceInfo) ds.getWorkspace();
             if ( !workspace.equals( ws.getName() ) ) {
                 throw new RestletException( "Expected workspace " + workspace +
                     " but client specified " + ws.getName(), Status.CLIENT_ERROR_FORBIDDEN );
             }
        }
        else {
             ds.setWorkspace( catalog.getWorkspaceByName( workspace ) );
View Full Code Here

        DataStoreInfo ds = (DataStoreInfo) object;
        DataStoreInfo original = catalog.getDataStoreByName(workspace, datastore);
       
        //ensure this is not a name or workspace change
        if ( ds.getName() != null && !ds.getName().equals( original.getName() ) ) {
            throw new RestletException( "Can't change name of data store.", Status.CLIENT_ERROR_FORBIDDEN );
        }
        if ( ds.getWorkspace() != null && !ds.getWorkspace().equals( original.getWorkspace() ) ) {
            throw new RestletException( "Can't change workspace of data store.", Status.CLIENT_ERROR_FORBIDDEN );
        }
       
        new CatalogBuilder( catalog ).updateDataStore( original, ds );
       
        catalog.save( original );
View Full Code Here

        String workspace = getAttribute("workspace");
        String datastore = getAttribute("datastore");
       
        DataStoreInfo ds = catalog.getDataStoreByName(workspace, datastore);
        if ( !catalog.getFeatureTypesByDataStore(ds).isEmpty() ) {
            throw new RestletException( "datastore not empty", Status.CLIENT_ERROR_FORBIDDEN);
        }
        catalog.remove( ds );
        
        LOGGER.info( "DELETE data store " + workspace + "," + datastore );
    }
View Full Code Here

                uploadedFile = RESTUtils.handleEXTERNALUpload(getRequest());
            }
            else{
                final StringBuilder builder =
                    new StringBuilder("Unrecognized file upload method: ").append(method);
                throw new RestletException( builder.toString(), Status.CLIENT_ERROR_BAD_REQUEST);
            }
        }
        catch (Throwable t) {
            throw new RestletException( "Error while storing uploaded file:", Status.SERVER_ERROR_INTERNAL, t );
        }
       
        //handle the case that the uploaded file was a zip file, if so unzip it
        if (mediaType!=null && RESTUtils.isZipMediaType( mediaType ) ) {
            //rename to .zip if need be
            if ( !uploadedFile.getName().endsWith( ".zip") ) {
                File newUploadedFile = new File( uploadedFile.getParentFile(), uploadedFile.getName() + ".zip" );
                uploadedFile.renameTo( newUploadedFile );
                uploadedFile = newUploadedFile;
            }
            //unzip the file
            try {
                RESTUtils.unzipFile(uploadedFile, directory );
               
                //look for the "primary" file
                //TODO: do a better check
                File primaryFile = findPrimaryFile( directory, format );
                if ( primaryFile != null ) {
                    uploadedFile = primaryFile;
                }
                else {
                    throw new RestletException( "Could not find appropriate " + format + " file in archive", Status.CLIENT_ERROR_BAD_REQUEST );
                }
            }
            catch( RestletException e ) {
                throw e;
            }
            catch( Exception e ) {
                throw new RestletException( "Error occured unzipping file", Status.SERVER_ERROR_INTERNAL, e );
            }
        }
       
        return uploadedFile;
View Full Code Here

   
    @Override
    public Resource findTarget(Request request, Response response) {
        String lg = (String) request.getAttributes().get( "layergroup" );
        if ( lg != null && catalog.getLayerGroupByName( lg ) == null ) {
            throw new RestletException( "No such layer group " + lg, Status.CLIENT_ERROR_NOT_FOUND );
        }
       
        if ( lg == null && request.getMethod() == Method.GET ) {
            return new LayerGroupListResource( getContext(), request, response, catalog );
        }
View Full Code Here

        String cs = (String) request.getAttributes().get( "coveragestore" );
        String c = (String) request.getAttributes().get( "coverage");
       
        //ensure referenced resources exist
        if ( ws != null && catalog.getWorkspaceByName( ws ) == null ) {
            throw new RestletException( "No such workspace: " + ws, Status.CLIENT_ERROR_NOT_FOUND );
        }
        if ( cs != null && catalog.getCoverageStoreByName(ws, cs) == null ) {
            throw new RestletException( "No such coveragestore: " + ws + "," + cs, Status.CLIENT_ERROR_NOT_FOUND );
        }
       
        if ( c == null && request.getMethod() == Method.GET ) {
            return new CoverageListResource( getContext(), request, response, catalog );
        }
       
        if ( c != null ) {
            if ( cs != null &&
                    catalog.getCoverageByCoverageStore(catalog.getCoverageStoreByName(ws, cs), c) == null) {
                throw new RestletException( "No such coverage: "+ws+","+cs+","+c, Status.CLIENT_ERROR_NOT_FOUND );
            }
            else {
                //look up by workspace/namespace
                NamespaceInfo ns = catalog.getNamespaceByPrefix( ws );
                if ( ns == null || catalog.getCoverageByName( ns, c ) == null ) {
                    throw new RestletException( "No such coverage: "+ws+","+c, Status.CLIENT_ERROR_NOT_FOUND );
                }
           
            }
        }
           
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.