Exemple #1
0
  /** Servlet GET request: handles event requests. */
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    Event event = null;

    try {
      // Event parm identifies event type from the client
      String eventType = Servlets.getParameter(request, P_EVENT);

      // Always must have an event type
      if (eventType == null) {
        Log.warn("Pushlet.doGet(): bad request, no event specified");
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No eventType specified");
        return;
      }
      // Create Event and set attributes from parameters
      event = new Event(eventType);
      for (Enumeration e = request.getParameterNames(); e.hasMoreElements(); ) {
        String nextAttribute = (String) e.nextElement();
        event.setField(nextAttribute, request.getParameter(nextAttribute));
      }
    } catch (Throwable t) {
      // Error creating event
      Log.warn("Pushlet: Error creating event in doGet(): ", t);
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }
    // Handle parsed request
    doRequest(event, request, response);
  }
  @RequestMapping("")
  public String toRolePage(
      @RequestParam(value = "page", defaultValue = "1") int pageNumber,
      @RequestParam(value = "page.size", defaultValue = PAGE_SIZE) int pageSize,
      @RequestParam(value = "sortType", defaultValue = "auto") String sortType,
      Model model,
      ServletRequest request)
      throws UnsupportedEncodingException {

    Map<String, Object> searchParam = Servlets.getParametersStartingWith(request, "search_");
    Page<Role> roles = roleService.getRoleByPage(searchParam, pageNumber, pageSize, sortType);

    model.addAttribute("roles", roles);
    model.addAttribute("sortType", sortType);
    model.addAttribute("sortTypes", sortTypes);
    model.addAttribute("roleActive", "active");

    model.addAttribute(
        "searchParams", Servlets.encodeParameterStringWithPrefix(searchParam, "search_"));

    return "role/roleList";
  }
