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)

Constructor Summary
GeoServerRESTPublisher(String restURL, String username, String password)
          Creates a GeoServerRESTPublisher for a given GeoServer instance with the given auth credentials.
 
Method Summary
protected  boolean configureCoverage(GSCoverageEncoder ce, String wsname, String csname, String cname)
          Allows to configure some coverage's attributes
 RESTCoverageStore configureExternaMosaicDatastore(String workspace, String storeName, File mosaicDir)
          Deprecated. work in progress
protected  boolean configureLayer(GSLayerEncoder layer, String layerName)
          Allows to configure some layer attributes such as WmsPath and DefaultStyle
 boolean createWorkspace(String workspace)
          Create a new Workspace
protected  String encode(String s)
           
 boolean publishDBLayer(String workspace, String storename, String layername, String srs, String defaultStyle)
          Publish a table in a PostGis store as a new layer.
 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, String srs, String defaultStyle)
          Deprecated. work in progress
 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 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 removeCoverageStore(String workspace, String storename)
          Remove a given CoverageStore in a given Workspace.
 boolean removeDatastore(String workspace, String storename)
          Remove a given Datastore in a given Workspace.
 boolean removeLayerGroup(String name)
           
 boolean removeStyle(String styleName)
          Remove a Style.
 boolean removeWorkspace(String workspace)
          Remove a given Workspace.
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.

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
 

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

publishDBLayer

public boolean publishDBLayer(String workspace,
                              String storename,
                              String layername,
                              String srs,
                              String defaultStyle)
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/" + layerName


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

configureExternaMosaicDatastore

public RESTCoverageStore configureExternaMosaicDatastore(String workspace,
                                                         String storeName,
                                                         File mosaicDir)
                                                  throws FileNotFoundException
Deprecated. work in progress

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
Returns:
true if the operation completed successfully.
Throws:
FileNotFoundException

publishExternalMosaic

public RESTCoverageStore publishExternalMosaic(String workspace,
                                               String storeName,
                                               File mosaicDir,
                                               String srs,
                                               String defaultStyle)
                                        throws FileNotFoundException
Deprecated. work in progress

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
defaultStyle - may be null
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 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.

removeCoverageStore

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

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.

removeLayerGroup

public boolean removeLayerGroup(String name)

configureLayer

protected boolean configureLayer(GSLayerEncoder layer,
                                 String layerName)
Allows to configure some layer attributes such as WmsPath and DefaultStyle


configureCoverage

protected boolean configureCoverage(GSCoverageEncoder ce,
                                    String wsname,
                                    String csname,
                                    String cname)
Allows to configure some coverage's attributes


sanitize

protected String sanitize(String s)

encode

protected String encode(String s)


Copyright © 2007-2011 GeoSolutions. All Rights Reserved.