use of javax.servlet.http.HttpServletResponse in project druid by druid-io.
the class RedirectFilter method doFilter.
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request;
HttpServletResponse response;
try {
request = (HttpServletRequest) req;
response = (HttpServletResponse) res;
} catch (ClassCastException e) {
throw new ServletException("non-HTTP request or response");
}
if (redirectInfo.doLocal(request.getRequestURI())) {
chain.doFilter(request, response);
} else {
URL url = redirectInfo.getRedirectURL(request.getQueryString(), request.getRequestURI());
log.debug("Forwarding request to [%s]", url);
if (url == null) {
// We apparently have nothing to redirect to, so let's do a Service Unavailable
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
return;
}
response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
response.setHeader("Location", url.toString());
}
}
use of javax.servlet.http.HttpServletResponse in project druid by druid-io.
the class AsyncQueryForwardingServletTest method makeTestDeleteServer.
private static Server makeTestDeleteServer(int port, final CountDownLatch latch) {
Server server = new Server(port);
ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(new ServletHolder(new HttpServlet() {
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
latch.countDown();
resp.setStatus(200);
}
}), "/default/*");
server.setHandler(handler);
return server;
}
use of javax.servlet.http.HttpServletResponse in project che by eclipse.
the class DashboardRedirectionFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
if ("GET".equals(req.getMethod()) && !projectPattern.matcher(req.getRequestURI()).matches()) {
resp.sendRedirect("/dashboard/");
return;
}
chain.doFilter(request, response);
}
use of javax.servlet.http.HttpServletResponse in project ghostdriver by detro.
the class ElementFindingTest method findChildElements.
@Test
public void findChildElements() {
server.setHttpHandler("GET", new HttpRequestCallback() {
@Override
public void call(HttpServletRequest req, HttpServletResponse res) throws IOException {
res.getOutputStream().println("<div id=\"y-masthead\">" + "<input type=\"text\" name=\"t\" />" + "<input type=\"hidden\" name=\"h\" value=\"v\" />" + "</div>");
}
});
WebDriver d = getDriver();
d.get(server.getBaseUrl());
WebElement parent = d.findElement(By.id("y-masthead"));
List<WebElement> children = parent.findElements(By.tagName("input"));
assertEquals(2, children.size());
}
use of javax.servlet.http.HttpServletResponse in project ghostdriver by detro.
the class WindowHandlesTest method openPopupAndGetCurrentUrl.
@Test
public void openPopupAndGetCurrentUrl() throws InterruptedException {
server.setHttpHandler("GET", new HttpRequestCallback() {
@Override
public void call(HttpServletRequest req, HttpServletResponse res) throws IOException {
res.getOutputStream().println("<html>" + "<head>" + "<script language=\"javascript\" type=\"text/javascript\">\n" + "function openProjectPopup(url) {\n" + " var popWidth = 1024;\n" + " var leftX = (screen.width) ? (screen.width-popWidth)/2 : 0;\n" + " var height = screen.availHeight;\n" + " var win = window.open(url, \"projectPopup\", \"left=\"+leftX+\",top=0,width=\"+popWidth+\",height=\"+height+\",location=yes,menubar=no,resizable=yes,status=no,scrollbars=yes\");\n" + " win.location.href='http://www.jnto.go.jp/'; //put a link to a slow loading webpage here\n" + " win.focus();\n" + "}\n" + "</script>\n" + "</head>\n" + " <body>\n" + " <a href=\"popup.htm\" onclick=\"return openProjectPopup('popup.htm')\">Link to popup</a>" + " </body>\n" + "</html>");
}
});
// Load page
WebDriver d = getDriver();
d.get(server.getBaseUrl());
// Click on link that will cause popup to be created
d.findElement(By.xpath("//a")).click();
// Switch to new popup
String popupHandle = (String) d.getWindowHandles().toArray()[1];
d.switchTo().window(popupHandle);
assertTrue(d.getTitle().contains("Japan"));
}
Aggregations