Exemple #3
0
  /** Sets up the charset for the request and response based on
   * {@link #getPreferredLocale(HttpSession,ServletRequest)}. After setting up, you shall invoke
   * {@link #cleanup} before exiting.
   *
   * <pre><code> final Object old = setup(request, response, null);
   * try {
   *	  ....
   * } finally {
   *    cleanup(request, old);
   * }
   *
   * <p>It is OK to call this method multiple time, since it is smart
   * enough to ignore redundant calls.
   *
   * <p>{@link CharsetFilter} actually use this method to setup
   * the proper charset and locale. By mapping {@link CharsetFilter} to
   * all servlets, the encoding charset could be prepared correctly.
   * However, if you are writing libraries to be as independent of
   * web.xml as possible, you might choose to invoke this method directly.
   *
   * @param sess the session to look for the preferred locale. Ignored if null.
   * @param charset the response's charset. If null or empty,
   * response.setCharacterEncoding won't be called, i.e., the container's
   * default is used.
   * @return an object that must be passed to {@link #cleanup}
   */
  public static final Object setup(
      HttpSession sess, ServletRequest request, ServletResponse response, String charset) {
    if (hasSetup(request)) // processed before?
    return Objects.UNKNOWN;

    final Locale locale = getPreferredLocale(sess, request);
    response.setLocale(locale);
    if (charset != null && charset.length() > 0) {
      try {
        if (Servlets.isServlet24()) {
          response.setCharacterEncoding(charset);
        } else {
          // don't access 2.4 API: setCharacterEncoding, getContentType
          response.setContentType(";charset=" + charset);
        }
      } catch (Throwable ex) {
        try {
          final String v = response.getCharacterEncoding();
          if (!Objects.equals(v, charset))
            log.warn("Unable to set response's charset: " + charset + " (current=" + v + ')', ex);
        } catch (Throwable t) { // just in case
        }
      }
    }

    if (request.getCharacterEncoding() == null) {
      charset = response.getCharacterEncoding();
      try {
        request.setCharacterEncoding(charset);
      } catch (Throwable ex) {
        final String v = request.getCharacterEncoding();
        if (!Objects.equals(v, charset))
          log.warn(
              "Unable to set request's charset: "
                  + charset
                  + " (current="
                  + v
                  + "): "
                  + Exceptions.getMessage(ex));
      }
    }

    markSetup(request, true);
    return Locales.setThreadLocal(locale);
  }
 private InputStream getReport(
     HttpServletRequest request,
     HttpServletResponse response,
     Tab tab,
     TableModel tableModel,
     Integer columnCountLimit)
     throws ServletException, IOException {
   StringBuffer suri = new StringBuffer();
   suri.append("/xava/jasperReport");
   suri.append("?language=");
   suri.append(Locales.getCurrent().getLanguage());
   suri.append("&widths=");
   suri.append(Arrays.toString(getWidths(tableModel)));
   if (columnCountLimit != null) {
     suri.append("&columnCountLimit=");
     suri.append(columnCountLimit);
   }
   response.setCharacterEncoding(XSystem.getEncoding());
   return Servlets.getURIAsStream(request, response, suri.toString());
 }
 @Override
 protected Configuration createConfigurationInstance() {
   Principal principal = (Principal) UserUtils.getPrincipal();
   if (principal == null) {
     return new CKFinderConfig(this.servletConf);
   }
   boolean isView = true; // UserUtils.getSubject().isPermitted("cms:ckfinder:view");
   boolean isUpload = true; // UserUtils.getSubject().isPermitted("cms:ckfinder:upload");
   boolean isEdit = true; // UserUtils.getSubject().isPermitted("cms:ckfinder:edit");
   AccessControlLevel alc = this.getAccessConrolLevels().get(0);
   alc.setFolderView(isView);
   alc.setFolderCreate(isEdit);
   alc.setFolderRename(isEdit);
   alc.setFolderDelete(isEdit);
   alc.setFileView(isView);
   alc.setFileUpload(isUpload);
   alc.setFileRename(isEdit);
   alc.setFileDelete(isEdit);
   //		for (AccessControlLevel a : this.getAccessConrolLevels()){
   //			System.out.println(a.getRole()+", "+a.getResourceType()+", "+a.getFolder()
   //					+", "+a.isFolderView()+", "+a.isFolderCreate()+", "+a.isFolderRename()+",
   // "+a.isFolderDelete()
   //					+", "+a.isFileView()+", "+a.isFileUpload()+", "+a.isFileRename()+", "+a.isFileDelete());
   //		}
   AccessControlUtil.getInstance(this).loadACLConfig();
   try {
     //			Principal principal = (Principal)SecurityUtils.getSubject().getPrincipal();
     //			this.baseURL =
     // ServletContextFactory.getServletContext().getContextPath()+"/userfiles/"+principal+"/";
     this.baseURL =
         FileUtils.path(
             Servlets.getRequest().getContextPath() + Global.USERFILES_BASE_URL + principal + "/");
     this.baseDir =
         FileUtils.path(
             Global.getUserfilesBaseDir() + Global.USERFILES_BASE_URL + principal + "/");
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
   return new CKFinderConfig(this.servletConf);
 }
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // 取得参数
    String contentPath = request.getParameter("contentPath");
    if (StringUtils.isBlank(contentPath)) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, "contentPath parameter is required.");
      return;
    }

    // 获取请求内容的基本信息.
    ContentInfo contentInfo = getContentInfo(contentPath);

    // 根据Etag或ModifiedSince Header判断客户端的缓存文件是否有效, 如仍有效则设置返回码为304,直接返回.
    if (!Servlets.checkIfModifiedSince(request, response, contentInfo.lastModified)
        || !Servlets.checkIfNoneMatchEtag(request, response, contentInfo.etag)) {
      return;
    }

    // 设置Etag/过期时间
    Servlets.setExpiresHeader(response, Servlets.ONE_YEAR_SECONDS);
    Servlets.setLastModifiedHeader(response, contentInfo.lastModified);
    Servlets.setEtag(response, contentInfo.etag);

    // 设置MIME类型
    response.setContentType(contentInfo.mimeType);

    // 设置弹出下载文件请求窗口的Header
    if (request.getParameter("download") != null) {
      Servlets.setFileDownloadHeader(request, response, contentInfo.fileName);
    }

    // 构造OutputStream
    OutputStream output;
    if (checkAccetptGzip(request) && contentInfo.needGzip) {
      // 使用压缩传输的outputstream, 使用http1.1 trunked编码不设置content-length.
      output = buildGzipOutputStream(response);
    } else {
      // 使用普通outputstream, 设置content-length.
      response.setContentLength(contentInfo.length);
      output = response.getOutputStream();
    }

    // 高效读取文件内容并输出,然后关闭input file
    FileUtils.copyFile(contentInfo.file, output);
    output.flush();
  }