コード例 #1
0
  protected boolean isWrap(HttpServletResponse response) {
    if (response instanceof WebLogicIncludeServletResponse) {
      return false;
    }

    boolean wrap = false;

    HttpServletResponseWrapper previousResponseWrapper = null;

    while (response instanceof HttpServletResponseWrapper) {
      if (!wrap && (response instanceof MetaInfoCacheServletResponse)) {
        wrap = true;
      }

      HttpServletResponseWrapper responseWrapper = (HttpServletResponseWrapper) response;

      response = (HttpServletResponse) responseWrapper.getResponse();

      if (responseWrapper instanceof WebLogicIncludeServletResponse) {
        previousResponseWrapper.setResponse(response);
      }

      previousResponseWrapper = responseWrapper;
    }

    return wrap;
  }
コード例 #2
0
  /**
   * {@inheritDoc}
   *
   * @see javax.servlet.ServletResponseWrapper#flushBuffer()
   */
  @Override
  public void flushBuffer() throws IOException {
    if (out != null) {
      out.flush();
      out.close();
      out = null;
    }

    try {
      if (isCommitted()) return;

      if (os != null) {
        // Get the buffered content
        byte[] content = os.getContent();

        // Set content-related headers
        setContentLength(content.length);

        // Write the buffered content to the underlying output stream
        super.getOutputStream().write(content);
      }

      // Flush the underlying buffer
      super.flushBuffer();

    } finally {
      os = null;
    }
  }
コード例 #3
0
ファイル: GzipFilter.java プロジェクト: yuri0x7c1/opentaps-1
 /** {@inheritDoc} */
 public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
     throws IOException, ServletException {
   HttpServletRequest request = (HttpServletRequest) req;
   HttpServletResponseWrapper response =
       new HttpServletResponseWrapper((HttpServletResponse) resp);
   String encoding = request.getHeader("Accept-Encoding");
   boolean supportsGzip = false;
   // Now, check to see if the browser supports the GZIP compression
   if (encoding != null) {
     if (encoding.toLowerCase().indexOf("gzip") > -1) supportsGzip = true;
   }
   Debug.log(
       "supportsGzip : "
           + supportsGzip
           + ", encoding : "
           + encoding
           + ", requestURL : "
           + request.getRequestURL());
   if (supportsGzip) {
     // add content encoding
     response.setHeader("Content-Encoding", "gzip");
     GzipResponse compressionResponse = new GzipResponse(response);
     chain.doFilter(request, compressionResponse);
     compressionResponse.close();
   } else {
     chain.doFilter(req, resp);
   }
 }
コード例 #4
0
  @Override
  public void setContentType(String contentType) {
    super.setHeader("Expires", "-1");
    super.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    logger.debug("Header changed successfully");

    super.setContentType(contentType);
  }
コード例 #5
0
ファイル: HtmlComponent.java プロジェクト: juanmadryn/web-db
 /** This method will encode a url to support URL rewriting */
 public String encodeURL(String url) {
   if (url == null) return null;
   if (url.toLowerCase().startsWith("javascript:")) return url;
   if (!getPage().getEncodeURLs()) {
     String logicalName = getSiteMapEntryName(url);
     if (logicalName == null) return url;
     else {
       url = translateSiteMapURL(url);
       SiteMap m = getPage().getSiteMap();
       if (m != null) return m.addJavaScriptToUrl(logicalName, url);
       else return url;
     }
   }
   if (!getPage().isWMLMaintained()) {
     HttpServletRequest req = getPage().getCurrentRequest();
     HttpServletResponse res = getPage().getCurrentResponse();
     String logicalName = getSiteMapEntryName(url);
     if (logicalName == null) return HttpServletResponseWrapper.encodeURL(url, req, res);
     else {
       String translatedURL = translateSiteMapURL(url);
       String encodedURL = HttpServletResponseWrapper.encodeURL(translatedURL, req, res);
       SiteMap m = getPage().getSiteMap();
       if (m != null) return m.addJavaScriptToUrl(logicalName, encodedURL);
       else return encodedURL;
     }
   } else {
     url = translateSiteMapURL(url);
     HttpServletRequest req = getPage().getCurrentRequest();
     HttpServletResponse res = getPage().getCurrentResponse();
     if (HttpServletResponseWrapper.encodeURL(url, req, res).indexOf(';') >= 0) {
       if (url.indexOf('?') >= 0)
         if (url.indexOf(
                 PageTag.getSessionIdentifier()
                     + "="
                     + PageTag.getWmlSessId(getPage().getSession()))
             < 0) {
           if (url.endsWith("&amp;") || url.endsWith("?"))
             return url
                 + PageTag.getSessionIdentifier()
                 + "="
                 + PageTag.getWmlSessId(getPage().getSession());
           else
             return url
                 + "&amp;"
                 + PageTag.getSessionIdentifier()
                 + "="
                 + PageTag.getWmlSessId(getPage().getSession());
         } else return url;
       else
         return url
             + "?"
             + PageTag.getSessionIdentifier()
             + "="
             + PageTag.getWmlSessId(getPage().getSession());
     } else return url;
   }
 }
コード例 #6
0
 @Override
 public void setHeader(String name, String value) {
   if (name.equals(LOCATION)) {
     String newLocation = mapLocation(value.trim());
     super.setHeader(name, newLocation);
   } else {
     super.setHeader(name, value);
   }
 }
コード例 #7
0
  /**
   * Flush OutputStream or PrintWriter
   *
   * @throws IOException
   */
  @Override
  public void flushBuffer() throws IOException {

    // PrintWriter.flush() does not throw exception
    if (this.printWriter != null) {
      this.printWriter.flush();
    }

    IOException exception1 = null;
    try {
      if (this.gzipOutputStream != null) {
        this.gzipOutputStream.flush();
      }
    } catch (IOException e) {
      exception1 = e;
    }

    IOException exception2 = null;
    try {
      super.flushBuffer();
    } catch (IOException e) {
      exception2 = e;
    }

    if (exception1 != null) throw exception1;
    if (exception2 != null) throw exception2;
  }
コード例 #8
0
ファイル: TestFilter.java プロジェクト: kantega/superheroic
 @Override
 public void setDateHeader(String name, long date) {
   if (name.equals("Last-Modified")) {
     return;
   }
   super.setDateHeader(name, date);
 }
コード例 #9
0
ファイル: TestFilter.java プロジェクト: kantega/superheroic
 @Override
 public void setStatus(int i) {
   if (i != 200) {
     wrapped = false;
   }
   super.setStatus(i);
 }
コード例 #10
0
ファイル: RackFilter.java プロジェクト: kim/jruby-rack
 @Override
 public void setStatus(int status, String message) {
   this.status = status;
   if (!isError()) {
     super.setStatus(status, message);
   }
 }
コード例 #11
0
ファイル: RackFilter.java プロジェクト: kim/jruby-rack
 @Override
 public void setStatus(int status) {
   this.status = status;
   if (!isError()) {
     super.setStatus(status);
   }
 }
コード例 #12
0
 /** Resets the response. */
 public void reset() {
   super.reset();
   cookies.clear();
   headers.clear();
   statusCode = SC_OK;
   contentType = null;
   contentLength = 0;
 }
コード例 #13
0
  public final void setContentType(String contentType) {
    // If something tries to change the content type of the response by setting a content type of
    // "text/html; charset=...", just ignore it. This happens in Tomcat and Jetty JSPs.
    if (StringUtils.startsWith(contentType, "text/html")
        && contentType.length() > "text/html".length()) {
      return;
    }

    // Ensure that the charset parameter is appended if we're called with just "text/html".
    // This happens on WebLogic.
    if (StringUtils.trimToEmpty(contentType).equals("text/html")) {
      super.setContentType(contentType + ";charset=" + getResponse().getCharacterEncoding());
      return;
    }

    // for all other content types, just set the value
    super.setContentType(contentType);
  }
コード例 #14
0
ファイル: GZIPFilter.java プロジェクト: jongillies/pwm
 @Override
 public void flushBuffer() throws IOException {
   if (printWriter != null) {
     printWriter.flush();
   }
   if (outputStream != null) {
     outputStream.flush();
   }
   super.flushBuffer();
 }
コード例 #15
0
  @Override
  public void sendRedirect(String redirect) throws IOException {
    String portalURL = PortalUtil.getPortalURL(_request);

    if (redirect.charAt(0) == CharPool.SLASH) {
      if (Validator.isNotNull(portalURL)) {
        redirect = portalURL.concat(redirect);
      }
    }

    if (!CookieKeys.hasSessionId(_request) && redirect.startsWith(portalURL)) {

      redirect = PortalUtil.getURLWithSessionId(redirect, _request.getSession().getId());
    }

    _request.setAttribute(AbsoluteRedirectsResponse.class.getName(), redirect);

    super.sendRedirect(redirect);
  }
