Skip to content
Snippets Groups Projects

add ing ivalid url rejects with proper error

Merged Piotr Gawron requested to merge 1723-add-gene-mapping into devel_16.2.x
3 files
+ 58
0
Compare changes
  • Side-by-side
  • Inline
Files
3
package lcsb.mapviewer.api.genomics;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
@@ -13,6 +15,7 @@ import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
@@ -230,6 +233,19 @@ public class ReferenceGenomeController extends BaseController {
if (!url.toLowerCase().endsWith("bb")) {
throw new QueryException("Only big bed format files are supported but found: \"" + url + "\".");
}
if (url.startsWith("http")) {
try {
HttpURLConnection huc = (HttpURLConnection) new URL(url).openConnection();
huc.setRequestMethod("HEAD");
HttpStatus status = HttpStatus.valueOf(huc.getResponseCode());
if (status != HttpStatus.OK) {
throw new QueryException("Invalid url. Server returned: " + status.name() + " (" + status.value() + ").");
}
} catch (IOException e) {
throw new QueryException("Problem with processing url.", e);
}
}
referenceGenomeService.addReferenceGenomeGeneMapping(genome, name, url);
return new HashMap<>();
Loading