Search in sources :

Example 66 with HttpServletResponse

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());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) HttpServletResponse(javax.servlet.http.HttpServletResponse) URL(java.net.URL)

Example 67 with HttpServletResponse

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 68 with HttpServletResponse

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 69 with HttpServletResponse

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());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpRequestCallback(ghostdriver.server.HttpRequestCallback) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Test(org.junit.Test)

Example 70 with HttpServletResponse

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"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebDriver(org.openqa.selenium.WebDriver) HttpRequestCallback(ghostdriver.server.HttpRequestCallback) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

HttpServletResponse (javax.servlet.http.HttpServletResponse)1635 HttpServletRequest (javax.servlet.http.HttpServletRequest)1312 Test (org.junit.Test)705 IOException (java.io.IOException)576 ServletException (javax.servlet.ServletException)491 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)223 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)195 Request (org.eclipse.jetty.server.Request)186 HttpServlet (javax.servlet.http.HttpServlet)157 CountDownLatch (java.util.concurrent.CountDownLatch)156 FilterChain (javax.servlet.FilterChain)148 PrintWriter (java.io.PrintWriter)138 Test (org.testng.annotations.Test)127 HashMap (java.util.HashMap)106 ServletOutputStream (javax.servlet.ServletOutputStream)105 InterruptedIOException (java.io.InterruptedIOException)97 InputStream (java.io.InputStream)85 OutputStream (java.io.OutputStream)81 HttpSession (javax.servlet.http.HttpSession)75 ServletResponse (javax.servlet.ServletResponse)74