diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java
index 0c71858..008c6ab 100644
--- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java
+++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java
@@ -40,7 +40,9 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Iterator;
+import java.util.List;
+import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.io.FilenameUtils;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
@@ -284,15 +286,64 @@ public class GeoServerRESTPublisher {
* }
*
*
+ * {@link #publishShp(String, String, String, File, String, NameValuePair...)}
+ *
* @return true if the operation completed successfully.
*/
public boolean publishShp(String workspace, String storename,
String layername, File zipFile, String srs)
throws FileNotFoundException {
+ publishShp(workspace, storename, layername, zipFile, srs, null);
+ }
+
+ /**
+ *
+ * Publish a zipped shapefile.
+ *
+ * http://docs.geoserver.org/stable/en/user
+ * /restconfig/rest-config-examples/rest-
+ * config-examples-curl.html#uploading-a-shapefile
+ *
+ * @param workspace
+ * the name of the workspace to use
+ * @param storename
+ * the name of the store to create
+ * @param layername
+ * the name of the layer to configure
+ * @param zipFile
+ * the zip file containing the shapefile
+ * @param srs
+ * the native CRS
+ * @param params
+ * parameters to append to the url (can be null).
+ * Accepted parameters are:
+ *
+ * - charset used to set the charset
+ *
+ * @return true if success false otherwise
+ * @throws FileNotFoundException
+ */
+ public boolean publishShp(String workspace, String storename,
+ String layername, File zipFile, String srs, NameValuePair... params)
+ throws FileNotFoundException {
// build full URL
StringBuilder sbUrl = new StringBuilder(restURL)
.append("/rest/workspaces/").append(workspace)
.append("/datastores/").append(storename).append("/file.shp?");
+
+ // append parameters
+ if (params != null) {
+ final int paramsSize = params.length;
+ if (paramsSize > 0) {
+ sbUrl.append(params[0].getName()).append("=")
+ .append(params[0].getValue());
+ for (int i = 1; i < paramsSize; i++) {
+ sbUrl.append("&").append(params[i].getName()).append("=")
+ .append(params[i].getValue());
+ }
+ }
+ }
+
// if (workspace != null) {
// sbUrl.append("namespace=").append(workspace);
// }
@@ -354,7 +405,7 @@ public class GeoServerRESTPublisher {
String layername, String srs, String defaultStyle) {
final GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
-
+
fte.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED);
fte.addKeyword("KEYWORD");
fte.addName(layername);
@@ -450,7 +501,8 @@ public class GeoServerRESTPublisher {
/**
* Overrides the default toString method printing a toLowerCase
- * representation of this Parameter which is suitable to build parameter in the rest URL
+ * representation of this Parameter which is suitable to build parameter
+ * in the rest URL
*/
@Override
public String toString() {
@@ -602,16 +654,18 @@ public class GeoServerRESTPublisher {
public RESTCoverageStore createExternaMosaicDatastore(String workspace,
String storeName, File mosaicDir, ParameterConfigure configure,
ParameterUpdate update) throws FileNotFoundException {
+
/*
- * Carlo (23 Nov 2011):
- * commented out since this directory should be readable by targhet GeoServer
- * not the calling client!
+ * Carlo (23 Nov 2011): commented out since this directory should be
+ * readable by targhet GeoServer not the calling client!
*/
if (!mosaicDir.isDirectory()) {
if (LOGGER.isEnabledFor(Level.WARN))
- LOGGER.warn("Directory '" + mosaicDir+ "' not exists locally. Continue: please check existance on the remote server.");
+ LOGGER.warn("Directory '"
+ + mosaicDir
+ + "' not exists locally. Continue: please check existance on the remote server.");
}
-
+
String sUrl = restURL + "/rest/workspaces/" + workspace
+ "/coveragestores/" + storeName
+ "/external.imagemosaic?configure=" + configure.toString()
@@ -1376,7 +1430,7 @@ public class GeoServerRESTPublisher {
* name)
* @return true if success
* @deprecated use {@link configureCoverage(final GSCoverageEncoder ce,
- final String wsname, final String csname)}
+ * final String wsname, final String csname)}
*/
protected boolean configureCoverage(final GSCoverageEncoder ce,
final String wsname, final String csname, String cname) {
diff --git a/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTPublisherTest.java b/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTPublisherTest.java
index 9bbecc9..64bc6bd 100644
--- a/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTPublisherTest.java
+++ b/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTPublisherTest.java
@@ -34,6 +34,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.jdom.Element;
@@ -250,6 +251,46 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
assertFalse(reader.existsStyle(styleName));
}
+ public void testPublishDeleteShapeZipWithParams() throws FileNotFoundException, IOException {
+ if (!enabled()) {
+ return;
+ }
+// Assume.assumeTrue(enabled);
+ deleteAllWorkspaces();
+ assertTrue(publisher.createWorkspace(DEFAULT_WS));
+
+ String storeName = "resttestshp";
+ String layerName = "cities";
+
+ File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
+
+ // known state?
+ cleanupTestFT(layerName, DEFAULT_WS, storeName);
+
+ // test insert
+ boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile,"EPSG:4326",new NameValuePair("charset","UTF-8"));
+ assertTrue("publish() failed", published);
+ assertTrue(existsLayer(layerName));
+
+ RESTLayer layer = reader.getLayer(layerName);
+
+ LOGGER.info("Layer style is " + layer.getDefaultStyle());
+
+ //test delete
+ boolean ok = publisher.unpublishFeatureType(DEFAULT_WS, storeName, layerName);
+ assertTrue("Unpublish() failed", ok);
+ assertFalse(existsLayer(layerName));
+
+ // remove also datastore
+ boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName);
+ assertTrue("removeDatastore() failed", dsRemoved);
+
+ }
+
+
+
+
+
public void testPublishDeleteStyleFile() throws FileNotFoundException, IOException {
if (!enabled()) {
return;