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 data.

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

Author:
ETj (etj at geo-solutions.it)

Nested Class Summary
static class GeoServerRESTPublisher.ParameterConfigure
          The configure parameter is used to control how the data store is configured upon file upload.
static class GeoServerRESTPublisher.ParameterUpdate
          The update parameter is used to control 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.
 
Constructor Summary
GeoServerRESTPublisher(String restURL, String username, String password)
          Creates a GeoServerRESTPublisher for a given GeoServer instance with the given auth credentials.
 
Method Summary
 boolean configureCoverage(GSCoverageEncoder ce, String wsname, String csname)
          Configure an existent coverage in a given workspace and coverage store
protected  boolean configureCoverage(GSCoverageEncoder ce, String wsname, String csname, String cname)
          Deprecated. use configureCoverage(final GSCoverageEncoder ce, final String wsname, final String csname)
 RESTCoverageStore configureExternaMosaicDatastore(String workspace, String storeName, File mosaicDir)
          Deprecated. provided for backward compatibility use createExternaMosaicDatastore(String workspace, String storeName, File mosaicDir, CoverageConfigure configure)
 boolean configureLayer(GSLayerEncoder layer, String layerName)
          Deprecated. please use configureLayer(String workspace, String layerName, GSLayerEncoder layer)
 boolean configureLayer(String workspace, String layerName, GSLayerEncoder layer)
          Allows to configure some layer attributes such and DefaultStyle TODO WmsPath
 boolean createCoverage(GSCoverageEncoder ce, String wsname, String csname)
          Create a new coverage in a given workspace and coverage store
 boolean createExternalMosaic(String workspace, String storeName, File mosaicDir, GSCoverageEncoder coverageEncoder, GSLayerEncoder layerEncoder)
          Publish a Mosaic already in a filesystem readable by GeoServer.
 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 createPostGISDatastore(String workspace, GSPostGISDatastoreEncoder datastoreEncoder)
          Create a PostGIS datastore.
 boolean createWorkspace(String workspace)
          Create a new Workspace
protected  String encode(String s)
           
 boolean publishDBLayer(String workspace, String storename, GSFeatureTypeEncoder fte, GSLayerEncoder layerEncoder)
          Publish a table in a PostGis store as a new layer.
 boolean publishDBLayer(String workspace, String storename, String layername, String srs, String defaultStyle)
          Deprecated. use publishDBLayer(final String workspace, final String storename, final GSFeatureTypeEncoder fte, final GSLayerEncoder layerEncoder)
 RESTCoverageStore publishExternalGeoTIFF(String workspace, String storeName, File geotiff, String srs, String defaultStyle)
          Publish a GeoTiff already in a filesystem readable by GeoServer.
 RESTCoverageStore publishExternalMosaic(String workspace, String storeName, File mosaicDir, GSCoverageEncoder coverageEncoder, GSLayerEncoder layerEncoder)
          Deprecated. this is keep only for backward compatibility use createExternalMosaic and getCoverageStore separately
 RESTCoverageStore 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)
          Deprecated. UNTESTED
 boolean publishShp(String workspace, String storename, String layername, File zipFile)
          Publish a zipped shapefile.
 boolean publishShp(String workspace, String storename, String layername, File zipFile, String srs)
          Publish a zipped shapefile.
 boolean publishShp(String workspace, String storename, String layername, File zipFile, String srs, org.apache.commons.httpclient.NameValuePair... params)
          Publish a zipped shapefile.
http://docs.geoserver.org/stable/en/user /restconfig/rest-config-examples/rest- config-examples-curl.html#uploading-a-shapefile
 boolean publishShp(String workspace, String storename, String layerName, File zipFile, String nativeCrs, String defaultStyle)
          Publish a zipped shapefile.
 boolean publishStyle(File sldFile)
          Store and publish an SLD.
 boolean publishStyle(File sldFile, String name)
          Store and publish an SLD, assigning it a name.
 boolean publishStyle(String sldBody)
          Store and publish an SLD.
 boolean reload()
          reload the target geoserver configuration
 boolean removeCoverageStore(String workspace, String storename)
          Remove recursively a given CoverageStore in a given Workspace.
 boolean removeCoverageStore(String workspace, String storename, boolean recurse)
          Remove a given CoverageStore in a given Workspace.
 boolean removeDatastore(String workspace, String storename)
          Remove recursively a given Datastore in a given Workspace.
 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)
           
 boolean removeStyle(String styleName)
          Remove a Style.
 boolean removeWorkspace(String workspace)
          Remove a given Workspace.
 boolean reset()
          reset the target geoserver configuration
