@Override
 public void onError(AsyncEvent event) throws IOException {
   ServletResponse resp = event.getAsyncContext().getResponse();
   resp.getWriter().write("onError-");
   resp.flushBuffer();
   if (completeOnError) {
     event.getAsyncContext().complete();
   }
 }
 protected void writeData(ServletResponse response, String data) throws IOException {
   idleCheck.activity();
   Log.debug("Session[" + session.getSessionId() + "]: writeData(START): " + data);
   ServletOutputStream os = response.getOutputStream();
   os.println("Content-Type: text/plain");
   os.println();
   os.println(data);
   os.println(boundarySeperator);
   response.flushBuffer();
   Log.debug("Session[" + session.getSessionId() + "]: writeData(END): " + data);
 }
Example #3
0
 /**
  * Services this request in the same way as it would be serviced if configured as a Servlet. Does
  * not invoke any filters further down the chain. See the class-level comment for the reason why
  * this servlet might be configured as a filter.
  */
 @Override
 public void doFilter(
     final ServletRequest request, final ServletResponse response, final FilterChain chain)
     throws IOException, ServletException {
   if (Math.random() > 0.7d) {
     // response.setStatus(404);
     response.getWriter().println("The chaos monkey strikes again!");
     response.flushBuffer();
   } else {
     super.doFilter(request, response, chain);
   }
 }
 @Override
 public void onTimeout(AsyncEvent event) throws IOException {
   ServletResponse resp = event.getAsyncContext().getResponse();
   resp.getWriter().write("onTimeout-");
   resp.flushBuffer();
   if (completeOnTimeout) {
     if (dispatchUrl == null) {
       event.getAsyncContext().complete();
     } else {
       event.getAsyncContext().dispatch(dispatchUrl);
     }
   }
 }
Example #5
0
 @Override
 public void service(
     javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse)
     throws ServletException, IOException {
   HttpServletRequest req = (HttpServletRequest) servletRequest;
   HttpServletResponse resp = (HttpServletResponse) servletResponse;
   try {
     setThreadlocals(req, resp);
     tlServletConfig.set(config);
     Request request = new ServletRequest(req, servletContext);
     Response response = new ServletResponse(resp);
     httpManager.process(request, response);
   } finally {
     clearThreadlocals();
     tlServletConfig.remove();
     ServletRequest.clearThreadLocals();
     servletResponse.getOutputStream().flush();
     servletResponse.flushBuffer();
   }
 }
  @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {

    HttpServletRequest httpReq = (HttpServletRequest) request;
    HttpServletResponse httpResp = (HttpServletResponse) response;

    log.info("REQUEST-FILTER: checking for CORS (cross origin resource sharing) request");
    // for cross-domain request, add headers allowing access in a handshake
    // like manner
    if ("OPTIONS".equalsIgnoreCase(httpReq.getMethod())) {
      log.info("REQUEST-FILTER: CORS request from origin: " + httpReq.getHeader("Origin"));

      httpResp.setHeader("Access-Control-Allow-Origin", "*");
      httpResp.setHeader("Access-Control-Allow-Methods", ConfigurationStatics.VALID_HTTP_METHODS);

      // bounce back the access-control headers
      String headers = httpReq.getHeader("Access-Control-Request-Headers");
      if (headers != null) httpResp.setHeader("Access-Control-Allow-Headers", headers);

      // allow caching the cross-domain permission
      httpResp.setHeader("Access-Control-Max-Age", "3600");
      return;
    }

    log.info("REQUEST-FILTER: checking enabled flag");
    if (!poll.getEnabled()) {
      PrintWriter pw = response.getWriter();
      try {
        pw.println(VosyStatusCode.DISABLED.getStatusCode());
        response.flushBuffer();
      } catch (Exception e) {
        throw new AuthorizationServiceException("Could not write disabled response.", e);
      } finally {
        pw.close();
      }
    } else {
      chain.doFilter(request, response);
    }
  }
  /**
   * @see {@link ExternalContext#responseFlushBuffer()}
   * @since JSF 2.0
   */
  @Override
  public void responseFlushBuffer() throws IOException {

    if (portletResponse instanceof MimeResponse) {

      if (facesImplementationServletResponse != null) {

        // This happens when Mojarra's JspViewHandlingStrategy#buildView(FacesContext context,
        // UIViewRoot)
        // executes.
        facesImplementationServletResponse.flushBuffer();
      } else {
        MimeResponse mimeResponse = (MimeResponse) portletResponse;
        mimeResponse.flushBuffer();
      }
    } else {

      if (manageIncongruities) {
        incongruityContext.responseFlushBuffer();
      } else {
        throw new IllegalStateException();
      }
    }
  }
