Search in sources :

Example 26 with ServletInputStream

use of javax.servlet.ServletInputStream in project ninja by ninjaframework.

the class NinjaServletContextTest method testGetUTF8ParameterInMultipart.

@Test
public void testGetUTF8ParameterInMultipart() throws Exception {
    String body = "------Ninja\r\n" + "Content-Disposition: form-data; name=\"utf8\"\r\n" + "\r\n" + "✓\r\n" + "------Ninja--\r\n";
    ServletInputStream sis = createHttpServletRequestInputStream(body.getBytes(NinjaConstant.UTF_8));
    when(httpServletRequest.getContentType()).thenReturn("multipart/form-data; boundary=----Ninja");
    when(httpServletRequest.getMethod()).thenReturn("POST");
    when(ninjaProperties.getIntegerWithDefault(NinjaConstant.UPLOADS_MAX_FILE_SIZE, -1)).thenReturn(1024);
    when(ninjaProperties.getIntegerWithDefault(NinjaConstant.UPLOADS_MAX_TOTAL_SIZE, -1)).thenReturn(1024);
    when(httpServletRequest.getInputStream()).thenReturn(sis);
    context.init(servletContext, httpServletRequest, httpServletResponse);
    assertEquals("✓", context.getParameter("utf8"));
}
Also used : ServletInputStream(javax.servlet.ServletInputStream) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 27 with ServletInputStream

use of javax.servlet.ServletInputStream in project dropwizard by dropwizard.

the class TaskServletTest method passesQueryStringParamsAlong.

