mirror of https://github.com/apache/druid.git
parent
b64dbbb5b5
commit
0b85c60869
|
@ -23,9 +23,9 @@ import com.google.common.base.Throwables;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Inject;
|
||||
import io.druid.indexing.overlord.TaskMaster;
|
||||
import io.druid.java.util.common.StringUtils;
|
||||
import io.druid.server.http.RedirectInfo;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -59,9 +59,15 @@ public class OverlordRedirectInfo implements RedirectInfo
|
|||
final String leader = taskMaster.getCurrentLeader();
|
||||
if (leader == null || leader.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
return new URI(scheme, leader, requestURI, queryString, null).toURL();
|
||||
}
|
||||
|
||||
String location = StringUtils.format("%s://%s%s", scheme, leader, requestURI);
|
||||
|
||||
if (queryString != null) {
|
||||
location = StringUtils.format("%s?%s", location, queryString);
|
||||
}
|
||||
|
||||
return new URL(location);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
|
|
|
@ -25,7 +25,9 @@ import org.junit.Assert;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public class OverlordRedirectInfoTest
|
||||
{
|
||||
|
@ -95,4 +97,24 @@ public class OverlordRedirectInfoTest
|
|||
Assert.assertEquals("http://localhost/request?foo=bar&x=y", url.toString());
|
||||
EasyMock.verify(taskMaster);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRedirectURLWithEncodedCharacter() throws UnsupportedEncodingException
|
||||
{
|
||||
String host = "localhost";
|
||||
String request = "/druid/indexer/v1/task/" + URLEncoder.encode(
|
||||
"index_hadoop_datasource_2017-07-12T07:43:01.495Z",
|
||||
"UTF-8"
|
||||
) + "/status";
|
||||
|
||||
EasyMock.expect(taskMaster.getCurrentLeader()).andReturn(host).anyTimes();
|
||||
EasyMock.replay(taskMaster);
|
||||
URL url = redirectInfo.getRedirectURL("http", null, request);
|
||||
Assert.assertEquals(
|
||||
"http://localhost/druid/indexer/v1/task/index_hadoop_datasource_2017-07-12T07%3A43%3A01.495Z/status",
|
||||
url.toString()
|
||||
);
|
||||
EasyMock.verify(taskMaster);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue