0

我使用 Grails 2.0.4 构建了我的应用程序并在 Jetty 中对其进行了测试。在 Jetty 中一切正常,但是当我部署到 Glassfish 时,当我尝试在我的操作中分配一个文件时,我得到了一个 npe。为什么在 glassfish 上上传的文件为空,但使用码头可以?

def  uploadedFile = request.getFile('name_of_file')

Firebug 显示 http 请求正在获取文件。这是来自 Firebug 的多部分表单数据 Post 请求的开头:

**name_of_file**    %PDF-1.4 %âãÏÓ 5 0 obj <</Length 2712/Filter/FlateDecode>>stream x[]oÜ6}_A /ÛÝZD}öM+¶ñÌT#'5¶ÂuÄeolÅþüÔ¥D^êòÑ(PÏuyι<¤4²úuuÚ¬|æ!k>®ÊfõëêëÊ÷|ÆìïUÈ~ÿñ

因此,看起来文件信息在部署时在客户端被参数化,但没有进入控制器。

我的控制器代码:

 def sample(){

    if (params.ID == null) return 

    def sampleInstance = new Sample(params)// new sample
    if (sampleInstance.validate()) { // try to validate
        def  uploadedFile = request.getFile('name_of_file')// see if there is a file to upload
        session.uploadedFile = [
            originalFile: uploadedFile.originalFilename
        ]



        if (uploadedFile != null) { // is there a file? 
            sampleInstance.filepath =${uploadedFile.originalFilename}" // save the original filename

        }
        if (params.ageUnk){
           sampleInstance.sampleAge = null;
        }
        if (!params.ageUnk){
        def patients_age_in_years = (Integer.parseInt(params.patientYrs) * 12)

        def patients_age_in_months = Integer.parseInt(params.patientMos)

        def patients_total_age_in_months = (patients_age_in_years + patients_age_in_months) 

        sampleInstance.sampleAge = patients_total_age_in_months
        }

        sampleInstance.enteredby = springSecurityService.currentUser.id 
        sampleInstance.save()// save the sample in the database

        redirect( action:'sample', model:[sampleInstance:sampleInstance, checkDate:today, date: now])

    }else{
         [sampleInstance:sampleInstance, checkDate:today, date: now]
    }

}

除文件外,所有参数都可以通过。这是我的 gsp 表格:

<g:uploadForm action="sample">
<table>
  <tr>
    <td align="right"><br><b> Comments: &nbsp</b></td>
    <td><br><g:textField name="nameComments" value="" style='width: 200px'/></td>
  </tr>
    <td align="right"><br><b>ID: &nbsp</b></td>
    <td><br><g:textField name="nameID" value="" /></td>
  </tr>
  <tr>
    <td align="right"><br><b>Upload File: &nbsp</b></td>
    <td><br><input type='file' name='name_of_file' /></td>
  </tr>
  <tr>
    <td align="right"></td>
    <td><g:submitButton name="submit" value="Submit" /></td>
  </tr>
</table> 

</g:uploadForm>

堆栈跟踪:

java.lang.NullPointerException: Cannot get property 'originalFilename' on null object 
at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:56) 
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:156) 
at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:44) 
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227) 
at lims.SubmitSampleController.sample(SubmitSampleController.groovy:27) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:601) 
at org.codehaus.groovy.grails.web.servlet.mvc.MixedGrailsControllerHelper.invoke(MixedGrailsControllerHelper.java:67) 
at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleAction(AbstractGrailsControllerHelper.java:330) 
at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.executeAction(AbstractGrailsControllerHelper.java:211) 
at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleURI(AbstractGrailsControllerHelper.java:177) 
at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleURI(AbstractGrailsControllerHelper.java:116) 
at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:72) 
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48) 
at org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.doDispatch(GrailsDispatcherServlet.java:325) 
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827) 
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) 
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:688) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770) 
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) 
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:70) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) 
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:70) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) 
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:70) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) 
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:807) 
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:671) 
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:505) 
at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:476) 
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:355) 
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:305) 
at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:312) 
at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:277) 
at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:268) 
at org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.doFilterInternal(UrlMappingsFilter.java:209) 
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) 
at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.obtainContent(GrailsPageFilter.java:200) 
at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.doFilter(GrailsPageFilter.java:151) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) 
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:369) 
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109) 
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83) 
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381) 
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97) 
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381) 
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78) 
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381) 
at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119) 
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381) 
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) 
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381) 
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187) 
at org.codehaus.groovy.grails.plugins.springsecurity.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:40) 
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381) 
at org.codehaus.groovy.grails.plugins.springsecurity.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:79) 
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381) 
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79) 
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381) 
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:168) 
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) 
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) 
at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:69) 
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) 
at org.apache.catalina. 
4

1 回答 1

0

显然这是 Glassfish 3.1.2 的问题。今天早上我发现了一条关于我的问题的推文,这使我找到了这个JIRA

替换 web-core.jar 文件为我解决了这个问题。为了概念验证,我下载了 Glassfish 3.1.1 并在该版本上运行我的应用程序,没有任何问题。因此,所有事情都指向 3.1.2 是我问题的根本原因。我的应用程序中没有任何内容。

于 2012-06-18T16:40:32.770 回答