Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.google.common.annotations.VisibleForTesting;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -583,7 +585,7 @@ public String getRelativeDir(ConfVars c) {
}

public String getRelativeDir(String path) {
if (path != null && path.startsWith(File.separator) || isWindowsPath(path)) {
if (path != null && (path.startsWith(File.separator) || isWindowsPath(path) || isPathWithScheme(path))) {
return path;
} else {
return getString(ConfVars.ZEPPELIN_HOME) + File.separator + path;
Expand All @@ -602,6 +604,14 @@ public boolean isWindowsPath(String path){
return path.matches("^[A-Za-z]:\\\\.*");
}

public boolean isPathWithScheme(String path){
try {
return StringUtils.isNotBlank(new URI(path).getScheme());
} catch (URISyntaxException e) {
return false;
}
}

public boolean isAnonymousAllowed() {
if (anonymousAllowed == null) {
anonymousAllowed = this.getShiroPath().equals(StringUtils.EMPTY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
*/
package org.apache.zeppelin.conf;

import junit.framework.Assert;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -78,6 +79,30 @@ public void isWindowsPathTestFalse() throws ConfigurationException {
Assert.assertFalse(isIt);
}

@Test
public void isPathWithSchemeTestTrue() throws ConfigurationException {

ZeppelinConfiguration conf = new ZeppelinConfiguration(this.getClass().getResource("/zeppelin-site.xml"));
Boolean isIt = conf.isPathWithScheme("hdfs://hadoop.example.com/zeppelin/notebook");
Assert.assertTrue(isIt);
}

@Test
public void isPathWithSchemeTestFalse() throws ConfigurationException {

ZeppelinConfiguration conf = new ZeppelinConfiguration(this.getClass().getResource("/zeppelin-site.xml"));
Boolean isIt = conf.isPathWithScheme("~/test/file.xml");
Assert.assertFalse(isIt);
}

@Test
public void isPathWithInvalidSchemeTest() throws ConfigurationException {

ZeppelinConfiguration conf = new ZeppelinConfiguration(this.getClass().getResource("/zeppelin-site.xml"));
Boolean isIt = conf.isPathWithScheme("c:\\test\\file.txt");
Assert.assertFalse(isIt);
}

@Test
public void getNotebookDirTest() throws ConfigurationException {
ZeppelinConfiguration conf = new ZeppelinConfiguration(this.getClass().getResource("/zeppelin-site.xml"));
Expand Down