it.geosolutions.geoserver.rest
Class GeoServerRESTPublisher

java.lang.Object
  extended by it.geosolutions.geoserver.rest.GeoServerRESTPublisher

public class GeoServerRESTPublisher
extends Object

Connect to a GeoServer instance to publish or modify its contents via REST API.

There are no modifiable instance fields, so all the calls are thread-safe.

Author:
ETj (etj at geo-solutions.it), Carlo Cancellieri - carlo.cancellieri@geo-solutions.it

Nested Class Summary
static class GeoServerRESTPublisher.CoverageStoreExtension
          Raster data format being uploaded.
static class GeoServerRESTPublisher.DataStoreExtension
          Vector data format being uploaded.
static class GeoServerRESTPublisher.DataStoreType
          Deprecated. use GeoServerRESTPublisher.DataStoreType
static class GeoServerRESTPublisher.Format
          Represents the format used to GET, PUT or POST information via REST.
static class GeoServerRESTPublisher.ParameterConfigure
          Control if feature types are to be automatically configured upon file upload.
static class GeoServerRESTPublisher.ParameterUpdate
          Controls how existing data is handled when the file is PUT into a datastore that (a) already exists and (b) already contains a schema that matches the content of the file.
static class GeoServerRESTPublisher.StoreType
          DataStoreType definitions.
static class GeoServerRESTPublisher.UploadMethod
          Specifies the method used to publish a resource.
 
Field Summary
static String DEFAULT_CRS
           
 
Constructor Summary
GeoServerRESTPublisher(String restURL, String username, String password)
          Creates a GeoServerRESTPublisher to connect against a GeoServer instance with the given URL and user credentials.
 
Method Summary
 String backup(String backupDir)
          Issues a GeoServer BACKUP.
 String backup(String backupDir, boolean includedata, boolean includegwc, boolean includelog)
          Issues a GeoServer BACKUP.
 boolean configureCoverage(GSCoverageEncoder ce, String wsname, String csname)
          Configure an existent coverage in a given workspace and coverage store
 boolean configureLayer(String workspace, String resourceName, GSLayerEncoder layer)
          Allows to configure some layer attributes such and DefaultStyle
 boolean configureLayerGroup(String name, GSLayerGroupEncoder group)
          Update a LayerGroup using the specified encoder
 boolean configureLayerGroup(String workspace, String name, GSLayerGroupEncoder group)
          Update a LayerGroup using the specified encoder
 boolean createCoverage(GSCoverageEncoder ce, String wsname, String csname)
          Deprecated. use createCoverage(String, String, GSCoverageEncoder)
 boolean createCoverage(String wsname, String storeName, GSCoverageEncoder ce)
          Create a new coverage in a given workspace and coverage store
 boolean createExternalMosaic(String workspace, String storeName, File mosaicDir, GSCoverageEncoder coverageEncoder, GSLayerEncoder layerEncoder)
          Deprecated. use publishExternalMosaic(String, String, File, GSCoverageEncoder, GSLayerEncoder)
 RESTCoverageStore createExternaMosaicDatastore(String workspace, String storeName, File mosaicDir, GeoServerRESTPublisher.ParameterConfigure configure, GeoServerRESTPublisher.ParameterUpdate update)
          Publish a Mosaic from a filesystem currently readable by GeoServer.
 boolean createLayerGroup(String name, GSLayerGroupEncoder group)
          Create a new LayerGroup using the specified encoder
 boolean createLayerGroup(String workspace, String name, GSLayerGroupEncoder group)
          Create a new LayerGroup using the specified encoder
 boolean createNamespace(String prefix, URI uri)
          Create a new Namespace.
 boolean createPostGISDatastore(String workspace, GSPostGISDatastoreEncoder datastoreEncoder)
          Deprecated. Will be deleted in next version 1.5.x, use GeoServerRESTDatastoreManager instead.
 boolean createWorkspace(String workspace)
          Create a new Workspace.
 boolean createWorkspace(String name, URI uri)
          Create both a workspace and its associated namespace.
