Skip to content

Commit c928664

Browse files
committed
Directory service should use HTTP temporary redirect (307)
1 parent 5c82997 commit c928664

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

pulsar-broker/src/test/java/com/yahoo/pulsar/discovery/service/web/DiscoveryServiceWebTest.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,12 @@ public void testRiderectUrlWithServerStarted() throws Exception {
9696
* verify : every time when vip receives a request: it redirects to above brokers sequentially and broker
9797
* returns appropriate response which must not be null.
9898
**/
99-
assertEquals("Cannot get the replication clusters for a non-global namespace", hitBrokerService(HttpMethod.POST, postRequestUrl, Lists.newArrayList("use")));
100-
assertEquals("Property does not exist", hitBrokerService(HttpMethod.PUT, putRequestUrl, new BundlesData(1)));
101-
assertEquals("Property does not exist", hitBrokerService(HttpMethod.GET, getRequestUrl, null));
102-
99+
100+
assertEquals(hitBrokerService(HttpMethod.POST, postRequestUrl, Lists.newArrayList("use")),
101+
"Cannot set replication on a non-global namespace");
102+
assertEquals(hitBrokerService(HttpMethod.PUT, putRequestUrl, new BundlesData(1)), "Property does not exist");
103+
assertEquals(hitBrokerService(HttpMethod.GET, getRequestUrl, null), "Property does not exist");
104+
103105
server.stop();
104106

105107
}
@@ -128,15 +130,15 @@ public String hitBrokerService(String method, String url, Object data) throws Js
128130
String serviceResponse = jsonObject.get("reason").getAsString();
129131
return serviceResponse;
130132
}
131-
133+
132134
static class DiscoveryZooKeeperClientFactoryImpl implements ZooKeeperClientFactory {
133-
static ZooKeeper zk;
134-
135-
@Override
136-
public CompletableFuture<ZooKeeper> create(String serverList, SessionType sessionType,
137-
int zkSessionTimeoutMillis) {
138-
return CompletableFuture.completedFuture(zk);
139-
}
135+
static ZooKeeper zk;
136+
137+
@Override
138+
public CompletableFuture<ZooKeeper> create(String serverList, SessionType sessionType,
139+
int zkSessionTimeoutMillis) {
140+
return CompletableFuture.completedFuture(zk);
141+
}
140142
}
141143

142144
}

pulsar-discovery-service/src/main/java/com/yahoo/pulsar/discovery/service/web/DiscoveryServiceServlet.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ private void redirect(HttpServletRequest request, HttpServletResponse response)
134134
if (log.isDebugEnabled()) {
135135
log.info("Redirecting to {}", location);
136136
}
137-
response.sendRedirect(location.toString());
137+
138+
response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
139+
response.setHeader("Location", location.toString());
138140
} catch (URISyntaxException e) {
139141
log.warn("No broker found in zookeeper {}", e.getMessage(), e);
140142
throw new RestException(Status.SERVICE_UNAVAILABLE, "Broker is not available");

0 commit comments

Comments
 (0)