protected  String sanitize(String s)
           
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeoServerRESTPublisher

public GeoServerRESTPublisher(String restURL,
                              String username,
                              String password)
Creates a GeoServerRESTPublisher for a given GeoServer instance with the given auth credentials.

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

createWorkspace

public boolean createWorkspace(String workspace)
Create a new Workspace

Parameters:
workspace - The name of the new workspace.

This is the equivalent call with cUrl:

 curl -u admin:geoserver -XPOST \
      -H 'Content-type: text/xml' \
      -d "<workspace><name>$WORKSPACE</name></workspace>" \
      http://$GSIP:$GSPORT/$SERVLET/rest/workspaces
 
 

publishStyle

public boolean publishStyle(String sldBody)
Store and publish an SLD.

This is the equivalent call with cUrl:

 curl -u admin:geoserver -XPOST \
      -H 'Content-type: application/vnd.ogc.sld+xml' \
      -d @$FULLSLD \
      http://$GSIP:$GSPORT/$SERVLET/rest/styles
 

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

publishStyle

public boolean publishStyle(File sldFile)
Store and publish an SLD.

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 an SLD, assigning it a name.

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

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)
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

publishShp

public boolean publishShp(String workspace,
                          String storename,
                          String layername,
                          File zipFile)
                   throws FileNotFoundException
Publish a zipped shapefile.
The CRS will be forced to EPSG:4326.

Parameters:
workspace -
storename -
layername -
zipFile -
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException

publishShp

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

Parameters:
workspace -
storename -
layerName -
nativeCrs -
defaultStyle - may be null
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException

publishShp

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

These are the equivalent calls with cUrl:

 curl -u admin:geoserver -XPUT -H 'Content-type: application/zip' \
       --data-binary @$ZIPFILE \
       http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/datastores/$STORENAME/file.shp
 
 curl -u admin:geoserver -XPOST -H 'Content-type: text/xml'  \
       -d "<featureType><name>$BARE</name><nativeCRS>EPSG:4326</nativeCRS><enabled>true</enabled></featureType>"  \
       http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/datastores/$STORENAME/featuretypes/$LAYERNAME
  
 
publishShp(String, String, String, File, String, NameValuePair...)

Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException

publishShp

public boolean publishShp(String workspace,
                          String storename,
                          String layername,
                          File zipFile,
                          String srs,
                          org.apache.commons.httpclient.NameValuePair... params)
                   throws FileNotFoundException
Publish a zipped shapefile.
http://docs.geoserver.org/stable/en/user /restconfig/rest-config-examples/rest- config-examples-curl.html#uploading-a-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 native CRS
params - parameters to append to the url (can be null).
Accepted parameters are:
  • charset used to set the charset
Returns:
true if success false otherwise
Throws:
FileNotFoundException

publishDBLayer

public boolean publishDBLayer(String workspace,
                              String storename,
                              String layername,
                              String srs,
                              String defaultStyle)
Deprecated. use publishDBLayer(final String workspace, final String storename, final GSFeatureTypeEncoder fte, final GSLayerEncoder layerEncoder)

Parameters:
workspace -
storename -
layername -
srs -
defaultStyle -
Returns:

publishDBLayer

public boolean publishDBLayer(String workspace,
                              String storename,
                              GSFeatureTypeEncoder fte,
                              GSLayerEncoder layerEncoder)
Publish a table in a PostGis store as a new layer.

This is the equivalent call with cUrl:

 curl -u admin:geoserver -XPOST -H 'Content-type: text/xml' \
      -d "<featureType><name>easia_gaul_1_aggr</name><nativeCRS>EPSG:4326</nativeCRS><enabled>true</enabled></featureType>" \
      http://localhost:8080/geoserver/rest/workspaces/it.geosolutions/datastores/pg_kids/featuretypes
 
 
and a PUT to
restURL + "/rest/layers/" workspace + : + layerName

Parameters:
workspace -
storename -
fte - GSFeatureTypeEncoder encoding creating FeatureType
Returns:
true if layer is successfully created

publishGeoTIFF

public boolean publishGeoTIFF(String workspace,
                              String storeName,
                              File geotiff)
                       throws FileNotFoundException
Deprecated. UNTESTED

