I am trying to create a URI redirect link. But, I simply cannot get the syntax right. I assume it's really easy, and that's why I can't find similarly asked questions. Either that, or it's not a typical user case. In either event, here is my method:
public void handle (final HttpExchange exchange) throws IOException {
try {
final InetSocketAddress redirectServerAddress = this.selectRedirectServerAddress(exchange.getRemoteAddress().getAddress());
final URI requestURI = exchange.getRequestURI();
// TODO: create the redirect URI
// I thought this would be most promising:
// URI redirectURI = new URI(http:redirectServerAddress, "/path/here", null)
URI redirectURI = null;
// send the exchanges's response headers using the code 307 (temp redirect) and zero as response length
exchange.getResponseHeaders().set("Location", redirectURI.toASCIIString());
exchange.sendResponseHeaders(307, 0);
Logger.getGlobal().log(Level.INFO, "Redirected request for \"{0}\" to \"{1}\".", new URI[] { requestURI, redirectURI });
} finally {
exchange.close();
}
}
I have tried various options, the one answer here looks promising, but I could not get it to work. Any help would be appreciated. Thanks!