Hibernate Icefaces outputresource在项目重建之前返回错误500

Hibernate Icefaces outputresource在项目重建之前返回错误500,hibernate,jsf,liferay,icefaces,icefaces-3,Hibernate,Jsf,Liferay,Icefaces,Icefaces 3,当我试图使用ice:outputResource从服务器(Liferay jsf2.0)下载文件时,我遇到了一些奇怪的问题 使用相同的代码、页面和文件,但outputresource将抛出错误代码500,直到我重建我的项目,重建后可以下载我的文件 我的场景是(我确信路径和文件存在): 用户上传文件A(将文件存储在临时文件中)-下载确定 用户保存操作(将文件移动到资源文件夹) 用户编辑表单(从资源文件夹重新加载文件)-下载失败(抛出错误500) 重新生成代码,然后上载另一个文件B(与A相同) 用户

当我试图使用ice:outputResource从服务器(Liferay jsf2.0)下载文件时,我遇到了一些奇怪的问题

使用相同的代码、页面和文件,但outputresource将抛出错误代码500,直到我重建我的项目,重建后可以下载我的文件

我的场景是(我确信路径和文件存在):

用户上传文件A(将文件存储在临时文件中)-下载确定

用户保存操作(将文件移动到资源文件夹)

用户编辑表单(从资源文件夹重新加载文件)-下载失败(抛出错误500)

重新生成代码,然后上载另一个文件B(与A相同)

用户编辑表单(重新加载A和B)-下载A正常,但下载B失败

我将资源初始化代码放在(Hibernate)模型中以避免循环:

@Transient
    private Resource ksf_resource;

    public Resource getKsf_resource() {
        if(ksf_resource == null){
            try{                    
                ksf_resource = new CCHCResource("/"+path + "/" , ksf_realname);
                _log.info("path {}, file {}", path, ksf_realname);
                }

            }catch(Exception ex){
                //file not found or server error
                _log.warn("File not found!");
                ksf_resource = null;
            }
        }
        return ksf_resource;
    }
资源代码

public class CCHCResource implements Resource, Serializable {

    private static final long serialVersionUID = -639586497927876085L;


    private String path;
    private String resourceName;
    private InputStream inputStream;
    private final Date lastModified;

    public CCHCResource(String path, String resourceName) {
        this.path = path;
        this.resourceName = resourceName;
        this.lastModified= new Date();
    }

    @Override
    public InputStream open() throws IOException {
        InputStream stream = FacesContext.getCurrentInstance()
                .getExternalContext().getResourceAsStream(path + resourceName);
//      System.out.println("get resource: " + path + resourceName);
        byte[] byteArray = toByteArray(stream);
        inputStream = new ByteArrayInputStream(byteArray);
        return inputStream;
    }

    public static byte[] toByteArray(InputStream input) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        byte[] buf = new byte[4096];
        int len = 0;
        while ((len = input.read(buf)) > -1) output.write(buf, 0, len);
        return output.toByteArray();
    }

    @Override
    public String calculateDigest() {
       return resourceName;
    }

    @Override
    public void withOptions(Options arg0) throws IOException {
    }

    @Override
    public Date lastModified() {
        return lastModified;
    }
}
xhtml


确实不知道为什么,但添加属性shared=“false”可以解决此错误

<ice:outputResource
    image="#{resource['images:isoDownload']}"       
    resource="#{file.ksf_resource}"
    attachment="true"
    fileName="#{file.ksf_displayname}"
    type="application/text"
    label="#{itemtp.ksf_displayname}"
shared="false"/>

<ice:outputResource
    image="#{resource['images:isoDownload']}"       
    resource="#{file.ksf_resource}"
    attachment="true"
    fileName="#{file.ksf_displayname}"
    type="application/text"
    label="#{itemtp.ksf_displayname}"
shared="false"/>