Publish a GeoTiff.

This is the equivalent call with cUrl:

 curl -u admin:geoserver -XPUT -H 'Content-type: text' -d "file:$FULLPATH" \
       http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/coveragestores/$STORENAME/external.geotiff
  
 

Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException

publishExternalGeoTIFF

public RESTCoverageStore publishExternalGeoTIFF(String workspace,
                                                String storeName,
                                                File geotiff,
                                                String srs,
                                                String defaultStyle)
                                         throws 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
Returns:
a PublishedCoverage, or null on errors
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.

Sample cUrl usage:
<> curl -u admin:geoserver -XPUT -H 'Content-type: text' -d "file:$ABSPORTDIR" http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/coveragestores/$BAREDIR/external.imagemosaic

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

configureExternaMosaicDatastore

public RESTCoverageStore configureExternaMosaicDatastore(String workspace,
                                                         String storeName,
                                                         File mosaicDir)
                                                  throws FileNotFoundException
Deprecated. provided for backward compatibility use createExternaMosaicDatastore(String workspace, String storeName, File mosaicDir, CoverageConfigure configure)

Parameters:
workspace -
storeName -
mosaicDir -
Returns:
Throws:
FileNotFoundException

publishExternalMosaic

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

Sample cUrl usage:
curl -u admin:geoserver -XPUT -H 'Content-type: text' -d "file:$ABSPORTDIR" http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/coveragestores/$BAREDIR/external.imagemosaic

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

publishExternalMosaic

public RESTCoverageStore publishExternalMosaic(String workspace,
                                               String storeName,
                                               File mosaicDir,
                                               GSCoverageEncoder coverageEncoder,
                                               GSLayerEncoder layerEncoder)
                                        throws FileNotFoundException
Deprecated. this is keep only for backward compatibility use createExternalMosaic and getCoverageStore separately

Publish a Mosaic already in a filesystem readable by GeoServer.

Sample cUrl usage:
curl -u admin:geoserver -XPUT -H 'Content-type: text' -d "file:$ABSPORTDIR" http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/coveragestores/$BAREDIR/external.imagemosaic

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:
the created RESTCoverageStore
Throws:
FileNotFoundException

createExternalMosaic

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

Sample cUrl usage:
curl -u admin:geoserver -XPUT -H 'Content-type: text' -d "file:$ABSPORTDIR" http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/coveragestores/$BAREDIR/external.imagemosaic

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

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.

REST URL: http://localhost:8080/geoserver/rest/workspaces/it.geosolutions/coveragestores/gbRESTtestStore/coverages/resttestdem.xml

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)
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)
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.

removeCoverageStore

public boolean removeCoverageStore(String workspace,
                                   String storename)
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)
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.

removeWorkspace

public boolean removeWorkspace(String workspace)
Remove a given Workspace.

Parameters:
workspace - The name of the workspace
Returns:
true if the WorkSpace was successfully removed.

reload

public boolean reload()
reload the target geoserver configuration

Returns:
true if success
See Also:
://docs.geoserver.org/stable/en/user/restconfig/rest-config-api.html

reset

public boolean reset()
reset the target geoserver configuration

Returns:
true if success
See Also:
://docs.geoserver.org/stable/en/user/restconfig/rest-config-api.html

removeLayerGroup

public boolean removeLayerGroup(String name)

configureLayer

public boolean configureLayer(GSLayerEncoder layer,
                              String layerName)
Deprecated. please use configureLayer(String workspace, String layerName, GSLayerEncoder layer)


removeLayer

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

Parameters:
workspace -
layerName -
Returns:
true if success

configureLayer

public boolean configureLayer(String workspace,
                              String layerName,
                              GSLayerEncoder layer)
Allows to configure some layer attributes such and DefaultStyle TODO WmsPath


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:

createCoverage

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

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

configureCoverage

protected boolean configureCoverage(GSCoverageEncoder ce,
                                    String wsname,
                                    String csname,
                                    String cname)
Deprecated. use configureCoverage(final GSCoverageEncoder ce, final String wsname, final String csname)

Allows to configure some coverage's attributes

Parameters:
ce - Coverage encoder
wsname - workspace name
csname - coveragestore name
cname - coverage name (if != null will override the CoverageEncoder name)
Returns:
true if success

sanitize

protected String sanitize(String s)

encode

protected String encode(String s)


Copyright © 2007-2012 GeoSolutions. All Rights Reserved.