コード例 #16
0
  /**
   * Flush OutputStream or PrintWriter
   *
   * @throws IOException
   */
  @Override
  public void flushBuffer() throws IOException {

    // PrintWriter.flush() does not throw exception
    if (this.printWriter != null) {
      this.printWriter.flush();
    }

    if (this.gzipOutputStream != null) {
      this.gzipOutputStream.flush();
    }

    // doing this might leads to response already committed exception
    // when the PageInfo has not yet built but the buffer already flushed
    // Happens in Weblogic when a servlet forward to a JSP page and the forward
    // method trigger a flush before it forwarded to the JSP
    // disableFlushBuffer for that purpose is 'true' by default
    if (!disableFlushBuffer) {
      super.flushBuffer();
    }
  }
コード例 #17
0
 public void setStatus(int code, String msg) {
   statusCode = code;
   super.setStatus(code);
 }
コード例 #18
0
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String param = request.getParameter("id");
    // responseWrapper importante per includere header ********************************************
    HttpServletResponseWrapper responseWrapper =
        new HttpServletResponseWrapper(response) {
          private final StringWriter sw = new StringWriter();

          @Override
          public PrintWriter getWriter() throws IOException {
            return new PrintWriter(sw);
          }

          @Override
          public String toString() {
            return sw.toString();
          }
        };
    request.getRequestDispatcher("/includes/header.jsp").include(request, responseWrapper);
    // **************************************************************************************

    String res = "";
    res +=
        "<html>\n"
            + "<head>"
            + "<meta charset=\"utf-8\">\n"
            + "    <title>Cinema Multisala</title>\n"
            + "    <link rel=\"stylesheet\" href=\"http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css\">\n"
            + "    <link href=\"CSS/mycss.css\" rel=\"stylesheet\" type=\"text/css\">\n"
            + "\n"
            + "    <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js\"></script>\n"
            + "    <script src=\"http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js\"></script>\n"
            + "</head>\n"
            + "<body>";

    res += "<div class=\"col-md-1 sidebar\"></div>";
    res += "<div class=\"col-md-10\">";

    res += responseWrapper.toString();

    if (param != null) {
      Integer tmp = Integer.parseInt(param);
      int idfilm = tmp.intValue();

      MultisalaDAO dao = new MultisalaDAO();
      List<Spettacolo> spettacoli = dao.getSpettacoloByFilmId(idfilm);

      Date date = new Date();
      for (int i = 0; i < spettacoli.size(); i++) {
        // ceck se gli spettacoli sono già stati proiettati
        if (new Timestamp(date.getTime()).before(spettacoli.get(i).getDataOra())) {
          res += "<div class=\"row text-center\">";
          res += spettacoli.get(i).getDataOraToString();
          res +=
              "<a href=\"http://localhost:8080/CinemaMultisala_war_exploded/prenotation/spett?id="
                  + spettacoli.get(i).getIdSpettacolo()
                  + "\">"
                  + "<button type=\"button\" class=\"btn btn-primary left\">Prenota</button>"
                  + "</a>"
                  + "</div>"
                  + "</br>";
        }
      }
    }

    res += "\n" + "<footer>\n" + "</footer>\n";

    res += "</div>";
    res += "<div class=\"col-md-1 sidebar\"></div>";
    res += "</body>\n" + "</html>";

    PrintWriter out = response.getWriter();
    out.println(res);
  }
