org.apache.struts2.util.TokenHelper Java Examples

The following examples show how to use org.apache.struts2.util.TokenHelper. 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: UploadAction.java    From Mall-Server with MIT License 5 votes vote down vote up
public String upload() {
    if (uploadFile == null) {
        jsonResult = ResponseTemplate.error(-1, "No file!");
        return SUCCESS;
    }

    // 1.获取文件的保存路径
    String basePath = ServletActionContext.getServletContext().getRealPath("/uploads");
    File basePathFile = new File(basePath);
    if (!basePathFile.exists()) {
        basePathFile.mkdirs();
    }

    // 2.把文件名UUID
    String GUIDFileName = TokenHelper.generateGUID();
    if ("image/png".equals(uploadFileContentType)) {
         GUIDFileName = GUIDFileName + ".png";
    } else {
        GUIDFileName = GUIDFileName + ".jpg";
    }

    // 3.保存文件
    // 复制:临时文件还在,浪费服务器磁盘空间
    //FileUtils.copyFile(visitFile, new File(file,GUIDFileName));
    // 剪切:把临时文件重命名到指定位置(比较好)
    uploadFile.renameTo(new File(basePathFile, GUIDFileName));

    // 4. 返回结果,将文件的保存路径返回
    Map<String, Object> map = new HashMap<>();
    map.put("filePath", "uploads/" + GUIDFileName);
    jsonResult = ResponseTemplate.success(map);
    return SUCCESS;
}
 
Example #2
Source File: TestCustomTokenInterceptor.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected ActionInvocation prepareAction() throws Exception {
    this.setUserOnSession("admin");
    this.initAction("/do/User", "list");
    String token = TokenHelper.setToken();
    super.addParameter(TokenHelper.TOKEN_NAME_FIELD, new String[]{TokenHelper.DEFAULT_TOKEN_NAME});
    super.addParameter(TokenHelper.DEFAULT_TOKEN_NAME, new String[]{token});
    this.getActionContext().setParameters(HttpParameters.create(this.getRequest().getParameterMap()).build());
    return super.getActionInvocation();
}
 
Example #3
Source File: TestIdeaFrontAction.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void setToken() {
	String token = TokenHelper.generateGUID();
	ActionContext.getContext().setSession(new HashMap<String, Object>());
	String tokenName = "test_tokenName";
	String tokenSessionAttributeName = TokenHelper.buildTokenSessionAttributeName(tokenName);
	ActionContext.getContext().getSession().put(tokenSessionAttributeName, token);
	this.addParameter(TokenHelper.TOKEN_NAME_FIELD, new String[]{tokenName});
	this.addParameter(tokenName, new String[]{token});
}
 
Example #4
Source File: TestCommentFrontEndAction.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void setToken() {
    String token = TokenHelper.generateGUID();
    ActionContext.getContext().setSession(new HashMap<String, Object>());
    String tokenName = "test_tokenName";
    String tokenSessionAttributeName = TokenHelper.buildTokenSessionAttributeName(tokenName);
    ActionContext.getContext().getSession().put(tokenSessionAttributeName, token);
    this.addParameter(TokenHelper.TOKEN_NAME_FIELD, new String[]{tokenName});
    this.addParameter(tokenName, new String[]{token});
}