0

我在使用 Eclipse Kepler 的 Google App Engine 项目 (api-1.0-sdk-1.8.4) 中使用 Mojarra 2.2.0 和 tomahawk12-1.1.14 (t:inputFileUpload)。

该项目在从 Eclipse 本地运行时运行良好,但如果在尝试上传文件时部署到 Google App Engine 会出现以下错误:

/faces/tmotifs.xhtml
java.lang.NullPointerException
    at java.io.File.<init>(File.java:290)
    at org.apache.myfaces.webapp.filter.MultipartRequestWrapper.parseRequest(MultipartRequestWrapper.java:141)
    at org.apache.myfaces.webapp.filter.MultipartRequestWrapper.getParameter(MultipartRequestWrapper.java:299)
    at com.sun.faces.context.RequestParameterMap.get(RequestParameterMap.java:75)
    at com.sun.faces.context.RequestParameterMap.get(RequestParameterMap.java:56)
    at java.util.Collections$UnmodifiableMap.get(Collections.java:1339)
    ...

我在 tmotifs.xhtml 中使用文件上传组件,如下所示:

<h:form enctype="multipart/form-data">
    <t:inputFileUpload value="#{trainingBean.uploadedFile}"
        accept="text/x-fasta" requiredMessage="A fasta file must be selected" />
    <h:commandButton value="Refresh" actionListener="#{trainingBean.upload}" />
....

支持 bean 如下所示:

@ManagedBean
@SessionScoped
public class TrainingBean implements Serializable {
    private static final long serialVersionUID = 1L;
    private UploadedFile uploadedFile;

    public UploadedFile getUploadedFile() {
        return uploadedFile;
    }

    public void setUploadedFile(UploadedFile uploadedFile) {
        this.uploadedFile = uploadedFile;
    }

    public void upload() {
        if( uploadedFile == null ) {
            refresh();
            return;
        }

        this.inputList.clear();
        try {
            Reader rd = new InputStreamReader(uploadedFile.getInputStream());
            inputGroupList = InputGroup.readEntries(rd); 
            rd.close();
            for( InputGroup p : inputGroupList )
                this.inputList.addAll(p.getMotifs());
            uploadError = null;
            inputFileName = uploadedFile.getName();
        } catch (IOException e) {
            uploadError = e.getMessage();
            e.printStackTrace();
        } catch( InvalidSequenceException e ) {
            uploadError = e.getMessage();
            e.printStackTrace();
        }

        refresh();
    }
...

和 web.xml:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<web-app
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    version="2.5"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>JavaServerFaces</display-name>    

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <!--<param-value>client</param-value>-->
        <param-value>server</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>
    <context-param>  
        <param-name>com.sun.faces.expressionFactory</param-name>  
        <param-value>com.sun.el.ExpressionFactoryImpl</param-value>  
    </context-param>
    <!-- Disable use of threading for single-threaded environments such as the Google AppEngine. -->
    <context-param>
        <param-name>com.sun.faces.enableThreading</param-name>
        <param-value>false</param-value>
    </context-param>    
    <!-- Change to "Production" when you are ready to deploy -->
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
        <param-value>true</param-value>
    </context-param>

    <!-- ***** Specify session timeout of thirty (30) minutes. ***** -->
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

    <!-- Welcome page -->
    <welcome-file-list>
        <welcome-file>faces/home.xhtml</welcome-file>
    </welcome-file-list>

    <!-- JSF mapping -->
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
        <url-pattern>*.jsf</url-pattern>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

    <!-- MyFaces Tomahawk -->
    <filter>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
        <init-param>
            <param-name>uploadMaxFileSize</param-name>
            <param-value>20m</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
    <filter-mapping>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
    </filter-mapping>

    <error-page>
        <exception-type>javax.faces.application.ViewExpiredException</exception-type>
        <location>/faces/home.xhtml</location>
    </error-page>

    <!-- System -->
    <servlet>
        <servlet-name>SystemServiceServlet</servlet-name>
        <servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
        <init-param>
            <param-name>services</param-name>
            <param-value/>
        </init-param>
    </servlet>  
    <servlet-mapping>
        <servlet-name>SystemServiceServlet</servlet-name>
        <url-pattern>/_ah/spi/*</url-pattern>
    </servlet-mapping>

    <listener>
        <listener-class>es.ehu.grk.wregex.gae.ServletListener</listener-class>
    </listener>
</web-app>

所以我的问题是,我错过了什么吗?为什么 t:inputFileUpload 在本地 GAE 服务器上运行时工作正常,但在部署时却不行?

任何帮助/方向都会受到欢迎。先感谢您!

4

1 回答 1

1

最后,我按照GAE 上 JSF 文件上传的说明,在高级模式下使用 PrimeFaces 的 fileUpload 解决了这个问题(简单文件上传不起作用),但我没有在支持 bean 中使用 BlobUtils(现在已弃用?),而是从记忆为:

public void uploadedFileEvent(FileUploadEvent event) {
    Reader rd = new InputStreamReader(new ByteArrayInputStream(event.getFile().getContents()));
    //...
}
于 2013-10-09T09:17:49.217 回答