コード例 #19
0
  @Override
  public void setResponse(Object response) {

    // Assume that the JSP_AFTER_VIEW_CONTENT feature is deactivated.
    facesImplementationServletResponse = null;

    // If JSP AFTER_VIEW_CONTENT processing has been activated by the bridge's
    // ViewDeclarationLanguageJspImpl#buildView(FacesContext, UIViewRoot) method, then wrap the
    // specified response
    // object with a ServletResponse that is able to handle the AFTER_VIEW_CONTENT feature. This is
    // necessary
    // because the Mojarra JspViewHandlingStrategy#getWrapper(ExternalContext) method has a Servlet
    // API dependency
    // due to explicit casts to HttpServletResponse.
    if (bridgeContext.isProcessingAfterViewContent()) {

      // If the specified response is of type HttpServletResponseWrapper, then it is almost certain
      // that Mojarra's
      // JspViewHandlingStrategy#executePageToBuildView(FacesContext, UIViewRoot) method is
      // attempting to wrap the
      // bridge's response object (that it originally got by calling the
      // ExternalContext#getResponse() method)
      // with it's ViewHandlerResponseWrapper, which extends HttpServletResponseWrapper.
      if (response instanceof HttpServletResponseWrapper) {

        this.facesImplementationServletResponse = (ServletResponse) response;

        HttpServletResponseWrapper httpServletResponseWrapper =
            (HttpServletResponseWrapper) response;
        ServletResponse wrappedServletResponse = httpServletResponseWrapper.getResponse();

        if (wrappedServletResponse instanceof BridgeAfterViewContentResponse) {
          BridgeAfterViewContentResponse bridgeAfterViewContentPreResponse =
              (BridgeAfterViewContentResponse) wrappedServletResponse;
          PortletResponse wrappedPortletResponse = bridgeAfterViewContentPreResponse.getWrapped();

          BridgeWriteBehindSupportFactory bridgeWriteBehindSupportFactory =
              (BridgeWriteBehindSupportFactory)
                  FactoryExtensionFinder.getFactory(BridgeWriteBehindSupportFactory.class);
          BridgeWriteBehindResponse bridgeWriteBehindResponse =
              bridgeWriteBehindSupportFactory.getBridgeWriteBehindResponse(
                  (MimeResponse) wrappedPortletResponse, facesImplementationServletResponse);

          // Note: See comments in BridgeContextImpl#dispatch(String) regarding Liferay's inability
          // to
          // accept a wrapped response. This is indeed supported in Pluto.
          this.portletResponse = (PortletResponse) bridgeWriteBehindResponse;
        } else {

          // Since we're unable to determine the wrapped PortletResponse, the following line will
          // throw an
          // intentional ClassCastException. Note that this case should never happen.
          this.portletResponse = (PortletResponse) response;
        }
      }

      // Otherwise, the specified response is of type BridgeAfterViewContentResponse, then Mojarra's
      // JspViewHandlingStrategy#executePageToBuildView(FacesContext, UIViewRoot) method is trying
      // to restore the
      // bridge's response object that it originally got from calling the
      // ExternalContext#getResponse() method
      // prior to wrapping with it's ViewHandlerResponseWrapper.
      else if (response instanceof BridgeAfterViewContentResponse) {
        BridgeAfterViewContentResponse bridgeAfterViewContentResponse =
            (BridgeAfterViewContentResponse) response;
        this.portletResponse = bridgeAfterViewContentResponse.getWrapped();
      }

      // Otherwise, assume that the specified response is a PortletResponse.
      else {
        this.portletResponse = (PortletResponse) response;
      }

    }

    // Otherwise, since the JSF AFTER_VIEW_CONTENT feature is not activated, assume that the
    // specified response is
    // a PortletResponse.
    else {
      this.portletResponse = (PortletResponse) response;
    }

    try {
      boolean requestChanged = false;
      boolean responseChanged = true;
      preInitializeObjects(requestChanged, responseChanged);
    } catch (Exception e) {
      logger.error(e);
    }
  }
コード例 #20
0
 @Override
 public void setStatus(final int status) {
   super.setStatus(status);
   this.status = status;
 }
コード例 #21
0
 @Override
 public void sendError(final int status) throws IOException {
   super.sendError(status);
   this.status = status;
 }
コード例 #22
0
 public void setStatus(int statusCode) {
   detectErrorResponse(statusCode);
   super.setStatus(statusCode);
 }
コード例 #23
0
 public void setStatus(int statusCode, String message) {
   detectErrorResponse(statusCode);
   super.setStatus(statusCode, message);
 }
コード例 #24
0
  /**
   * Set the response that we are wrapping.
   *
   * @param response The new wrapped response
   */
  void setResponse(HttpServletResponse response) {

    super.setResponse(response);
  }
コード例 #25
0
 public void sendError(int errorCode, String message) throws IOException {
   detectErrorResponse(errorCode);
   super.sendError(errorCode, message);
 }
コード例 #26
0
 public void reset() {
   super.reset();
   statusCode = SC_OK;
 }
コード例 #27
0
 public void sendRedirect(String string) throws IOException {
   statusCode = HttpServletResponse.SC_MOVED_TEMPORARILY;
   super.sendRedirect(string);
 }
コード例 #28
0
 public void sendError(int i, String string) throws IOException {
   statusCode = i;
   super.sendError(i, string);
 }
コード例 #29
0
 public void sendError(int i) throws IOException {
   statusCode = i;
   super.sendError(i);
 }
コード例 #30
0
 public void setStatus(int code) {
   statusCode = code;
   super.setStatus(code);
 }