/** * The default behavior of this method is to return getInputStream() * on the wrapped request object. */ public ServletInputStream getInputStream() throws IOException { return this.request.getInputStream(); }
@Override public ServletInputStream getInputStream() throws IOException { if (this.inputStream == null) { this.inputStream = new ContentCachingInputStream(getRequest().getInputStream()); } return this.inputStream; }
public static String readInputStreamToString(ServletRequest request) { try { return IOUtils.toString(request.getInputStream(), UTF_8.name()); } catch (IOException ioe) { MOCK_SERVER_LOGGER.error("IOException while reading HttpServletRequest input stream", ioe); throw new RuntimeException("IOException while reading HttpServletRequest input stream", ioe); } }
public static byte[] readInputStreamToByteArray(ServletRequest request) { try { return IOUtils.toByteArray(request.getInputStream()); } catch (IOException ioe) { MOCK_SERVER_LOGGER.error("IOException while reading HttpServletRequest input stream", ioe); throw new RuntimeException("IOException while reading HttpServletRequest input stream", ioe); } }
protected BufferedInputStream getBufferedInputStream() throws IOException { if (bufferedInputStream == null) { //workaround Tomcat issue with form POSTs //see http://stackoverflow.com/questions/18489399/read-httpservletrequests-post-body-and-then-call-getparameter-in-tomcat final ServletRequest request = getRequest(); request.getParameterMap(); //buffer the payload so we can inspect it bufferedInputStream = new BufferedInputStream(request.getInputStream()); // and mark to allow the stream to be reset bufferedInputStream.mark(Integer.MAX_VALUE); } return bufferedInputStream; }
@Override public ServletInputStream getInputStream() throws IOException { if (this.inputStream == null) { this.inputStream = new ContentCachingInputStream(getRequest().getInputStream()); } return this.inputStream; }
/** * 解析上传文件和表单数据 * * @param request Http请求 * @throws IOException IO异常 */ public void parseRequest(ServletRequest request) throws IOException { parseRequestStream(request.getInputStream(), request.getCharacterEncoding()); }
/** * 解析上传文件和表单数据 * * @param request Http请求 * @throws IOException IO异常 */ public void parseRequest(ServletRequest request) throws IOException { parseRequestStream(request.getInputStream(), request.getCharacterEncoding()); }
@Override public void onDataAvailable() throws IOException { Log.trace("Data is available to be read from [" + remoteAddress + "]"); final ServletInputStream inputStream = context.getRequest().getInputStream(); byte b[] = new byte[1024]; int length; while (inputStream.isReady() && (length = inputStream.read(b)) != -1) { outStream.write(b, 0, length); } }
/** * 获取请求体byte[]<br> * 调用该方法后,getParam方法将失效 * * @param request {@link ServletRequest} * @return 获得请求体byte[] * @since 4.0.2 */ public static byte[] getBodyBytes(ServletRequest request) { try { return IoUtil.readBytes(request.getInputStream()); } catch (IOException e) { throw new IORuntimeException(e); } } // --------------------------------------------------------- getParam end
/** * 获取请求体byte[]<br> * 调用该方法后,getParam方法将失效 * * @param request {@link ServletRequest} * @return 获得请求体byte[] * @since 4.0.2 */ public static byte[] getBodyBytes(ServletRequest request) { try { return IoUtil.readBytes(request.getInputStream()); } catch (IOException e) { throw new IORuntimeException(e); } } // --------------------------------------------------------- getParam end
@Override public void doFilter(ServletRequest filterRequest, ServletResponse filterResponse) throws IOException, ServletException { ((HttpServletResponse) filterResponse).setStatus(HttpServletResponse.SC_OK); byte[] buf = FileCopyUtils.copyToByteArray(filterRequest.getInputStream()); assertArrayEquals(requestBody, buf); } };
@Override public void doFilter(ServletRequest filterRequest, ServletResponse filterResponse) throws IOException, ServletException { ((HttpServletResponse) filterResponse).setStatus(HttpServletResponse.SC_OK); byte[] buf = FileCopyUtils.copyToByteArray(filterRequest.getInputStream()); assertArrayEquals(requestBody, buf); ContentCachingRequestWrapper wrapper = WebUtils.getNativeRequest(filterRequest, ContentCachingRequestWrapper.class); assertArrayEquals("Hel".getBytes("UTF-8"), wrapper.getContentAsByteArray()); } };
@Override protected DataBuffer readFromInputStream() throws IOException { boolean release = true; int capacity = this.bufferSize; DataBuffer dataBuffer = this.factory.allocateBuffer(capacity); try { ByteBuffer byteBuffer = dataBuffer.asByteBuffer(0, capacity); ServletRequest request = getNativeRequest(); int read = ((CoyoteInputStream) request.getInputStream()).read(byteBuffer); logBytesRead(read); if (read > 0) { dataBuffer.writePosition(read); release = false; return dataBuffer; } else if (read == -1) { return EOF_BUFFER; } else { return null; } } finally { if (release) { DataBufferUtils.release(dataBuffer); } } } }
@Override protected DataBuffer readFromInputStream() throws IOException { boolean release = true; int capacity = this.bufferSize; DataBuffer dataBuffer = this.factory.allocateBuffer(capacity); try { ByteBuffer byteBuffer = dataBuffer.asByteBuffer(0, capacity); ServletRequest request = getNativeRequest(); int read = ((CoyoteInputStream) request.getInputStream()).read(byteBuffer); logBytesRead(read); if (read > 0) { dataBuffer.writePosition(read); release = false; return dataBuffer; } else if (read == -1) { return EOF_BUFFER; } else { return null; } } finally { if (release) { DataBufferUtils.release(dataBuffer); } } } }
/** * The default behavior of this method is to return getInputStream() * on the wrapped request object. */ public ServletInputStream getInputStream() throws IOException { return this.request.getInputStream(); }
/** * The default behavior of this method is to return getInputStream() * on the wrapped request object. */ public ServletInputStream getInputStream() throws IOException { return this.request.getInputStream(); }
@Override public ServletInputStream getInputStream() throws IOException { if (this.inputStream == null) { if (cacheRequest) { byte inputBytes[] = IOUtils.toByteArray(getRequest().getInputStream()); ByteBuf byteBuf = Unpooled.wrappedBuffer(inputBytes); this.inputStream = new BufferInputStream(byteBuf); setBodyBuffer(Buffer.buffer(Unpooled.wrappedBuffer(byteBuf))); } else { this.inputStream = getRequest().getInputStream(); } } return this.inputStream; }
final PushbackInputStream requestBody = new PushbackInputStream(req.getInputStream()); int firstByte = requestBody.read(); final boolean isBodyEmpty = firstByte == -1;
final PushbackInputStream requestBody = new PushbackInputStream(req.getInputStream()); int firstByte = requestBody.read(); final boolean isBodyEmpty = firstByte == -1;