javax.servlet.ReadListener Java Examples
The following examples show how to use
javax.servlet.ReadListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RepeatedlyReadRequestWrapper.java From ueboot with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public ServletInputStream getInputStream() { final ByteArrayInputStream bais = new ByteArrayInputStream(body); return new ServletInputStream() { @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return false; } @Override public void setReadListener(ReadListener listener) { } @Override public int read() { return bais.read(); } }; }
Example #2
Source File: RequestWrapper.java From auto-subtitle-tool with GNU General Public License v2.0 | 6 votes |
@Override public ServletInputStream getInputStream() throws IOException { final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes()); ServletInputStream servletInputStream = new ServletInputStream() { @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return false; } @Override public void setReadListener(ReadListener readListener) { } @Override public int read() throws IOException { return byteArrayInputStream.read(); } }; return servletInputStream; }
Example #3
Source File: RequestWrapper.java From wisp with Apache License 2.0 | 6 votes |
@Override public ServletInputStream getInputStream() throws IOException { return new ServletInputStream() { @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return false; } @Override public void setReadListener(ReadListener readListener) { } private TeeInputStream tee = new TeeInputStream(RequestWrapper.super.getInputStream(), bos); @Override public int read() throws IOException { return tee.read(); } }; }
Example #4
Source File: UpgradeServletInputStream.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void setReadListener(final ReadListener readListener) { if (readListener == null) { throw UndertowServletMessages.MESSAGES.listenerCannotBeNull(); } if (listener != null) { throw UndertowServletMessages.MESSAGES.listenerAlreadySet(); } listener = readListener; channel.getReadSetter().set(new ServletInputStreamChannelListener()); //we resume from an async task, after the request has been dispatched ioExecutor.execute(new Runnable() { @Override public void run() { channel.wakeupReads(); } }); }
Example #5
Source File: ProxyExchange.java From spring-cloud-gateway with Apache License 2.0 | 6 votes |
public ServletInputStream getInputStream() { ByteArrayInputStream body = new ByteArrayInputStream( builder.toString().getBytes()); return new ServletInputStream() { @Override public int read() throws IOException { return body.read(); } @Override public void setReadListener(ReadListener listener) { } @Override public boolean isReady() { return true; } @Override public boolean isFinished() { return body.available() <= 0; } }; }
Example #6
Source File: RequestWrapper.java From spring-boot-vue-admin with Apache License 2.0 | 6 votes |
@Override public ServletInputStream getInputStream() { final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(this.body.toString().getBytes()); return new ServletInputStream() { @Override public int read() { return byteArrayInputStream.read(); } @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return false; } @Override public void setReadListener(final ReadListener readListener) {} }; }
Example #7
Source File: ContentCachingRequestWrapper.java From fast-family-master with Apache License 2.0 | 6 votes |
@Override public ServletInputStream getInputStream() throws IOException { final ByteArrayInputStream bais = new ByteArrayInputStream(body); return new ServletInputStream() { @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return false; } @Override public void setReadListener(ReadListener listener) { } @Override public int read() throws IOException { return bais.read(); } }; }
Example #8
Source File: CachingRequestWrapper.java From spring-hmac-rest with MIT License | 6 votes |
@Override public ServletInputStream getInputStream() throws IOException { final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(getPayload()); return new ServletInputStream() { @Override public int read() throws IOException { return byteArrayInputStream.read(); } @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return true; } @Override public void setReadListener(ReadListener listener) { // } }; }
Example #9
Source File: MultipartTest.java From everrest with Eclipse Public License 2.0 | 6 votes |
private ServletInputStream createServletInputStream(ByteArrayInputStream in) { return new ServletInputStream() { @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return false; } @Override public void setReadListener(ReadListener readListener) { } @Override public int read() throws IOException { return in.read(); } }; }
Example #10
Source File: HttpSolrCallGetCoreTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public ServletInputStream getInputStream() throws IOException { return new ServletInputStream() { @Override public boolean isFinished() { return true; } @Override public boolean isReady() { return true; } @Override public void setReadListener(ReadListener readListener) { } @Override public int read() throws IOException { return 0; } }; }
Example #11
Source File: CustomHttpServletRequestWrapper.java From NFVO with Apache License 2.0 | 6 votes |
@Override public ServletInputStream getInputStream() { final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes()); return new ServletInputStream() { @Override public boolean isFinished() { return byteArrayInputStream.available() == 0; } @Override public boolean isReady() { return true; } @Override public void setReadListener(ReadListener listener) { throw new RuntimeException("Not implemented"); } public int read() { return byteArrayInputStream.read(); } }; }
Example #12
Source File: InputBuffer.java From Tomcat8-Source-Read with MIT License | 6 votes |
public void setReadListener(ReadListener listener) { coyoteRequest.setReadListener(listener); // The container is responsible for the first call to // listener.onDataAvailable(). If isReady() returns true, the container // needs to call listener.onDataAvailable() from a new thread. If // isReady() returns false, the socket will be registered for read and // the container will call listener.onDataAvailable() once data arrives. // Must call isFinished() first as a call to isReady() if the request // has been finished will register the socket for read interest and that // is not required. if (!coyoteRequest.isFinished() && isReady()) { coyoteRequest.action(ActionCode.DISPATCH_READ, null); if (!ContainerThreadMarker.isContainerThread()) { // Not on a container thread so need to execute the dispatch coyoteRequest.action(ActionCode.DISPATCH_EXECUTE, null); } } }
Example #13
Source File: UpgradeServletInputStream.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public final void setReadListener(ReadListener listener) { if (listener == null) { throw new IllegalArgumentException( sm.getString("upgrade.sis.readListener.null")); } if (this.listener != null) { throw new IllegalArgumentException( sm.getString("upgrade.sis.readListener.set")); } if (closed) { throw new IllegalStateException(sm.getString("upgrade.sis.read.closed")); } this.listener = listener; // Container is responsible for first call to onDataAvailable(). if (ContainerThreadMarker.isContainerThread()) { processor.addDispatch(DispatchType.NON_BLOCKING_READ); } else { socketWrapper.registerReadInterest(); } // Switching to non-blocking. Don't know if data is available. ready = null; }
Example #14
Source File: PingServlet31Async.java From sample.daytrader7 with Apache License 2.0 | 5 votes |
/** * forwards post requests to the doGet method Creation date: (11/6/2000 * 10:52:39 AM) * * @param res * javax.servlet.http.HttpServletRequest * @param res2 * javax.servlet.http.HttpServletResponse */ @Override public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); AsyncContext ac = req.startAsync(); ServletInputStream input = req.getInputStream(); ReadListener readListener = new ReadListenerImpl(input, res, ac); input.setReadListener(readListener); }
Example #15
Source File: XssHttpServletRequestWrapper.java From springboot-admin with Apache License 2.0 | 5 votes |
@Override public ServletInputStream getInputStream() throws IOException { //非json类型,直接返回 if(!MediaType.APPLICATION_JSON_VALUE.equalsIgnoreCase(super.getHeader(HttpHeaders.CONTENT_TYPE))){ return super.getInputStream(); } //为空,直接返回 String json = IOUtils.toString(super.getInputStream(), "utf-8"); if (StringUtils.isBlank(json)) { return super.getInputStream(); } //xss过滤 json = xssEncode(json); final ByteArrayInputStream bis = new ByteArrayInputStream(json.getBytes("utf-8")); return new ServletInputStream() { @Override public boolean isFinished() { return true; } @Override public boolean isReady() { return true; } @Override public void setReadListener(ReadListener readListener) { } @Override public int read() throws IOException { return bis.read(); } }; }
Example #16
Source File: XssHttpServletRequestWrapper.java From sdb-mall with Apache License 2.0 | 5 votes |
@Override public ServletInputStream getInputStream() throws IOException { //非json类型,直接返回 if(!MediaType.APPLICATION_JSON_VALUE.equalsIgnoreCase(super.getHeader(HttpHeaders.CONTENT_TYPE))){ return super.getInputStream(); } //为空,直接返回 String json = IOUtils.toString(super.getInputStream(), "utf-8"); if (StringUtils.isBlank(json)) { return super.getInputStream(); } //xss过滤 json = xssEncode(json); final ByteArrayInputStream bis = new ByteArrayInputStream(json.getBytes("utf-8")); return new ServletInputStream() { @Override public boolean isFinished() { return true; } @Override public boolean isReady() { return true; } @Override public void setReadListener(ReadListener readListener) { } @Override public int read() throws IOException { return bis.read(); } }; }
Example #17
Source File: SolrRequestParserTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testParameterIncompatibilityException1() throws Exception { HttpServletRequest request = getMock("/solr/select", "application/x-www-form-urlencoded", 100); // we emulate Jetty that returns empty stream when parameters were parsed before: when(request.getInputStream()).thenReturn(new ServletInputStream() { @Override public int read() { return -1; } @Override public boolean isFinished() { return true; } @Override public boolean isReady() { return true; } @Override public void setReadListener(ReadListener readListener) { } }); FormDataRequestParser formdata = new FormDataRequestParser( 2048 ); SolrException e = expectThrows(SolrException.class, () -> { formdata.parseParamsAndFillStreams(request, new ArrayList<>()); }); assertTrue(e.getMessage().startsWith("Solr requires that request parameters")); assertEquals(500, e.code()); verify(request).getInputStream(); }
Example #18
Source File: XssHttpServletRequestWrapper.java From DimpleBlog with Apache License 2.0 | 5 votes |
@Override public ServletInputStream getInputStream() throws IOException { // 非json类型,直接返回 if (!isJsonRequest()) { return super.getInputStream(); } // 为空,直接返回 String json = IOUtils.toString(super.getInputStream(), StandardCharsets.UTF_8); if (StringUtils.isEmpty(json)) { return super.getInputStream(); } // xss过滤 json = EscapeUtil.clean(json).trim(); final ByteArrayInputStream bis = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)); return new ServletInputStream() { @Override public boolean isFinished() { return true; } @Override public boolean isReady() { return true; } @Override public void setReadListener(ReadListener readListener) { } @Override public int read() throws IOException { return bis.read(); } }; }
Example #19
Source File: ServerHttpRequestTests.java From spring-analysis-note with MIT License | 5 votes |
@Override public ServletInputStream getInputStream() { return new DelegatingServletInputStream(new ByteArrayInputStream(new byte[0])) { @Override public void setReadListener(ReadListener readListener) { // Ignore } }; }
Example #20
Source File: XssHttpServletRequestWrapper.java From blade-tool with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ServletInputStream getInputStream() throws IOException { if (null == super.getHeader(HttpHeaders.CONTENT_TYPE)) { return super.getInputStream(); } if (super.getHeader(HttpHeaders.CONTENT_TYPE).startsWith(MediaType.MULTIPART_FORM_DATA_VALUE)) { return super.getInputStream(); } final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(inputHandlers(super.getInputStream()).getBytes()); return new ServletInputStream() { @Override public int read() { return byteArrayInputStream.read(); } @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return false; } @Override public void setReadListener(ReadListener readListener) { } }; }
Example #21
Source File: AccessLogFilter.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public ServletInputStream getInputStream() throws IOException { final ServletInputStream inputStream = d.getInputStream(); return new ServletInputStream() { @Override public int read() throws IOException { int b = inputStream.read(); if (b != -1) { reqBody.write(b); } return b; } @Override public void setReadListener(ReadListener readListener) { inputStream.setReadListener(readListener); } @Override public boolean isReady() { return inputStream.isReady(); } @Override public boolean isFinished() { return inputStream.isFinished(); } }; }
Example #22
Source File: CrossDomainRpcLoaderTest.java From selenium with Apache License 2.0 | 5 votes |
private HttpServletRequest createJsonRequest( String method, String path, Object data) throws IOException { when(mockRequest.getHeader("content-type")).thenReturn("application/json"); Map<String, Object> payload = new TreeMap<>(); payload.put("method", method); payload.put("path", path); payload.put("data", data); InputStream stream = new ByteArrayInputStream(new Json().toJson(payload).getBytes(UTF_8)); when(mockRequest.getInputStream()).thenReturn(new ServletInputStream() { @Override public int read() throws IOException { return stream.read(); } @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return true; } @Override public void setReadListener(ReadListener readListener) { throw new UnsupportedOperationException(); } }); return mockRequest; }
Example #23
Source File: BodyReaderHttpServletRequestWrapper.java From bird-java with MIT License | 5 votes |
@Override public ServletInputStream getInputStream() { final ByteArrayInputStream stream = new ByteArrayInputStream(requestBody); return new ServletInputStream() { @Override public int read() { return stream.read(); } @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return false; } @Override public void setReadListener(ReadListener readListener) { } }; }
Example #24
Source File: ServletContextImpl.java From lams with GNU General Public License v2.0 | 5 votes |
void invokeOnDataAvailable(HttpServerExchange exchange, ReadListener listener) { try { this.onDataAvailableTask.call(exchange, listener); } catch (Exception e) { throw new RuntimeException(e); } }
Example #25
Source File: ServerHttpRequestTests.java From java-technology-stack with MIT License | 5 votes |
@Override public ServletInputStream getInputStream() { return new DelegatingServletInputStream(new ByteArrayInputStream(new byte[0])) { @Override public void setReadListener(ReadListener readListener) { // Ignore } }; }
Example #26
Source File: RequestUtils.java From pnc with Apache License 2.0 | 5 votes |
public static HttpServletRequest requestWithEntity(Object entity) throws IOException { HttpServletRequest request = mock(HttpServletRequest.class); String entityAsJson = JsonUtils.toJson(entity); when(request.getInputStream()).thenReturn(new ServletInputStream() { private ByteArrayInputStream input = new ByteArrayInputStream(entityAsJson.getBytes("UTF-8")); @Override public boolean isFinished() { return input.available() == 0; } @Override public boolean isReady() { return input.available() > 0; } @Override public void setReadListener(ReadListener readListener) { } @Override public int read() throws IOException { return input.read(); } }); return request; }
Example #27
Source File: ServletInputStreamImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void setReadListener(final ReadListener readListener) { if (readListener == null) { throw UndertowServletMessages.MESSAGES.listenerCannotBeNull(); } if (listener != null) { throw UndertowServletMessages.MESSAGES.listenerAlreadySet(); } if (!request.isAsyncStarted()) { throw UndertowServletMessages.MESSAGES.asyncNotStarted(); } asyncContext = request.getAsyncContext(); listener = readListener; channel.getReadSetter().set(internalListener = new ServletInputStreamChannelListener()); //we resume from an async task, after the request has been dispatched asyncContext.addAsyncTask(new Runnable() { @Override public void run() { channel.getIoThread().execute(new Runnable() { @Override public void run() { internalListener.handleEvent(channel); } }); } }); }
Example #28
Source File: MultipartToBase64ConverterServletRequest.java From AuTe-Framework with Apache License 2.0 | 5 votes |
@Override public void setReadListener(ReadListener readListener) { try { readListener.onDataAvailable(); } catch (IOException ex){ ex.printStackTrace(); } }
Example #29
Source File: StreamReceiverHandlerTest.java From flow with Apache License 2.0 | 5 votes |
private ServletInputStream createInputStream(final String content) { return new ServletInputStream() { boolean finished = false; @Override public boolean isFinished() { return finished; } @Override public boolean isReady() { return true; } @Override public void setReadListener(ReadListener readListener) { } int counter = 0; byte[] msg = content.getBytes(); @Override public int read() throws IOException { if (counter > msg.length + 1) { throw new AssertionError( "-1 was ignored by StreamReceiverHandler."); } if (counter >= msg.length) { counter++; finished = true; return -1; } return msg[counter++]; } }; }
Example #30
Source File: AccountServiceTest.java From swellrt with Apache License 2.0 | 5 votes |
protected ServletInputStream asServletInputStream(final String data) { return new ServletInputStream() { ByteArrayInputStream byteInputStream = new ByteArrayInputStream(data.getBytes(Charset.forName("UTF-8"))); int b; @Override public boolean isFinished() { return b == -1; } @Override public boolean isReady() { return true; } @Override public void setReadListener(ReadListener readListener) { } @Override public int read() throws IOException { this.b = byteInputStream.read(); return b; } }; }