protected  String encode(String s)
          URL-encodes a String.
 boolean publishDBLayer(String workspace, String storename, GSFeatureTypeEncoder fte, GSLayerEncoder layerEncoder)
          Publish and configure a new layer from an existing DataStore (v.
 boolean publishDBLayer(String workspace, String storename, String layername, String srs, String defaultStyle)
          Deprecated. Will be removed in the next release.
 RESTCoverageStore publishExternalGeoTIFF(String workspace, String storeName, File geotiff, GSCoverageEncoder coverageEncoder, GSLayerEncoder layerEncoder)
          Publish a GeoTiff already in a filesystem readable by GeoServer.
 boolean publishExternalGeoTIFF(String workspace, String storeName, File geotiff, String coverageName, String srs, GSResourceEncoder.ProjectionPolicy policy, String defaultStyle)
          Publish a GeoTiff already in a filesystem readable by GeoServer.
 boolean publishExternalMosaic(String workspace, String storeName, File mosaicDir, GSCoverageEncoder coverageEncoder, GSLayerEncoder layerEncoder)
          Publish a Mosaic already in a filesystem readable by GeoServer.
 boolean publishExternalMosaic(String workspace, String storeName, File mosaicDir, String srs, String defaultStyle)
          Publish a Mosaic already in a filesystem readable by GeoServer.
 boolean publishGeoTIFF(String workspace, String storeName, File geotiff)
          Upload and publish a GeoTIFF image.
 boolean publishGeoTIFF(String workspace, String storeName, String coverageName, File geotiff)
          Upload and publish a GeoTIFF image.
 boolean publishGeoTIFF(String workspace, String storeName, String resourceName, File geotiff, String srs, GSResourceEncoder.ProjectionPolicy policy, String defaultStyle)
          Deprecated. use the former method with bbox set to null.
 boolean publishGeoTIFF(String workspace, String storeName, String coverageName, File geotiff, String srs, GSResourceEncoder.ProjectionPolicy policy, String defaultStyle, double[] bbox)
          Upload and publish a GeoTIFF image.
 boolean publishImageMosaic(String workspace, String storeName, File zipFile)
          Publish imagemosaic as zip file.
 boolean publishImageMosaic(String workspace, String storeName, File zipFile, GeoServerRESTPublisher.ParameterConfigure configure, org.apache.commons.httpclient.NameValuePair... params)
          Publish imagemosaic as zip file.
 boolean publishShp(String workspace, String storeName, org.apache.commons.httpclient.NameValuePair[] storeParams, String datasetName, GeoServerRESTPublisher.UploadMethod method, URI shapefile, String srs, GSResourceEncoder.ProjectionPolicy policy, String defaultStyle)
          Deprecated. use publishShp(String, String, NameValuePair[], String, UploadMethod, URI, String, String) instead as the behaviour of this method is misleading as it allows you to use wrong ProjectionPolicy values.
 boolean publishShp(String workspace, String storeName, org.apache.commons.httpclient.NameValuePair[] storeParams, String datasetName, GeoServerRESTPublisher.UploadMethod method, URI shapefile, String srs, String defaultStyle)
          Publish a shapefile.
 boolean publishShp(String workspace, String storeName, org.apache.commons.httpclient.NameValuePair[] storeParams, String datasetName, GeoServerRESTPublisher.UploadMethod method, URI shapefile, String srs, String nativeCRS, GSResourceEncoder.ProjectionPolicy policy, String defaultStyle)
          Publish a shapefile.
 boolean publishShp(String workspace, String storename, String datasetname, File zipFile)
          Upload an publish a local shapefile.
 boolean publishShp(String workspace, String storename, String layername, File zipFile, String srs)
          Publish a zipped shapefile forcing the srs to the one provided.
 boolean publishShp(String workspace, String storename, String layername, File zipFile, String srs, org.apache.commons.httpclient.NameValuePair... params)
          Publish a zipped shapefile.
 boolean publishShp(String workspace, String storename, String layerName, File zipFile, String srs, String defaultStyle)
          Publish a zipped shapefile.
 boolean publishShpCollection(String workspace, String storeName, URI resource)
          Publish a collection of shapefiles.
 boolean publishStyle(File sldFile)
          Store and publish a Style.
 boolean publishStyle(File sldFile, String name)
          Store and publish a Style, assigning it a name.
 boolean publishStyle(String sldBody)
          Store and publish a Style.
 boolean publishStyle(String sldBody, String name)
          Store and publish a Style, assigning it a name.
 boolean publishWorldImage(String workspace, String coveragestore, File zipFile)
          Publish a zipped worldimage file.
 boolean publishWorldImage(String workspace, String coveragestore, File zipFile, GeoServerRESTPublisher.ParameterConfigure configure, org.apache.commons.httpclient.NameValuePair... params)
          Publish a zipped worldimage file.
 boolean reload()
          Reload the target geoserver configuration
 boolean reloadStore(String workspace, String storeName, GeoServerRESTPublisher.StoreType storeType)
          /workspaces//datastores/.xml /workspaces//coveragestores/.xml
 boolean removeCoverageStore(String workspace, String storename)
          Deprecated. use removeCoverageStore(String, String, boolean)
 boolean removeCoverageStore(String workspace, String storename, boolean recurse)
          Remove a given CoverageStore in a given Workspace.
 boolean removeDatastore(String workspace, String storename)
          Deprecated. will be removed in next release use removeDatastore(String, String, boolean)
 boolean removeDatastore(String workspace, String storename, boolean recurse)
          Remove a given Datastore in a given Workspace.
 boolean removeLayer(String workspace, String layerName)
          remove a generic given layer from a given workspace
 boolean removeLayerGroup(String name)
          Remove a layer group.
 boolean removeLayerGroup(String workspace, String name)
          Remove a layer group.
 boolean removeNamespace(String prefix, boolean recurse)
          Remove a given Namespace.
 boolean removeStyle(String styleName)
          Remove a Style.
 boolean removeStyle(String styleName, boolean purge)
          Remove a Style.
 boolean removeWorkspace(String workspace)
          Deprecated. removeWorkspace(String, boolean)
 boolean removeWorkspace(String workspace, boolean recurse)
          Remove a given Workspace.
 boolean reset()
          Reset the target geoserver configuration
 String restore(String backupDir)
          Issues a GeoServer RESTORE.
protected  String sanitize(String s)
          Appends ".DUMMY" to any string containing a dot (sic).
 boolean unpublishCoverage(String workspace, String storename, String layerName)
          Remove the Coverage configuration from GeoServer.
 boolean unpublishFeatureType(String workspace, String storename, String layerName)
          Removes the featuretype and the associated layer.
 boolean updateNamespace(String prefix, URI uri)
          Update a Namespace URI.
 boolean updateStyle(File sldFile, String name)
          Update a Style.
 boolean updateStyle(String sldBody, String name)
          Update a Style.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CRS

public static final String DEFAULT_CRS
See Also:
Constant Field Values
Constructor Detail

GeoServerRESTPublisher

public GeoServerRESTPublisher(String restURL,
                              String username,
                              String password)
Creates a GeoServerRESTPublisher to connect against a GeoServer instance with the given URL and user credentials.

Parameters:
restURL - the base GeoServer URL (e.g.: http://localhost:8080/geoserver)
username - auth credential
password - auth credential
Method Detail

backup

public String backup(String backupDir)
              throws IllegalArgumentException
Issues a GeoServer BACKUP.

Won't include data, cached tiles, or logs. Use backup(String, boolean, boolean, boolean) to control these parameters.

Parameters:
backupDir - the target Backup Dir String.
Returns:
id of the backup.
Throws:
IllegalArgumentException - if the backupDir is null or empty

backup

public String backup(String backupDir,
                     boolean includedata,
                     boolean includegwc,
                     boolean includelog)
              throws IllegalArgumentException
Issues a GeoServer BACKUP.

Parameters:
backupDir - the target Backup Dir String.
includedata - whether or not include the data dir Boolean.
includegwc - whether or not include the geowebcache dir Boolean.
includelog - whether or not include the log dir Boolean.
Returns:
id of the backup.
Throws:
IllegalArgumentException - if the backupDir is null or empty.

restore

public String restore(String backupDir)
               throws IllegalArgumentException
Issues a GeoServer RESTORE.

Parameters:
backupDir - the source backup dir.
Returns:
id of the backup.
Throws:
IllegalArgumentException - if the backupDir is null or empty

createWorkspace

public boolean createWorkspace(String workspace)
Create a new Workspace.

GeoServer will automatically create an associated Namespace with the URI being "http://{workspaceName}". To specify a custom Namespace URI, use createWorkspace(String, URI).

Parameters:
workspace - The name of the new workspace.
Returns:
true if the workspace was created.

createWorkspace

public boolean createWorkspace(String name,
                               URI uri)
Create both a workspace and its associated namespace.

Note that this method is equivalent to createNamespace(java.lang.String, java.net.URI).

Parameters:
name - Name for the new workspace, which will be also its associated namespace prefix.
uri - Namespace URI. Cannot be empty.
Returns:
true if the Workspace and its associated namespace were successfully created.

createNamespace

public boolean createNamespace(String prefix,
                               URI uri)
Create a new Namespace. GeoServer will automatically create the corresponding Workspace. Prefix and URI are mandatory and cannot be empty. If a Namespace with the given prefix already exists, it won't be created.

Parameters:
prefix - The name of the new Namespace.
uri - The URI of the new Namespace.
Returns:
true if the Namespace was successfully created.
See Also:
GeoServer Documentation

updateNamespace

public boolean updateNamespace(String prefix,
                               URI uri)
Update a Namespace URI. Prefix and URI are mandatory and cannot be empty. A Namespace with the given prefix should exist.

Parameters:
prefix - The prefix of an existing Namespace.
uri - The new URI.
Returns:
true if the Namespace was successfully updated.

removeNamespace

public boolean removeNamespace(String prefix,
                               boolean recurse)
Remove a given Namespace. It will remove the associated Workspace as well.

Parameters:
prefix - The Namespace prefix
recurse - The recurse parameter is used to recursively delete all resources contained in the workspace associated with this Namespace. This includes data stores, coverage stores, feature types, etc... Allowable values for this parameter are true or false. The default (safer) value is false.
Returns:
true if the Namespace was successfully removed.

publishStyle

public boolean publishStyle(String sldBody)
Store and publish a Style.

Parameters:
sldBody - the full SLD document as a String.
Returns:
true if the operation completed successfully.

publishStyle

public boolean publishStyle(String sldBody,
                            String name)
                     throws IllegalArgumentException
Store and publish a Style, assigning it a name.

Parameters:
sldBody - the full SLD document as a String.
name - the Style name.
Returns:
true if the operation completed successfully.
Throws:
IllegalArgumentException - if the style body is null or empty.

publishStyle

public boolean publishStyle(File sldFile)
Store and publish a Style.

Parameters:
sldFile - the File containing the SLD document.
Returns:
true if the operation completed successfully.

publishStyle

public boolean publishStyle(File sldFile,
                            String name)
Store and publish a Style, assigning it a name.

Parameters:
sldFile - the File containing the SLD document.
name - the Style name.
Returns:
true if the operation completed successfully.

updateStyle

public boolean updateStyle(String sldBody,
                           String name)
                    throws IllegalArgumentException
Update a Style.

Parameters:
sldBody - the new SLD document as a String.
name - the Style name to update.
Returns:
true if the operation completed successfully.
Throws:
IllegalArgumentException - if the style body or name are null or empty.

updateStyle

public boolean updateStyle(File sldFile,
                           String name)
                    throws IllegalArgumentException
Update a Style.

Parameters:
sldFile - the File containing the SLD document.
name - the Style name.
Returns:
true if the operation completed successfully.
Throws:
IllegalArgumentException - if the sldFile file or name are null or name is empty.

removeStyle

public boolean removeStyle(String styleName,
                           boolean purge)
                    throws IllegalArgumentException
Remove a Style.

The Style will be unpublished, and (optionally) the SLD file will be removed.

Parameters:
styleName - the name of the Style to remove.
purge - remove the related SLD file from disk.
Returns:
true if the operation completed successfully.
Throws:
IllegalArgumentException - if styleName is null or empty.

removeStyle

public boolean removeStyle(String styleName)
Remove a Style.

The Style will be unpublished and the related SLD file will be removed.

Parameters:
styleName - the name of the Style to remove.
Returns:
true if the operation completed successfully.

createPostGISDatastore

public boolean createPostGISDatastore(String workspace,
                                      GSPostGISDatastoreEncoder datastoreEncoder)
Deprecated. Will be deleted in next version 1.5.x, use GeoServerRESTDatastoreManager instead.

Create a PostGIS datastore.

Parameters:
workspace - Name of the workspace to contain the database. This will also be the prefix of any layer names created from tables in the database.
datastoreEncoder - the set of parameters to be set to the datastore (including connection params).
Returns:
true if the PostGIS datastore has been successfully created, false otherwise

publishDBLayer

public boolean publishDBLayer(String workspace,
                              String storename,
                              String layername,
                              String srs,
                              String defaultStyle)
Deprecated. Will be removed in the next release.


publishDBLayer

public boolean publishDBLayer(String workspace,
                              String storename,
                              GSFeatureTypeEncoder fte,
                              GSLayerEncoder layerEncoder)
Publish and configure a new layer from an existing DataStore (v. gr. a layer from a DB table).

Parameters:
workspace - Workspace name where DataStore is.
storename - DataStore name.
fte - FeatureType configuration details using a GSFeatureTypeEncoder.
Returns:
true if layer is successfully created.

publishShp

public boolean publishShp(String workspace,
                          String storename,
                          String datasetname,
                          File zipFile)
                   throws FileNotFoundException,
                          IllegalArgumentException
Upload an publish a local shapefile.

The SRS will be set to EPSG:4326.

Parameters:
workspace - The workspace name.
storename - The store name.
layername - The layer name.
zipFile - The zipped file to publish.
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException - , IllegalArgumentException
IllegalArgumentException
See Also:
#publishShp(String, String, NameValuePair[], String, UploadMethod, URI, String, ProjectionPolicy, String)}

publishShp

public boolean publishShp(String workspace,
                          String storeName,
                          org.apache.commons.httpclient.NameValuePair[] storeParams,
                          String datasetName,
                          GeoServerRESTPublisher.UploadMethod method,
                          URI shapefile,
                          String srs,
                          String nativeCRS,
                          GSResourceEncoder.ProjectionPolicy policy,
                          String defaultStyle)
                   throws FileNotFoundException,
                          IllegalArgumentException
Publish a shapefile.

Parameters:
workspace - the name of the workspace to use
storename - the name of the store to create
storeParams - parameters to append to the url (can be null).
Accepted parameters are:
  • charset used to set the charset
layername - the name of the layer to configure
method - GeoServerRESTPublisher.UploadMethod
fileUri - the uri of the file containing the shapefile.It should be:
  • A zip file if 'method' is file
  • A shp file if 'method' is external
  • A zip file if 'method' is uri (UNTESTED)
srs - the SRS for this shapefile. It must be an ESPG code or GeoServer will choke.
nativeCRS - the nativeCRS for this shapefile. It can be an EPSG code (for GSResourceEncoder.ProjectionPolicy.NONE or a WKT for GSResourceEncoder.ProjectionPolicy.REPROJECT_TO_DECLARED.
policy - GSResourceEncoder.ProjectionPolicy
defaultStyle - the default style to set (can be null).
Returns:
true if success false otherwise
Throws:
FileNotFoundException - if file to upload is not found
IllegalArgumentException - if any of the mandatory arguments are null.

publishShp

public boolean publishShp(String workspace,
                          String storeName,
                          org.apache.commons.httpclient.NameValuePair[] storeParams,
                          String datasetName,
                          GeoServerRESTPublisher.UploadMethod method,
                          URI shapefile,
                          String srs,
                          GSResourceEncoder.ProjectionPolicy policy,
                          String defaultStyle)
                   throws FileNotFoundException,
                          IllegalArgumentException
Deprecated. use publishShp(String, String, NameValuePair[], String, UploadMethod, URI, String, String) instead as the behaviour of this method is misleading as it allows you to use wrong ProjectionPolicy values.

Publish a shapefile.

Parameters:
workspace - the name of the workspace to use
storename - the name of the store to create
storeParams - parameters to append to the url (can be null).
Accepted parameters are:
  • charset used to set the charset
layername - the name of the layer to configure
method - GeoServerRESTPublisher.UploadMethod
fileUri - the uri of the file containing the shapefile.It should be:
  • A zip file if 'method' is file
  • A shp file if 'method' is external
  • A zip file if 'method' is uri (UNTESTED)
srs - the SRS for this shapefile. It must be an ESPG code or GeoServer will choke. Notice that we can only use GSResourceEncoder.ProjectionPolicy.FORCE_DECLARED.
policy - GSResourceEncoder.ProjectionPolicy
defaultStyle - the default style to set (can be null).
Returns:
true if success false otherwise
Throws:
FileNotFoundException - if file to upload is not found
IllegalArgumentException - if any of the mandatory arguments are null.

publishShp

public boolean publishShp(String workspace,
                          String storeName,
                          org.apache.commons.httpclient.NameValuePair[] storeParams,
                          String datasetName,
                          GeoServerRESTPublisher.UploadMethod method,
                          URI shapefile,
                          String srs,
                          String defaultStyle)
                   throws FileNotFoundException,
                          IllegalArgumentException
Publish a shapefile.

Parameters:
workspace - the name of the workspace to use
storename - the name of the store to create
storeParams - parameters to append to the url (can be null).
Accepted parameters are:
  • charset used to set the charset
layername - the name of the layer to configure
method - GeoServerRESTPublisher.UploadMethod
fileUri - the uri of the file containing the shapefile.It should be:
  • A zip file if 'method' is file
  • A shp file if 'method' is external
  • A zip file if 'method' is uri (UNTESTED)
srs - the SRS for this shapefile. It must be an ESPG code or GeoServer will choke.
defaultStyle - the default style to set (can be null).
Returns:
true if success false otherwise
Throws:
FileNotFoundException - if file to upload is not found
IllegalArgumentException - if any of the mandatory arguments are null.

publishShp

public boolean publishShp(String workspace,
                          String storename,
                          String layerName,
                          File zipFile,
                          String srs,
                          String defaultStyle)
                   throws FileNotFoundException,
                          IllegalArgumentException
Publish a zipped shapefile.

Parameters:
workspace - the name of the workspace to use
storename - the name of the store to create
layerName - the name of the layer to configure
zipFile - The zipped file to publish
srs - the srs for this shapefile. It will be forced to use this one in GeoServer using GSResourceEncoder.ProjectionPolicy.FORCE_DECLARED.
defaultStyle - the default style to set (can be null).
Returns:
true if the operation completed successfully
Throws:
FileNotFoundException - if file to upload is not found
IllegalArgumentException - if any of the mandatory arguments are null.
See Also:
#publishShp(String, String, NameValuePair[], String, UploadMethod, URI, String, ProjectionPolicy, String)}

publishShp

public boolean publishShp(String workspace,
                          String storename,
                          String layername,
                          File zipFile,
                          String srs)
                   throws FileNotFoundException
Publish a zipped shapefile forcing the srs to the one provided.

Parameters:
workspace - the name of the workspace to use
storename - the name of the store to create
layername - the name of the layer to configure
zipFile - The zipped file to publish
srs - the CRS for this shapefile. It must be an EPSG CODE !
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException - if file to upload is not found
IllegalArgumentException - if any of the mandatory arguments are null.
See Also:
#publishShp(String, String, NameValuePair[], String, UploadMethod, URI, String, ProjectionPolicy, String)}

publishShp

public boolean publishShp(String workspace,
                          String storename,
                          String layername,
                          File zipFile,
                          String srs,
                          org.apache.commons.httpclient.NameValuePair... params)
                   throws FileNotFoundException,
                          IllegalArgumentException
Publish a zipped shapefile.

Parameters:
workspace - the name of the workspace to use
storename - the name of the store to create
layername - the name of the layer to configure
zipFile - the zip file containing the shapefile
srs - the shapefile srs. This must be an EPSG Codefor this code to work!
params - parameters to append to the url (can be null).
Accepted parameters are:
  • charset used to set the charset
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException - if file to upload is not found
IllegalArgumentException - if any of the mandatory arguments are null.
See Also:
#publishShp(String, String, NameValuePair[], String, UploadMethod, URI, String, ProjectionPolicy, String)}

publishShpCollection

public boolean publishShpCollection(String workspace,
                                    String storeName,
                                    URI resource)
                             throws FileNotFoundException
Publish a collection of shapefiles.

Will automatically create the store and publish each shapefile as a layer.

Parameters:
workspace - the name of the workspace to use
storeName - the name of the store to create
resource - the shapefile collection. It can be:
  • A path to a directory containing shapefiles in the server.
  • A local zip file containing shapefiles that will be uploaded.
  • A URL pointing to a shapefile collection in the wild web (not tested).
Returns:
true if publication successful.
Throws:
FileNotFoundException - if the specified zip file does not exist.

publishGeoTIFF

public boolean publishGeoTIFF(String workspace,
                              String storeName,
                              File geotiff)
                       throws FileNotFoundException
Upload and publish a GeoTIFF image.

Parameters:
workspace - Workspace to use
storeName - The store name to be used or created.
geotiff - The GeoTIFF file.
Returns:
true if success.
Throws:
FileNotFoundException - if GeoTIFF file does not exist.

publishGeoTIFF

public boolean publishGeoTIFF(String workspace,
                              String storeName,
                              String coverageName,
                              File geotiff)
                       throws FileNotFoundException,
                              IllegalArgumentException
Upload and publish a GeoTIFF image.

Parameters:
workspace - Workspace to use
storeName - Name of the coveragestore (if null the file name will be used)
coverageName - the name of the coverage (if null the file name will be used)
geotiff - file to upload
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException - if file does not exists
IllegalArgumentException - if workspace or geotiff are null

publishGeoTIFF

public boolean publishGeoTIFF(String workspace,
                              String storeName,
                              String resourceName,
                              File geotiff,
                              String srs,
                              GSResourceEncoder.ProjectionPolicy policy,
                              String defaultStyle)
                       throws FileNotFoundException,
                              IllegalArgumentException
Deprecated. use the former method with bbox set to null.

Same as #publishGeoTIFF(String, String, String, File, String, ProjectionPolicy, String, double[]) but without the last parameter (bbox). Kept here for backwards compatibility.

Throws:
FileNotFoundException
IllegalArgumentException

publishGeoTIFF

public boolean publishGeoTIFF(String workspace,
                              String storeName,
                              String coverageName,
                              File geotiff,
                              String srs,
                              GSResourceEncoder.ProjectionPolicy policy,
                              String defaultStyle,
                              double[] bbox)
                       throws FileNotFoundException,
                              IllegalArgumentException
Upload and publish a GeoTIFF image.

Parameters:
workspace - Workspace to use
storeName - Name of the coveragestore (if null the file name will be used)
coverageName - the name of the coverage (if null the file name will be used)
geotiff - file to upload
srs - the native CRS
policy - projection policy. See GSResourceEncoder.ProjectionPolicy.
defaultStyle - the default style to apply.
bbox - An array of 4 doubles indicating envelope in EPSG:4326. Order is [Xmin, Ymin, Xmax, Ymax].
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException - if file does not exists
IllegalArgumentException - if workspace or geotiff are null

publishExternalGeoTIFF

public boolean publishExternalGeoTIFF(String workspace,
                                      String storeName,
                                      File geotiff,
                                      String coverageName,
                                      String srs,
                                      GSResourceEncoder.ProjectionPolicy policy,
                                      String defaultStyle)
                               throws FileNotFoundException,
                                      IllegalArgumentException
Publish a GeoTiff already in a filesystem readable by GeoServer.

Parameters:
workspace - an existing workspace
storeName - the coverageStore to be created
geotiff - the geoTiff to be published
srs - the native CRS
policy - projection policy. See GSResourceEncoder.ProjectionPolicy.
defaultStyle - the default style to apply.
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException - if file does not exists
IllegalArgumentException - if any of the mandatory parameters are null.

publishExternalGeoTIFF

public RESTCoverageStore publishExternalGeoTIFF(String workspace,
                                                String storeName,
                                                File geotiff,
                                                GSCoverageEncoder coverageEncoder,
                                                GSLayerEncoder layerEncoder)
                                         throws IllegalArgumentException,
                                                FileNotFoundException
Publish a GeoTiff already in a filesystem readable by GeoServer.

Parameters:
workspace - an existing workspace
storeName - the coverageStore to be created
geotiff - the geoTiff to be published
coverageEncoder - coverage details. See GSCoverageEncoder.
layerEncoder - layer details, See GSLayerEncoder.
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException - if file does not exists
IllegalArgumentException - if any of the mandatory parameters are null.

publishWorldImage

public boolean publishWorldImage(String workspace,
                                 String coveragestore,
                                 File zipFile)
                          throws FileNotFoundException
Publish a zipped worldimage file. It is assumed that the the zip-file contain the *.prj to set the srs.

Parameters:
workspace - Workspace to use
coveragestore - Name of the coveragestore
zipFile - zip file to upload
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException

publishWorldImage

public boolean publishWorldImage(String workspace,
                                 String coveragestore,
                                 File zipFile,
                                 GeoServerRESTPublisher.ParameterConfigure configure,
                                 org.apache.commons.httpclient.NameValuePair... params)
                          throws FileNotFoundException
Publish a zipped worldimage file. It is assumed that the the zip-file contain the *.prj to set the srs.

Parameters:
workspace - Workspace to use
coveragestore - Name of the coveragestore
zipFile - zip file to upload
configure - Configure parameter. See GeoServerRESTPublisher.ParameterConfigure. It can be null.
params - parameters to append to the url (can be null).
Accepted parameters are:
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException

publishImageMosaic

public boolean publishImageMosaic(String workspace,
                                  String storeName,
                                  File zipFile)
                           throws FileNotFoundException
Publish imagemosaic as zip file.

Parameters:
workspace - Workspace to use
storeName - Name of the coveragestore
zipFile - file to upload
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException

publishImageMosaic

public boolean publishImageMosaic(String workspace,
                                  String storeName,
                                  File zipFile,
                                  GeoServerRESTPublisher.ParameterConfigure configure,
                                  org.apache.commons.httpclient.NameValuePair... params)
                           throws FileNotFoundException
Publish imagemosaic as zip file.

Parameters:
workspace - Workspace to use
storeName - Name of the coveragestore
zipFile - file to upload
configure - Configure parameter. See GeoServerRESTPublisher.ParameterConfigure. It can be null.
params - parameters to append to the url (can be null).
Accepted parameters are:
  • coverageName=name coverageName parameter to append. Only works if configure is not set to ParameterConfigure.NONE.
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException

createExternaMosaicDatastore

public RESTCoverageStore createExternaMosaicDatastore(String workspace,
                                                      String storeName,
                                                      File mosaicDir,
                                                      GeoServerRESTPublisher.ParameterConfigure configure,
                                                      GeoServerRESTPublisher.ParameterUpdate update)
                                               throws FileNotFoundException
Publish a Mosaic from a filesystem currently readable by GeoServer.

Parameters:
workspace - an existing workspace
storeName - the name of the coverageStore to be created
mosaicDir - the directory where the raster images are located
configure - a specify if a coverage should be configured
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException

publishExternalMosaic

public boolean publishExternalMosaic(String workspace,
                                     String storeName,
                                     File mosaicDir,
                                     String srs,
                                     String defaultStyle)
                              throws FileNotFoundException
Publish a Mosaic already in a filesystem readable by GeoServer.

Parameters:
workspace - an existing workspace
storeName - the name of the coverageStore to be created
mosaicDir - the directory where the raster images are located
srs - the coverage declared SRS
defaultStyle - may be null
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException

createExternalMosaic

public boolean createExternalMosaic(String workspace,
                                    String storeName,
                                    File mosaicDir,
                                    GSCoverageEncoder coverageEncoder,
                                    GSLayerEncoder layerEncoder)
                             throws FileNotFoundException
Deprecated. use publishExternalMosaic(String, String, File, GSCoverageEncoder, GSLayerEncoder)

Throws:
FileNotFoundException

publishExternalMosaic

public boolean publishExternalMosaic(String workspace,
                                     String storeName,
                                     File mosaicDir,
                                     GSCoverageEncoder coverageEncoder,
                                     GSLayerEncoder layerEncoder)
                              throws FileNotFoundException,
                                     IllegalArgumentException
Publish a Mosaic already in a filesystem readable by GeoServer.

Parameters:
workspace - an existing workspace
storeName - the name of the coverageStore to be created
mosaicDir - the directory where the raster images are located
coverageEncoder - the set of parameters to be set to the coverage (bbox, srs, ...)
layerEncoder - the set of parameters to be set to the layer (defaultstyle, wmspath, ...)
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException
IllegalArgumentException

unpublishCoverage

public boolean unpublishCoverage(String workspace,
                                 String storename,
                                 String layerName)
Remove the Coverage configuration from GeoServer.

First, the associated layer is removed, then the Coverage configuration itself.

CHECKME Maybe the coveragestore has to be removed as well.

Returns:
true if the operation completed successfully.

unpublishFeatureType

public boolean unpublishFeatureType(String workspace,
                                    String storename,
                                    String layerName)
Removes the featuretype and the associated layer.

You may also want to remove the datastore.

Returns:
true if the operation completed successfully.

removeDatastore

public boolean removeDatastore(String workspace,
                               String storename)
Deprecated. will be removed in next release use removeDatastore(String, String, boolean)

Remove recursively a given Datastore in a given Workspace.

Parameters:
workspace - The name of the workspace
storename - The name of the Datastore to remove.
Returns:
true if the datastore was successfully removed.

removeDatastore

public boolean removeDatastore(String workspace,
                               String storename,
                               boolean recurse)
                        throws IllegalArgumentException
Remove a given Datastore in a given Workspace.

Parameters:
workspace - The name of the workspace
storename - The name of the Datastore to remove.
recurse - if remove should be performed recursively
Returns:
true if the datastore was successfully removed.
Throws:
IllegalArgumentException - if workspace or storename are null or empty

removeCoverageStore

public boolean removeCoverageStore(String workspace,
                                   String storename)
Deprecated. use removeCoverageStore(String, String, boolean)

Remove recursively a given CoverageStore in a given Workspace.

Parameters:
workspace - The name of the workspace
storename - The name of the CoverageStore to remove.
Returns:
true if the CoverageStore was successfully removed.

removeCoverageStore

public boolean removeCoverageStore(String workspace,
                                   String storename,
                                   boolean recurse)
                            throws IllegalArgumentException
Remove a given CoverageStore in a given Workspace.

Parameters:
workspace - The name of the workspace
storename - The name of the CoverageStore to remove.
recurse - if remove should be performed recursively
Returns:
true if the CoverageStore was successfully removed.
Throws:
IllegalArgumentException

removeWorkspace

public boolean removeWorkspace(String workspace)
Deprecated. removeWorkspace(String, boolean)

Remove the workspace given Workspace using default parameters

Parameters:
workspace - the workspace to remove
Returns:
true if success, false otherwise
See Also:
GeoServerRESTPublisher#removeWorkspace(String, boolean)}

removeWorkspace

public boolean removeWorkspace(String workspace,
                               boolean recurse)
                        throws IllegalArgumentException
Remove a given Workspace.

Parameters:
workspace - The name of the workspace
recurse - The recurse parameter is used to recursively delete all resources contained by the specified workspace. This includes data stores, coverage stores, feature types, etc... Allowable values for this parameter are true or false. The default value is false.
Returns:
true if the WorkSpace was successfully removed.
Throws:
IllegalArgumentException

removeLayerGroup

public boolean removeLayerGroup(String workspace,
                                String name)
Remove a layer group.

Parameters:
workspace - the layer group workspace.
name - the layer group name.
Returns:
true if succeeded.

removeLayerGroup

public boolean removeLayerGroup(String name)
Remove a layer group.

Parameters:
name - the layer group name.
Returns:
true if succeeded.

removeLayer

public boolean removeLayer(String workspace,
                           String layerName)
remove a generic given layer from a given workspace

Parameters:
workspace -
layerName -
Returns:
true if success

reloadStore

public boolean reloadStore(String workspace,
                           String storeName,
                           GeoServerRESTPublisher.StoreType storeType)
                    throws IllegalArgumentException,
                           MalformedURLException
/workspaces//datastores/.xml /workspaces//coveragestores/.xml

Parameters:
workspace -
storeName -
mosaicDir -
Returns:
true if successfully reloaded
Throws:
FileNotFoundException
IllegalArgumentException
MalformedURLException

reload

public boolean reload()
Reload the target geoserver configuration

Returns:
true if success
See Also:
GeoServer REST Config API

reset

public boolean reset()
Reset the target geoserver configuration

Returns:
true if success
See Also:
GeoServer REST Config API

configureLayer

public boolean configureLayer(String workspace,
                              String resourceName,
                              GSLayerEncoder layer)
                       throws IllegalArgumentException
Allows to configure some layer attributes such and DefaultStyle

Parameters:
workspace -
resourceName - the name of the resource to use (featureStore or coverageStore name)
layer - the layer encoder used to configure the layer
Returns:
true if success
Throws:
IllegalArgumentException - if some arguments are null or empty

createLayerGroup

public boolean createLayerGroup(String name,
                                GSLayerGroupEncoder group)
Create a new LayerGroup using the specified encoder

Parameters:
name - name of the layer group
group - group encoder
Returns:
true if operation was successful

createLayerGroup

public boolean createLayerGroup(String workspace,
                                String name,
                                GSLayerGroupEncoder group)
Create a new LayerGroup using the specified encoder

Parameters:
workspace - name of the workspace
name - name of the layer group
group - group encoder
Returns:
true if operation was successful

configureLayerGroup

public boolean configureLayerGroup(String name,
                                   GSLayerGroupEncoder group)
Update a LayerGroup using the specified encoder

Parameters:
name - name of the layer group
group - group encoder
Returns:
true if operation was successful

configureLayerGroup

public boolean configureLayerGroup(String workspace,
                                   String name,
                                   GSLayerGroupEncoder group)
Update a LayerGroup using the specified encoder

Parameters:
workspace - name of the workspace
name - name of the layer group
group - group encoder
Returns:
true if operation was successful

configureCoverage

public boolean configureCoverage(GSCoverageEncoder ce,
                                 String wsname,
                                 String csname)
Configure an existent coverage in a given workspace and coverage store

Parameters:
ce - contains the coverage name to configure and the configuration to apply
wsname - the workspace to search for existent coverage
csname - the coverage store to search for existent coverage
Returns:
true if success

createCoverage

public boolean createCoverage(GSCoverageEncoder ce,
                              String wsname,
                              String csname)
Deprecated. use createCoverage(String, String, GSCoverageEncoder)


createCoverage

public boolean createCoverage(String wsname,
                              String storeName,
                              GSCoverageEncoder ce)
                       throws IllegalArgumentException
Create a new coverage in a given workspace and coverage store

Parameters:
wsname - the workspace to search for existent coverage
storeName - an existent store name to use as data source
ce - contains the coverage name to create and the configuration to apply
Returns:
true if success
Throws:
IllegalArgumentException - if arguments are null or empty

sanitize

protected String sanitize(String s)
Appends ".DUMMY" to any string containing a dot (sic).


encode

protected String encode(String s)
URL-encodes a String.

Parameters:
s - The original string.
Returns:
The encoded string.


Copyright © 2007-2013 GeoSolutions. All Rights Reserved.