@Test
public void passesQueryStringParamsAlong() throws Exception {
    final PrintWriter output = mock(PrintWriter.class);
    final ServletInputStream bodyStream = new TestServletInputStream(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)));
    when(request.getMethod()).thenReturn("POST");
    when(request.getPathInfo()).thenReturn("/gc");
    when(request.getParameterNames()).thenReturn(Collections.enumeration(ImmutableList.of("runs")));
    when(request.getParameterValues("runs")).thenReturn(new String[] { "1" });
    when(request.getInputStream()).thenReturn(bodyStream);
    when(response.getWriter()).thenReturn(output);
    servlet.service(request, response);
    verify(gc).execute(ImmutableMultimap.of("runs", "1"), output);
}
Also used : ServletInputStream(javax.servlet.ServletInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 28 with ServletInputStream

use of javax.servlet.ServletInputStream in project Axe by DongyuCai.

the class TestFilter4 method doFilter.

@Override
public boolean doFilter(HttpServletRequest request, HttpServletResponse response, Param param, Handler handler) throws RestException {
    try {
        ServletInputStream in = request.getInputStream();
        byte[] data = new byte[1024];
        int len = 0;
        while ((len = in.read(data, 0, data.length)) > 0) {
            System.out.println("read:" + len);
        }
    } catch (Exception e) {
    }
    return true;
}
Also used : ServletInputStream(javax.servlet.ServletInputStream) RestException(org.axe.exception.RestException)

Example 29 with ServletInputStream

use of javax.servlet.ServletInputStream in project OpenAM by OpenRock.

the class SOAPReceiver method doPost.

/**
     * Processes HTTP request and sends back HTTP response. It gets called
     * internally by the servlet engine.
     *
     * @param request the HTTP request.
     * @param response the HTTP response.
     * @throws IOException if an IO error occurs while processing
                           the request
     * @throws ServletException if an servlet error occurs while processing
     *                          the request
     */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    try {
        MimeHeaders mimeHeaders = SAMLUtils.getMimeHeaders(request);
        ServletInputStream sInputStream = request.getInputStream();
        SOAPMessage soapMessage = msgFactory.createMessage(mimeHeaders, sInputStream);
        SOAPMessage soapMessageReply = this.onMessage(soapMessage, request);
        if (soapMessageReply != null) {
            SAMLUtils.setMimeHeaders(soapMessageReply.getMimeHeaders(), response);
            ServletOutputStream sOutputStream = response.getOutputStream();
            soapMessageReply.writeTo(sOutputStream);
            sOutputStream.flush();
        } else {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    } catch (SOAPException se) {
        throw new ServletException(se);
    }
}
Also used : ServletException(javax.servlet.ServletException) MimeHeaders(javax.xml.soap.MimeHeaders) ServletInputStream(javax.servlet.ServletInputStream) ServletOutputStream(javax.servlet.ServletOutputStream) SOAPException(javax.xml.soap.SOAPException) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 30 with ServletInputStream

use of javax.servlet.ServletInputStream in project Asqatasun by Asqatasun.

the class LoginControllerTest method testDisplayLoginPage.

/**
     * Test of displayLoginPage method, of class LoginController.
     */
public void testDisplayLoginPage() {
    System.out.println("displayLoginPage");
    Model model = new ExtendedModelMap();
    setUpMockAuthenticationContext();
    LoginController instance = new LoginController();
    String expResult = TgolKeyStore.LOGIN_VIEW_NAME;
    String result = instance.displayLoginPage("", new HttpServletRequest() {

        @Override
        public String getAuthType() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Cookie[] getCookies() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public long getDateHeader(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getHeader(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Enumeration getHeaders(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Enumeration getHeaderNames() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public int getIntHeader(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getMethod() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getPathInfo() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getPathTranslated() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getContextPath() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getQueryString() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getRemoteUser() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean isUserInRole(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Principal getUserPrincipal() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getRequestedSessionId() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getRequestURI() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public StringBuffer getRequestURL() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getServletPath() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public HttpSession getSession(boolean bln) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public HttpSession getSession() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean isRequestedSessionIdValid() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean isRequestedSessionIdFromCookie() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean isRequestedSessionIdFromURL() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean isRequestedSessionIdFromUrl() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Object getAttribute(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Enumeration getAttributeNames() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getCharacterEncoding() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void setCharacterEncoding(String string) throws UnsupportedEncodingException {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public int getContentLength() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getContentType() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public ServletInputStream getInputStream() throws IOException {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getParameter(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Enumeration getParameterNames() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String[] getParameterValues(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Map getParameterMap() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getProtocol() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getScheme() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getServerName() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public int getServerPort() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public BufferedReader getReader() throws IOException {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getRemoteAddr() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getRemoteHost() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void setAttribute(String string, Object o) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void removeAttribute(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Locale getLocale() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Enumeration getLocales() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean isSecure() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public RequestDispatcher getRequestDispatcher(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getRealPath(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public int getRemotePort() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getLocalName() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getLocalAddr() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public int getLocalPort() {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }, model);
    assertEquals(expResult, result);
}
Also used : Locale(java.util.Locale) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Enumeration(java.util.Enumeration) HttpSession(javax.servlet.http.HttpSession) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) RequestDispatcher(javax.servlet.RequestDispatcher) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletInputStream(javax.servlet.ServletInputStream) Model(org.springframework.ui.Model) BufferedReader(java.io.BufferedReader) Map(java.util.Map) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Principal(java.security.Principal)

Aggregations

ServletInputStream (javax.servlet.ServletInputStream)79 IOException (java.io.IOException)51 HttpServletRequest (javax.servlet.http.HttpServletRequest)43 Test (org.junit.Test)43 ServletException (javax.servlet.ServletException)41 HttpServletResponse (javax.servlet.http.HttpServletResponse)40 CountDownLatch (java.util.concurrent.CountDownLatch)26 HttpServlet (javax.servlet.http.HttpServlet)20 DeferredContentProvider (org.eclipse.jetty.client.util.DeferredContentProvider)20 InterruptedIOException (java.io.InterruptedIOException)18 AsyncContext (javax.servlet.AsyncContext)17 ReadListener (javax.servlet.ReadListener)17 ServletOutputStream (javax.servlet.ServletOutputStream)16 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)16 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)15 Request (org.eclipse.jetty.server.Request)14 Response (org.eclipse.jetty.client.api.Response)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 PrintWriter (java.io.PrintWriter)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8