Package javax.servlet

Examples of javax.servlet.ServletInputStream


        when(mockHttpServletRequest.getInputStream()).thenReturn(stream);
    }

    @Test
    public void testValidateForInvalidEntityXML() throws IOException {
        ServletInputStream invalidProcessXML = getServletInputStream(SAMPLE_INVALID_PROCESS_XML);
        when(mockHttpServletRequest.getInputStream()).thenReturn(
                invalidProcessXML);

        try {
            validate(mockHttpServletRequest,
View Full Code Here


        }
    }

    @Test
    public void testValidateForInvalidEntityType() throws IOException {
        ServletInputStream invalidProcessXML = getServletInputStream(SAMPLE_PROCESS_XML);
        when(mockHttpServletRequest.getInputStream()).thenReturn(
                invalidProcessXML);

        try {
            validate(mockHttpServletRequest,
View Full Code Here

     * @param resourceName
     * @return ServletInputStream
     */
    private ServletInputStream getServletInputStream(String resourceName) {
        final InputStream stream = this.getClass().getResourceAsStream(resourceName);
        return new ServletInputStream() {

            @Override
            public int read() throws IOException {
                return stream.read();
            }
View Full Code Here

            ByteArrayOutputStream copyBuffer = streams.get();
            copyBuffer.reset();
            IOUtils.copyBytes(request.getInputStream(), copyBuffer, 4096, false);
            final ByteArrayInputStream buffer =
                    new ByteArrayInputStream(copyBuffer.toByteArray(), 0, copyBuffer.size());
            stream = new ServletInputStream() {
                @Override
                public int read() throws IOException {
                    return buffer.read();
                }
View Full Code Here

        return "text/plain";
    }

    @Override
    public ServletInputStream getInputStream() throws IOException {
        return new ServletInputStream() {
            @Override
            public int read() throws IOException {
                return 0;
            }
        };
View Full Code Here

        charset = Charset.defaultCharset().name();
      }
      byte[] bytes = data.getBytes(charset);
      final ByteArrayInputStream in = new ByteArrayInputStream(bytes);

      return new ServletInputStream() {
       
        @Override
        public int read() throws IOException {
          return in.read();
        }
View Full Code Here

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        StringBuffer buf = null;
        if(request.getContentLength() > 0) {
            buf = new StringBuffer();
            ServletInputStream in = request.getInputStream();
            int i = 0;
            while(i<request.getContentLength()) {
                int c = in.read();
                if(c == -1) {
                    break;
                } else {
                    buf.append((char)c);
                }
            }
        } else if("chunked".equalsIgnoreCase(request.getHeader("Transfer-Encoding"))) {
           buf = new StringBuffer();
           ServletInputStream in = request.getInputStream();
           for(int c = in.read(); c != -1; c = in.read()) {
               if(c == -1) {
                   break;
               } else {
                   buf.append((char)c);
               }
View Full Code Here

   * Sets up all the mock objects.
   */
  private void setUpMockObjects() {
    this.request = new CustomMockHttpServletRequest();
    byte[] content = { 4, 6, 7 };
    ServletInputStream inputStream = new DelegatingServletInputStream(
        new ByteArrayInputStream(content));
    this.request.inputStream = inputStream;

    this.response = new MockHttpServletResponse();

View Full Code Here

     */
    protected void uploadWar(HttpServletRequest request, File war)
        throws IOException {

        war.delete();
        ServletInputStream istream = null;
        BufferedOutputStream ostream = null;
        try {
            istream = request.getInputStream();
            ostream =
                new BufferedOutputStream(new FileOutputStream(war), 1024);
            byte buffer[] = new byte[1024];
            while (true) {
                int n = istream.read(buffer);
                if (n < 0) {
                    break;
                }
                ostream.write(buffer, 0, n);
            }
            ostream.flush();
            ostream.close();
            ostream = null;
            istream.close();
            istream = null;
        } catch (IOException e) {
            war.delete();
            throw e;
        } finally {
            if (ostream != null) {
                try {
                    ostream.close();
                } catch (Throwable t) {
                    ;
                }
                ostream = null;
            }
            if (istream != null) {
                try {
                    istream.close();
                } catch (Throwable t) {
                    ;
                }
                istream = null;
            }
View Full Code Here

    byte[] request = buildRequest();

    // Ok lets make an input stream to return
    final ByteArrayInputStream bais = new ByteArrayInputStream(request);

    return new ServletInputStream()
    {
      @Override
      public int read()
      {
        return bais.read();
View Full Code Here

TOP

Related Classes of javax.servlet.ServletInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.