Java Code Examples for javax.servlet.ServletResponse#flushBuffer()
The following examples show how to use
javax.servlet.ServletResponse#flushBuffer() .
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: NanoPiranha.java From piranha with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Service. * * @param servletRequest the request. * @param servletResponse the response. * @throws IOException when an I/O error occurs. * @throws ServletException when a Servlet error occurs. */ public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException { Iterator<Filter> iterator = filters.descendingIterator(); NanoFilterChain chain = new NanoFilterChain(servlet); while (iterator.hasNext()) { Filter filter = iterator.next(); NanoFilterChain previousChain = chain; chain = new NanoFilterChain(filter, previousChain); } if (servletRequest.getServletContext() == null && servletRequest instanceof NanoRequest) { NanoRequest nanoRequest = (NanoRequest) servletRequest; nanoRequest.setWebApplication(webApplication); } if (servletResponse instanceof NanoResponse) { NanoResponse nanoResponse = (NanoResponse) servletResponse; nanoResponse.setWebApplication(webApplication); } chain.doFilter(servletRequest, servletResponse); servletResponse.flushBuffer(); }
Example 2
Source File: TransformationFilter.java From sling-whiteboard with Apache License 2.0 | 6 votes |
/** * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, * javax.servlet.ServletResponse, javax.servlet.FilterChain) */ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof SlingHttpServletRequest)) { throw new ServletException("Request is not a Apache Sling HTTP request."); } final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response; List<TransformationStep> steps = manager.getSteps(slingRequest); if (!steps.isEmpty()) { TransformationContext context = new TransformationContextImpl(slingRequest, slingResponse, steps); steps.forEach(transformer -> transformer.before(context)); response = new TransformationResponse(context); chain.doFilter(request, response); steps.forEach(transformer -> transformer.after(context)); response.flushBuffer(); } else { chain.doFilter(request, response); } }
Example 3
Source File: RequestDispatcherImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void forward(ServletRequest request, ServletResponse response) throws IOException, ServletException { if (!(request instanceof HttpServletRequest && response instanceof HttpServletResponse)) { throw new ServletException("Must be http request"); } if (response.isCommitted()) { throw new IllegalStateException( "Cannot forward request after response is committed"); } response.reset(); service((RequestImpl) request, (ResponseImpl) response); response.flushBuffer(); }
Example 4
Source File: ErrorFilter.java From para with Apache License 2.0 | 6 votes |
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) { ErrorWrapperResponse wrapped = new ErrorWrapperResponse((HttpServletResponse) response); try { chain.doFilter(request, wrapped); int status = wrapped.getStatus(); if (status >= 400) { setErrorAttributes(request, status, wrapped.getMessage()); } } catch (Exception ex) { // rethrow(ex); LoggerFactory.getLogger(getClass()).error(null, ex); } response.flushBuffer(); } else { chain.doFilter(request, response); } }
Example 5
Source File: DefaultServletRequestDispatcher.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void invokeTargetAsyncServlet(ServletRequest invokeServletRequest, HttpServletRequest previousPathRequest, AsyncHttpDispatchWrapper asyncHttpDispatchWrapper, ServletResponse servletResponse) throws ServletException, IOException { // A typical call chain to arrive here is DefaultAsyncContext#dispatch -> DefaultAsyncDispatcher#dispatch -> forward -> asyncForwrd -> asyncHttpForward -> invokeTargetAsyncServlet if (path != null) { setAsyncAttributes(previousPathRequest, asyncHttpDispatchWrapper); asyncHttpDispatchWrapper.setServletPath(getServletPath(path)); // TODO: this is likely not entirely correct, maybe needs to be done earlier // TODO: also needs to combine query string from path with existing query string String queryString = getQueryString(path); if (queryString != null && !queryString.trim().equals("")) { asyncHttpDispatchWrapper.setQueryString(queryString); } else { asyncHttpDispatchWrapper.setQueryString(previousPathRequest.getQueryString()); } asyncHttpDispatchWrapper.setAttribute("PREVIOUS_REQUEST", invokeServletRequest); asyncHttpDispatchWrapper.getWrapperAttributes().add("PREVIOUS_REQUEST"); } else { asyncHttpDispatchWrapper.setServletPath("/" + servletEnvironment.getServletName()); } servletEnvironment.getWebApplication().linkRequestAndResponse(invokeServletRequest, servletResponse); servletEnvironment.getServlet().service(invokeServletRequest, servletResponse); servletEnvironment.getWebApplication().unlinkRequestAndResponse(invokeServletRequest, servletResponse); servletResponse.flushBuffer(); }
Example 6
Source File: RestAsyncListener.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Override public void onTimeout(AsyncEvent event) throws IOException { // in this time, maybe: // 1.invocation in executor's queue // 2.already executing in executor // 3.already send response // to avoid concurrent, must lock request ServletRequest request = event.getSuppliedRequest(); HttpServletRequestEx requestEx = (HttpServletRequestEx) request.getAttribute(RestConst.REST_REQUEST); LOGGER.error("Rest request timeout, method {}, path {}.", requestEx.getMethod(), requestEx.getRequestURI()); // Waiting till executing in executor done. This operation may block container pool and make timeout requests in executor's // queue getting executed, and will cause bad performance. So default timeout is setting to -1 to disable timeout. synchronized (requestEx) { ServletResponse response = event.getAsyncContext().getResponse(); if (!response.isCommitted()) { // invocation in executor's queue response.setContentType(MediaType.APPLICATION_JSON); // we don't know if developers declared one statusCode in contract // so we use cse inner statusCode here ((HttpServletResponse) response).setStatus(Status.INTERNAL_SERVER_ERROR.getStatusCode()); PrintWriter out = response.getWriter(); out.write(TIMEOUT_MESSAGE); response.flushBuffer(); } request.removeAttribute(RestConst.REST_REQUEST); } LOGGER.error("Rest request timeout committed, method {}, path {}.", requestEx.getMethod(), requestEx.getRequestURI()); }
Example 7
Source File: RequestDispatcherImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void include(ServletRequest request, ServletResponse response) throws IOException, ServletException { if (!(request instanceof HttpServletRequest && response instanceof HttpServletResponse)) { throw new ServletException("Must be http request"); } final RequestWrapper wrappedRequest = new RequestWrapper((HttpServletRequest) request); final ResponseWrapper wrappedResponse = new ResponseWrapper((HttpServletResponse) response); wrappedRequest.setAttribute("javax.servlet.include.request_uri", uri); wrappedRequest.setAttribute("javax.servlet.include.context_path", ""); wrappedRequest.setAttribute("javax.servlet.include.servlet_path", servletPath); if (pathInfo != null) { wrappedRequest.setAttribute("javax.servlet.include.path_info", pathInfo); } if (queryString != null) { wrappedRequest.setAttribute("javax.servlet.include.query_string", queryString); } service(wrappedRequest, wrappedResponse); response.flushBuffer(); }