AWS 插件扩展开发参考指南

下载生成的临时文件示例

  • 开发tmpDC处理器,为该应用存放临时文件(如上节你已完成,不再重复)
  • 用程序生成一个文件并下载,下载完毕后删除这个临时文件

源码见扩展插件概念验证应用

//本示例的文件存储目录
%AWS-HOME%/doccenter/com.actionsoft.apps.poc.plugin/tmp/

TmpFileProcessor

com.actionsoft.apps.poc.plugin.dc.TmpFileProcessor

package com.actionsoft.apps.poc.plugin.dc;

import java.util.Map;

import com.actionsoft.bpms.server.fs.AbstFileProcessor;
import com.actionsoft.bpms.server.fs.DCContext;
import com.actionsoft.bpms.server.fs.FileProcessorListener;
import com.actionsoft.bpms.server.fs.dc.DCMessage;
import com.actionsoft.bpms.util.UtilFile;

public class TmpFileProcessor extends AbstFileProcessor implements FileProcessorListener {

    public void downloadComplete(Map<String, Object> param) {
        DCContext context = (DCContext) param.get("DCContext");
        if (context.getGroupValue().equals("crm") && context.getFileValue().equals("auto-report")) {
            // 删除这个临时文件
            new UtilFile(context.getFilePath()).delete();
        }
    }
}

生成临时文件

com.actionsoft.apps.poc.plugin.web.SampleWeb#getDCSample3Home

public String getDCSample3Home() {
    long time = System.currentTimeMillis();
    // 生成一个临时文件,供用户下载
    String appId = "com.actionsoft.apps.poc.plugin";
    String repositoryName = "tmp";
    String groupValue = "crm";
    String fileValue = "auto-report";
    String fileName = time + ".txt";
    DCPluginProfile dcProfile = SDK.getDCAPI().getDCProfile(appId, repositoryName);
    DCContext dcContext = new DCContext(getContext(), dcProfile, appId, groupValue, fileValue, fileName);
    File dirFile = new File(dcContext.getPath());
    File tmpFile = new File(dcContext.getFilePath());
    // 模拟处理,返回一段文字
    String data = "Hello AWS PaaS! currentTimeMillis:" + time;
    InputStream in = null;
    try {
        if (tmpFile.exists()) {
            tmpFile.delete();
            tmpFile.createNewFile();
        } else {
            if (!dirFile.exists()) {
                dirFile.mkdirs();
            }
            tmpFile.createNewFile();
        }
        in = new ByteArrayInputStream(data.getBytes());
        boolean isWrited = SDK.getDCAPI().write(in, dcContext);
        if (!isWrited) {
            throw new AWSException("Write Error!");
        }
    } catch (Exception e) {
        throw new AWSException(e);
    } finally {
        try {
            if (in != null)
                in.close();
        } catch (Exception e) {
        }
    }
    Map<String, Object> macroLibraries = new LinkedHashMap<String, Object>();
    macroLibraries.put("sid", getContext().getSessionId());
    macroLibraries.put("tip", time);
    macroLibraries.put("url", dcContext.getDownloadURL());
    return HtmlPageTemplate.merge("com.actionsoft.apps.poc.plugin", "dc-sample3.htm", macroLibraries);
}

验证

进入AWS CONSOLE > 应用管理并打开你的应用,在部署中点击DCSample3,点击下载按钮得到如下相似内容的.txt文件

Hello AWS PaaS! currentTimeMillis:1416735361470


Seven
 010-62962343-690
 liujx@actionsoft.com.cn
感谢您对该文档的关注!如果您对当前页面内容有疑问或好的建议,请与我联系。如果您需要解答相关技术问题请登录AWS客户成功社区