Skip to content

Commit 776d812

Browse files
Issue 50861: Pass around properly encoded WebDav URLs (#320)
1 parent 58967e0 commit 776d812

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

jbrowse/src/org/labkey/jbrowse/model/JBrowseSession.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.labkey.jbrowse.JBrowseSchema;
3030

3131
import java.io.File;
32+
import java.net.URI;
3233
import java.nio.file.Path;
3334
import java.nio.file.Paths;
3435
import java.util.ArrayList;
@@ -361,12 +362,12 @@ public static String getAssemblyName(ReferenceGenome rg)
361362
public static JSONObject getIndexedFastaAdapter(ReferenceGenome rg)
362363
{
363364
ExpData d = ExperimentService.get().getExpData(rg.getFastaExpDataId());
364-
String url = d.getWebDavURL(FileContentService.PathType.full);
365+
URI url = d.getWebDavURL(FileContentService.PathType.full);
365366

366367
JSONObject ret = new JSONObject();
367368
ret.put("type", "IndexedFastaAdapter");
368369
ret.put("fastaLocation", new JSONObject(){{
369-
put("uri", url);
370+
put("uri", url.toString());
370371
}});
371372
ret.put("faiLocation", new JSONObject(){{
372373
put("uri", url + ".fai");
@@ -378,7 +379,7 @@ public static JSONObject getIndexedFastaAdapter(ReferenceGenome rg)
378379
public static JSONObject getBgZippedIndexedFastaAdapter(ReferenceGenome rg)
379380
{
380381
ExpData d = ExperimentService.get().getExpData(rg.getFastaExpDataId());
381-
String url = d.getWebDavURL(FileContentService.PathType.full);
382+
URI url = d.getWebDavURL(FileContentService.PathType.full);
382383

383384
JSONObject ret = new JSONObject();
384385
ret.put("type", "BgzipFastaAdapter");

jbrowse/src/org/labkey/jbrowse/model/JsonFile.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.labkey.api.util.JobRunner;
5151
import org.labkey.api.util.PageFlowUtil;
5252
import org.labkey.api.util.Path;
53+
import org.labkey.api.util.UnexpectedException;
5354
import org.labkey.api.view.UnauthorizedException;
5455
import org.labkey.jbrowse.JBrowseLuceneSearch;
5556
import org.labkey.jbrowse.JBrowseManager;
@@ -59,6 +60,8 @@
5960

6061
import java.io.File;
6162
import java.io.IOException;
63+
import java.net.URI;
64+
import java.net.URISyntaxException;
6265
import java.nio.file.Files;
6366
import java.sql.SQLException;
6467
import java.util.Arrays;
@@ -512,7 +515,7 @@ private JSONObject getVcfTrack(Logger log, ExpData targetFile, ReferenceGenome r
512515
put(JBrowseSession.getAssemblyName(rg));
513516
}});
514517

515-
String url = targetFile.getWebDavURL(FileContentService.PathType.full);
518+
URI url = targetFile.getWebDavURL(FileContentService.PathType.full);
516519
if (url == null)
517520
{
518521
log.info("Unable to create WebDav URL for JBrowse resource with path: " + targetFile.getFile());
@@ -522,7 +525,7 @@ private JSONObject getVcfTrack(Logger log, ExpData targetFile, ReferenceGenome r
522525
ret.put("adapter", new JSONObject(){{
523526
put("type", "ExtendedVariantAdapter");
524527
put("vcfGzLocation", new JSONObject(){{
525-
put("uri", url);
528+
put("uri", url.toString());
526529
}});
527530

528531
put("index", new JSONObject(){{
@@ -596,7 +599,7 @@ private JSONObject getBamOrCramTrack(Logger log, ExpData targetFile, ReferenceGe
596599
put(JBrowseSession.getAssemblyName(rg));
597600
}});
598601

599-
String url = targetFile.getWebDavURL(FileContentService.PathType.full);
602+
URI url = targetFile.getWebDavURL(FileContentService.PathType.full);
600603
if (url == null)
601604
{
602605
log.info("Unable to create WebDav URL for JBrowse resource with path: " + targetFile.getFile());
@@ -612,7 +615,7 @@ private JSONObject getBamOrCramTrack(Logger log, ExpData targetFile, ReferenceGe
612615
put("type", type);
613616
put("bamLocation", new JSONObject()
614617
{{
615-
put("uri", url);
618+
put("uri", url.toString());
616619
}});
617620

618621
put("index", new JSONObject()
@@ -667,7 +670,7 @@ private JSONObject getBigWigTrack(Logger log, ExpData targetFile, ReferenceGenom
667670
put(getCategory());
668671
}});
669672

670-
String url = targetFile.getWebDavURL(FileContentService.PathType.full);
673+
URI url = targetFile.getWebDavURL(FileContentService.PathType.full);
671674
if (url == null)
672675
{
673676
log.info("Unable to create WebDav URL for JBrowse resource with path: " + targetFile.getFile());
@@ -677,7 +680,7 @@ private JSONObject getBigWigTrack(Logger log, ExpData targetFile, ReferenceGenom
677680
ret.put("adapter", new JSONObject(){{
678681
put("type", "BigWigAdapter");
679682
put("bigWigLocation", new JSONObject(){{
680-
put("uri", url);
683+
put("uri", url.toString());
681684
put("locationType", "UriLocation");
682685
}});
683686
}});
@@ -747,7 +750,7 @@ private JSONObject getTabixTrack(User u, Logger log, ExpData targetFile, Referen
747750

748751
// if not gzipped, we need to process it:
749752
File gzipped = prepareResource(u, log, true, false);
750-
final String url;
753+
final URI url;
751754
if (!getExpData().getFile().equals(gzipped))
752755
{
753756
url = getWebDavURL(gzipped);
@@ -1192,7 +1195,7 @@ public File getExpectedLocationOfIndexFile(String extension, boolean throwIfNotF
11921195
return ret;
11931196
}
11941197

1195-
private String getWebDavURL(File input)
1198+
private URI getWebDavURL(File input)
11961199
{
11971200
java.nio.file.Path path = input.toPath();
11981201
if (getContainerObj() == null)
@@ -1221,7 +1224,14 @@ private String getWebDavURL(File input)
12211224
relPath = Path.parse(FilenameUtils.separatorsToUnix(relPath)).toString();
12221225
}
12231226

1224-
return AppProps.getInstance().getBaseServerUrl() + root.getWebdavURL() + relPath;
1227+
try
1228+
{
1229+
return new URI(AppProps.getInstance().getBaseServerUrl() + root.getWebdavURL() + relPath);
1230+
}
1231+
catch (URISyntaxException e)
1232+
{
1233+
throw UnexpectedException.wrap(e);
1234+
}
12251235
}
12261236

12271237
return null;

0 commit comments

Comments
 (0)