Skip to content

Commit

Permalink
[GEOS-8771] REST: cannot harvest files unless the input has file:// p…
Browse files Browse the repository at this point in the history
…refix
  • Loading branch information
aaime committed Jun 5, 2018
1 parent 987c53a commit c418413
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/rest/src/main/java/org/geoserver/rest/util/RESTUtils.java
Expand Up @@ -11,6 +11,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URL;
import java.net.URLDecoder;
import java.util.HashMap;
Expand Down Expand Up @@ -41,6 +42,7 @@
import org.geoserver.platform.resource.Resources;
import org.geoserver.rest.RestException;
import org.geotools.util.logging.Logging;
import org.h2.util.New;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

Expand Down Expand Up @@ -188,22 +190,22 @@ public static org.geoserver.platform.resource.Resource handleURLUpload(
* @throws IOException
*/
public static org.geoserver.platform.resource.Resource handleEXTERNALUpload(HttpServletRequest request) throws IOException {
//get the URL for this file to upload
InputStream inStream = null;
URL fileURL ;
try {
inStream = request.getInputStream();
final String stringURL = IOUtils.getStringFromStream(inStream);
fileURL = new URL(stringURL);
} finally {
IOUtils.closeQuietly(inStream);
// get the URL for this file to upload
final String stringURL;
File inputFile;
try (InputStream inStream = request.getInputStream()) {
stringURL = IOUtils.getStringFromStream(inStream);
inputFile = new File(stringURL);
if (!inputFile.exists()) {
URL fileURL = new URL(stringURL);
inputFile = IOUtils.URLToFile(fileURL);
}
}

final File inputFile = IOUtils.URLToFile(fileURL);
if(inputFile == null || !inputFile.exists()) {
throw new RestException("Failed to locate the input file " + fileURL, HttpStatus.BAD_REQUEST);
throw new RestException("Failed to locate the input file " + stringURL, HttpStatus.BAD_REQUEST);
} else if(!inputFile.canRead()) {
throw new RestException("Input file is not readable, check filesystem permissions: " + fileURL,
throw new RestException("Input file is not readable, check filesystem permissions: " + stringURL,
HttpStatus.BAD_REQUEST);
}

Expand Down
Expand Up @@ -399,6 +399,23 @@ public void testHarvestSingle() throws Exception {
assertXpathEvaluatesTo("3", "count(//gf:watertemp)", dom);
assertXpathEvaluatesTo("1", "count(//gf:watertemp[gf:location = '" + file.getName() + "'])", dom);
}

@Test
public void testHarvestSingleSimplePath() throws Exception {
File file = movedFiles.get(0);
File target = new File(mosaic, file.getName());
assertTrue(file.renameTo(target));

String body = target.getCanonicalPath();
MockHttpServletResponse response = postAsServletResponse(RestBaseController.ROOT_PATH + "/workspaces/wcs/coveragestores/watertemp/external.imagemosaic",
body, "text/plain");
assertEquals(202, response.getStatus());

Document dom = getAsDOM( RestBaseController.ROOT_PATH + "/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules.xml");
// print(dom);
assertXpathEvaluatesTo("3", "count(//gf:watertemp)", dom);
assertXpathEvaluatesTo("1", "count(//gf:watertemp[gf:location = '" + file.getName() + "'])", dom);
}

@Test
public void testHarvestMulti() throws Exception {
Expand Down

0 comments on commit c418413

Please sign in to comment.