Ported on the master branch: Fix issue #19. Adding charset support to pubblishShp().
This commit is contained in:
parent
395859124a
commit
64502efd0e
@ -40,7 +40,9 @@ import java.net.MalformedURLException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.NameValuePair;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.apache.log4j.Level;
|
import org.apache.log4j.Level;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@ -284,15 +286,64 @@ public class GeoServerRESTPublisher {
|
|||||||
* }
|
* }
|
||||||
* </PRE>
|
* </PRE>
|
||||||
*
|
*
|
||||||
|
* {@link #publishShp(String, String, String, File, String, NameValuePair...)}
|
||||||
|
*
|
||||||
* @return true if the operation completed successfully.
|
* @return true if the operation completed successfully.
|
||||||
*/
|
*/
|
||||||
public boolean publishShp(String workspace, String storename,
|
public boolean publishShp(String workspace, String storename,
|
||||||
String layername, File zipFile, String srs)
|
String layername, File zipFile, String srs)
|
||||||
throws FileNotFoundException {
|
throws FileNotFoundException {
|
||||||
|
publishShp(workspace, storename, layername, zipFile, srs, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Publish a zipped shapefile.<br>
|
||||||
|
*
|
||||||
|
* 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).<br>
|
||||||
|
* Accepted parameters are:<br>
|
||||||
|
* <ul>
|
||||||
|
* <li><b>charset</b> used to set the charset</li>
|
||||||
|
* </ul>
|
||||||
|
* @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
|
// build full URL
|
||||||
StringBuilder sbUrl = new StringBuilder(restURL)
|
StringBuilder sbUrl = new StringBuilder(restURL)
|
||||||
.append("/rest/workspaces/").append(workspace)
|
.append("/rest/workspaces/").append(workspace)
|
||||||
.append("/datastores/").append(storename).append("/file.shp?");
|
.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) {
|
// if (workspace != null) {
|
||||||
// sbUrl.append("namespace=").append(workspace);
|
// sbUrl.append("namespace=").append(workspace);
|
||||||
// }
|
// }
|
||||||
@ -450,7 +501,8 @@ public class GeoServerRESTPublisher {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides the default toString method printing a toLowerCase
|
* 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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
@ -602,14 +654,16 @@ public class GeoServerRESTPublisher {
|
|||||||
public RESTCoverageStore createExternaMosaicDatastore(String workspace,
|
public RESTCoverageStore createExternaMosaicDatastore(String workspace,
|
||||||
String storeName, File mosaicDir, ParameterConfigure configure,
|
String storeName, File mosaicDir, ParameterConfigure configure,
|
||||||
ParameterUpdate update) throws FileNotFoundException {
|
ParameterUpdate update) throws FileNotFoundException {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Carlo (23 Nov 2011):
|
* Carlo (23 Nov 2011): commented out since this directory should be
|
||||||
* commented out since this directory should be readable by targhet GeoServer
|
* readable by targhet GeoServer not the calling client!
|
||||||
* not the calling client!
|
|
||||||
*/
|
*/
|
||||||
if (!mosaicDir.isDirectory()) {
|
if (!mosaicDir.isDirectory()) {
|
||||||
if (LOGGER.isEnabledFor(Level.WARN))
|
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
|
String sUrl = restURL + "/rest/workspaces/" + workspace
|
||||||
@ -1376,7 +1430,7 @@ public class GeoServerRESTPublisher {
|
|||||||
* name)
|
* name)
|
||||||
* @return true if success
|
* @return true if success
|
||||||
* @deprecated use {@link configureCoverage(final GSCoverageEncoder ce,
|
* @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,
|
protected boolean configureCoverage(final GSCoverageEncoder ce,
|
||||||
final String wsname, final String csname, String cname) {
|
final String wsname, final String csname, String cname) {
|
||||||
|
|||||||
@ -34,6 +34,7 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.NameValuePair;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
@ -250,6 +251,46 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
|
|||||||
assertFalse(reader.existsStyle(styleName));
|
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 {
|
public void testPublishDeleteStyleFile() throws FileNotFoundException, IOException {
|
||||||
if (!enabled()) {
|
if (!enabled()) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user