Example #8
0
  /**
   * This is Wicket's main method to execute a request
   *
   * @param request
   * @param response
   * @param chain
   * @return false, if the request could not be processed
   * @throws IOException
   * @throws ServletException
   */
  boolean processRequest(
      ServletRequest request, final ServletResponse response, final FilterChain chain)
      throws IOException, ServletException {
    final ThreadContext previousThreadContext = ThreadContext.detach();

    // Assume we are able to handle the request
    boolean res = true;

    final ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader();
    final ClassLoader newClassLoader = getClassLoader();

    try {
      if (previousClassLoader != newClassLoader) {
        Thread.currentThread().setContextClassLoader(newClassLoader);
      }

      HttpServletRequest httpServletRequest = (HttpServletRequest) request;
      HttpServletResponse httpServletResponse = (HttpServletResponse) response;

      // Make sure getFilterPath() gets called before checkIfRedirectRequired()
      String filterPath = getFilterPath(httpServletRequest);

      if (filterPath == null) {
        throw new IllegalStateException("filter path was not configured");
      }

      if (shouldIgnorePath(httpServletRequest)) {
        log.debug("Ignoring request {}", httpServletRequest.getRequestURL());
        if (chain != null) {
          chain.doFilter(request, response);
        }
        return false;
      }

      String redirectURL = checkIfRedirectRequired(httpServletRequest);
      if (redirectURL == null) {
        // No redirect; process the request
        ThreadContext.setApplication(application);

        WebRequest webRequest = application.createWebRequest(httpServletRequest, filterPath);
        WebResponse webResponse = application.createWebResponse(webRequest, httpServletResponse);

        RequestCycle requestCycle = application.createRequestCycle(webRequest, webResponse);
        if (!requestCycle.processRequestAndDetach()) {
          if (chain != null) {
            chain.doFilter(request, response);
          }
          res = false;
        } else {
          webResponse.flush();
        }
      } else {
        if (Strings.isEmpty(httpServletRequest.getQueryString()) == false) {
          redirectURL += "?" + httpServletRequest.getQueryString();
        }

        try {
          // send redirect - this will discard POST parameters if the request is POST
          // - still better than getting an error because of lacking trailing slash
          httpServletResponse.sendRedirect(httpServletResponse.encodeRedirectURL(redirectURL));
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
    } finally {
      ThreadContext.restore(previousThreadContext);

      if (newClassLoader != previousClassLoader) {
        Thread.currentThread().setContextClassLoader(previousClassLoader);
      }

      if (response.isCommitted()) {
        response.flushBuffer();
      }
    }
    return res;
  }
Example #9
0
 public void flushBuffer() throws IOException {
   response.flushBuffer();
 }
 @Override
 public void onStartAsync(AsyncEvent event) throws IOException {
   ServletResponse resp = event.getAsyncContext().getResponse();
   resp.getWriter().write("onStartAsync-");
   resp.flushBuffer();
 }
Example #11
0
  /** @see javax.faces.context.ExternalContext#responseFlushBuffer() */
  @Override
  public void responseFlushBuffer() throws IOException {

    response.flushBuffer();
  }