Package org.geoserver.rest

Examples of org.geoserver.rest.RestletException


        LayerGroupInfo lg = (LayerGroupInfo) object;
        LayerGroupInfo original = catalog.getLayerGroupByName( layergroup );
      
        //ensure not a name change
        if ( lg.getName() != null && !lg.getName().equals( original.getName() ) ) {
            throw new RestletException( "Can't change name of a layer group", Status.CLIENT_ERROR_FORBIDDEN );
        }
       
        new CatalogBuilder( catalog ).updateLayerGroup( original, lg );
        catalog.save( original );
    }
View Full Code Here


        String style = (String) request.getAttributes().get( "style" );
        String layer = (String) request.getAttributes().get( "layer" );

        //check style exists if specified
        if ( style != null && catalog.getStyleByName( style ) == null ) {
            throw new RestletException( "No such style: " + style, Status.CLIENT_ERROR_NOT_FOUND );
        }

        //check layer exists if specified
        if ( layer != null && catalog.getLayerByName( layer ) == null ) {
            throw new RestletException( "No such layer: " + layer, Status.CLIENT_ERROR_NOT_FOUND);
            /*
            String ns = null;
            String resource = null;
           
            if ( layer.contains( ":" ) ) {
View Full Code Here

            return new LayerListResource(getContext(),request,response,catalog);
        }
       
        //ensure referenced resources exist
        if ( layer != null && catalog.getLayerByName(layer) == null ) {
            throw new RestletException( "No such layer: " + layer, Status.CLIENT_ERROR_NOT_FOUND );
        }
       
        return new LayerResource(null,request,response,catalog);
    }
View Full Code Here

        File directory;
        try {
            directory = catalog.getResourceLoader().find( "data/" + datastore );
        }
        catch (IOException e) {
            throw new RestletException( e.getMessage(), Status.SERVER_ERROR_INTERNAL, e );
        }
       
        if ( directory == null || !directory.exists() || !directory.isDirectory() ) {
            throw new RestletException( "No files for datastore " + datastore, Status.CLIENT_ERROR_NOT_FOUND );
        }
       
        //zip up all the files in the directory
        StreamDataFormat fmt = new StreamDataFormat(MediaType.APPLICATION_ZIP) {
View Full Code Here

        File directory;
        try {
            directory = catalog.getResourceLoader().createDirectory( "data/" + datastore );
        }
        catch (IOException e) {
            throw new RestletException( e.getMessage(), Status.SERVER_ERROR_INTERNAL, e );
        }
       
        File uploadedFile = handleFileUpload(datastore, format, directory);

        //create a builder to help build catalog objects
        CatalogBuilder builder = new CatalogBuilder(catalog);
        builder.setWorkspace( catalog.getWorkspaceByName( workspace ) );
       
        //check if the datastore already exists, if not auto configure one
        DataStoreInfo info = catalog.getDataStoreByName( datastore );
       
        boolean add = false;
        if ( info == null ) {
            LOGGER.info("Auto-configuring datastore: " + datastore);
           
            info = builder.buildDataStore( datastore );
            add = true;
        }
        else {
            LOGGER.info("Using existing datastore: " + datastore);
        }
       
        builder.setStore(info);
       
        //update the connection parameters to point to the new file
        Map connectionParameters = info.getConnectionParameters();
        for ( Param p : factory.getParametersInfo() ) {
            //the nasty url / file hack
            if ( File.class == p.type || URL.class == p.type ) {
                File f = uploadedFile;
               
                if ( "directory".equals( p.key ) ) {
                    //set the value to be the directory
                    f = directory;
                }
               
                //convert to the required type
                //TODO: use geotools converter
                Object converted = null;
                if ( URI.class.equals( p.type  ) ) {
                    converted = f.toURI();
                }
                else if ( URL.class.equals( p.type ) ) {
                    try {
                        converted = f.toURL();
                    }
                    catch (MalformedURLException e) {
                    }
                }
                //Converters.convert( f.getAbsolutePath(), p.type );
               
                if ( converted != null ) {
                    connectionParameters.put( p.key, converted );   
                }
                else {
                    connectionParameters.put( p.key, f );
                }
               
                continue;
            }
           
            if ( p.required ) {
                try {
                    p.lookUp( connectionParameters );
                }
                catch( Exception e ) {
                    //set the sample value
                    connectionParameters.put( p.key, p.sample );
                }   
            }
        }
       
        // set the namespace uri
        NamespaceInfo namespace = catalog.getNamespaceByPrefix( info.getWorkspace().getName() );
        connectionParameters.put( "namespace", namespace.getURI() );
       
        // ensure the parameters are valid
        if ( !factory.canProcess( connectionParameters ) ) {
            //TODO: log the parameters at the debug level
            throw new RestletException( "Unable to configure datastore, bad parameters.", Status.SERVER_ERROR_INTERNAL );
        }
       
        //add or update the datastore info
        if ( add ) {
            catalog.add( info );
View Full Code Here

        String ws = (String) request.getAttributes().get( "workspace" );
        String ds = (String) request.getAttributes().get( "datastore" );
       
        //ensure referenced resources exist
        if ( ws != null && catalog.getWorkspaceByName( ws ) == null ) {
            throw new RestletException( "No such workspace: " + ws, Status.CLIENT_ERROR_NOT_FOUND );
        }
        if ( ds != null && catalog.getDataStoreByName(ws, ds) == null ) {
            throw new RestletException( "No such datastore: " + ws + "," + ds, Status.CLIENT_ERROR_NOT_FOUND );
        }
       
        if ( ds == null && request.getMethod() == Method.GET ) {
            return new DataStoreListResource(getContext(),request,response,catalog);
        }
View Full Code Here

            NamespaceInfo ns = catalog.getNamespaceByPrefix( workspace );
            if ( ns != null ) {
                return catalog.getCoverageByName(ns,coverage);
            }

            throw new RestletException( "", Status.CLIENT_ERROR_NOT_FOUND );
        }

        LOGGER.fine( "GET coverage " + coveragestore + "," + coverage );
        CoverageStoreInfo cs = catalog.getCoverageStoreByName(workspace, coveragestore);
        return catalog.getCoverageByCoverageStore( cs, coverage );
View Full Code Here

        String ws = (String) request.getAttributes().get( "workspace" );
        String cs = (String) request.getAttributes().get( "coveragestore" );
       
        //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 coverage store: " + ws + "," + cs, Status.CLIENT_ERROR_NOT_FOUND );
        }
       
        if ( cs == null && request.getMethod() == Method.GET ) {
            return new CoverageStoreListResource(getContext(),request,response,catalog);
        }
View Full Code Here

        String ds = (String) request.getAttributes().get( "datastore" );
        String ft = (String) request.getAttributes().get( "featuretype");
       
        //ensure referenced resources exist
        if ( ws != null && catalog.getWorkspaceByName( ws ) == null ) {
            throw new RestletException( "No such workspace: " + ws, Status.CLIENT_ERROR_NOT_FOUND );
        }
        if ( ds != null && catalog.getDataStoreByName(ws, ds) == null ) {
            throw new RestletException( "No such datastore: " + ws + "," + ds, Status.CLIENT_ERROR_NOT_FOUND );
        }
       
        if ( ft != null ) {
            if ( ds != null &&
                    catalog.getFeatureTypeByDataStore(catalog.getDataStoreByName(ws, ds), ft) == null) {
                throw new RestletException( "No such feature type: "+ws+","+ds+","+ft, Status.CLIENT_ERROR_NOT_FOUND );
            }
            else {
                //look up by workspace/namespace
                NamespaceInfo ns = catalog.getNamespaceByPrefix( ws );
                if ( ns == null || catalog.getFeatureTypeByName( ns, ft ) == null ) {
                    throw new RestletException( "No such feature type: "+ws+","+ft, Status.CLIENT_ERROR_NOT_FOUND );
                }
            }
        }
        else {
            //check the list flag, if == 'available', just return the list
View Full Code Here

            public void handlePost() {
                try {  
                    reloadCatalog();
                }
                catch (Exception e) {
                    throw new RestletException("Error reloading catalog", Status.SERVER_ERROR_INTERNAL, e);
                }
            }
            @Override
            public void handlePut() {
                handlePost();
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.