Search in sources :

Example 56 with HttpServletRequest

use of javax.servlet.http.HttpServletRequest in project hadoop by apache.

the class TestWebAppTests method testInstances.

@Test
public void testInstances() throws Exception {
    Injector injector = WebAppTests.createMockInjector(this);
    HttpServletRequest req = injector.getInstance(HttpServletRequest.class);
    HttpServletResponse res = injector.getInstance(HttpServletResponse.class);
    String val = req.getParameter("foo");
    PrintWriter out = res.getWriter();
    out.println("Hello world!");
    logInstances(req, res, out);
    assertSame(req, injector.getInstance(HttpServletRequest.class));
    assertSame(res, injector.getInstance(HttpServletResponse.class));
    assertSame(this, injector.getInstance(TestWebAppTests.class));
    verify(req).getParameter("foo");
    verify(res).getWriter();
    verify(out).println("Hello world!");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Injector(com.google.inject.Injector) HttpServletResponse(javax.servlet.http.HttpServletResponse) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 57 with HttpServletRequest

use of javax.servlet.http.HttpServletRequest in project hadoop by apache.

the class DefaultWrapperServlet method doGet.

@Private
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    RequestDispatcher rd = getServletContext().getNamedDispatcher("default");
    HttpServletRequest wrapped = new HttpServletRequestWrapper(req) {

        public String getServletPath() {
            return "";
        }
    };
    rd.forward(wrapped, resp);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) RequestDispatcher(javax.servlet.RequestDispatcher) Private(org.apache.hadoop.classification.InterfaceAudience.Private)

Example 58 with HttpServletRequest

use of javax.servlet.http.HttpServletRequest in project hadoop by apache.

the class TestAggregatedLogsBlock method getAggregatedLogsBlockForTest.

private AggregatedLogsBlockForTest getAggregatedLogsBlockForTest(Configuration configuration, String user, String containerId, String nodeName) {
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getRemoteUser()).thenReturn(user);
    AggregatedLogsBlockForTest aggregatedBlock = new AggregatedLogsBlockForTest(configuration);
    aggregatedBlock.setRequest(request);
    aggregatedBlock.moreParams().put(YarnWebParams.CONTAINER_ID, containerId);
    aggregatedBlock.moreParams().put(YarnWebParams.NM_NODENAME, nodeName);
    aggregatedBlock.moreParams().put(YarnWebParams.APP_OWNER, user);
    aggregatedBlock.moreParams().put("start", "");
    aggregatedBlock.moreParams().put("end", "");
    aggregatedBlock.moreParams().put(YarnWebParams.ENTITY_STRING, "entity");
    return aggregatedBlock;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AggregatedLogsBlockForTest(org.apache.hadoop.yarn.webapp.log.AggregatedLogsBlockForTest)

Example 59 with HttpServletRequest

use of javax.servlet.http.HttpServletRequest in project hadoop by apache.

the class TestHsWebServicesAcls method testGetJobTaskAcls.

@Test
public void testGetJobTaskAcls() {
    HttpServletRequest hsr = mock(HttpServletRequest.class);
    when(hsr.getRemoteUser()).thenReturn(ENEMY_USER);
    try {
        hsWebServices.getJobTask(hsr, jobIdStr, this.taskIdStr);
        fail("enemy can access job");
    } catch (WebApplicationException e) {
        assertEquals(Status.UNAUTHORIZED, Status.fromStatusCode(e.getResponse().getStatus()));
    }
    when(hsr.getRemoteUser()).thenReturn(FRIENDLY_USER);
    hsWebServices.getJobTask(hsr, this.jobIdStr, this.taskIdStr);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 60 with HttpServletRequest

use of javax.servlet.http.HttpServletRequest in project hadoop by apache.

the class TestHsWebServicesAcls method testGetJobTaskAttemptsAcls.

@Test
public void testGetJobTaskAttemptsAcls() {
    HttpServletRequest hsr = mock(HttpServletRequest.class);
    when(hsr.getRemoteUser()).thenReturn(ENEMY_USER);
    try {
        hsWebServices.getJobTaskAttempts(hsr, this.jobIdStr, this.taskIdStr);
        fail("enemy can access job");
    } catch (WebApplicationException e) {
        assertEquals(Status.UNAUTHORIZED, Status.fromStatusCode(e.getResponse().getStatus()));
    }
    when(hsr.getRemoteUser()).thenReturn(FRIENDLY_USER);
    hsWebServices.getJobTaskAttempts(hsr, this.jobIdStr, this.taskIdStr);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Aggregations

HttpServletRequest (javax.servlet.http.HttpServletRequest)2488 HttpServletResponse (javax.servlet.http.HttpServletResponse)1308 Test (org.junit.Test)987 IOException (java.io.IOException)595 ServletException (javax.servlet.ServletException)498 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)223 FilterChain (javax.servlet.FilterChain)200 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)196 Test (org.testng.annotations.Test)168 Request (org.eclipse.jetty.server.Request)164 CountDownLatch (java.util.concurrent.CountDownLatch)160 HttpServlet (javax.servlet.http.HttpServlet)156 HttpSession (javax.servlet.http.HttpSession)150 HashMap (java.util.HashMap)130 PrintWriter (java.io.PrintWriter)121 Map (java.util.Map)100 InterruptedIOException (java.io.InterruptedIOException)97 ServletRequest (javax.servlet.ServletRequest)95 ServletContext (javax.servlet.ServletContext)91 ServletOutputStream (javax.servlet.ServletOutputStream)90