You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Marinus Maris <ma...@magiad.nl> on 2009/08/29 12:26:50 UTC

ServletOutputStream gives null pointer in v5.1.0.5 but not in v5.0.18

Hi

To get a file from disk I wrote this code below. It works perfectly in 
version 5.0.18 but it generates a null pointer in v5.1.0.5. I checked 
the release notes to no avail. What's going on here?

    Object onActionFromGetParticipantsFile() {
        String method = "get";
        try {
            FileInputStream fInput = new FileInputStream(fileName);
            byte[] bytes = new byte[fInput.available()];
            fInput.read(bytes, 0, fInput.available());
            if (bytes != null) {
                ServletOutputStream stream = 
response.getHTTPServletResponse().getOutputStream();
                
response.getHTTPServletResponse().setContentType("text/plain");
                
response.getHTTPServletResponse().setContentLength(bytes.length);
                
response.getHTTPServletResponse().setHeader("Content-Disposition", 
method + ";filename=" +fileName;

                stream.write(bytes);
**** Here it comes up with a null pointer, although the streanm object 
exists as I checked that !

                stream.flush();
                stream.close();
                return response;
            }
        } catch (Exception e) {
            System.out.println("onActionFromGetFile; " + e);
        }
        return new TextStreamResponse("text/plain", String.format("file 
" + fileName+ " not found"));

Marinus


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: ServletOutputStream gives null pointer in v5.1.0.5 but not in v5.0.18

Posted by Marinus Maris <ma...@magiad.nl>.
Solved it. I should have checked the Tapestry Wiki first before posting, 
sorry about that.
http://wiki.apache.org/tapestry/Tapestry5HowToStreamAnExistingBinaryFile

Still I don't know what changed in between versions, but I can live with 
that.

Marinus


Marinus Maris schreef:
> I post this mail again, now with the stack trace added below the code:
>
> To get a file from disk I wrote this code below. It works perfectly in 
> version 5.0.18 but it generates a null pointer in v5.1.0.5. I checked 
> the release notes to no avail. What's going on here? Apparently a gzip 
> service is needed now?
>
>   Object onActionFromGetParticipantsFile() {
>       String method = "get";
>       try {
>           FileInputStream fInput = new FileInputStream(fileName);
>           byte[] bytes = new byte[fInput.available()];
>           fInput.read(bytes, 0, fInput.available());
>           if (bytes != null) {
>               ServletOutputStream stream = 
> response.getHTTPServletResponse().getOutputStream();
>               
> response.getHTTPServletResponse().setContentType("text/plain");
>               
> response.getHTTPServletResponse().setContentLength(bytes.length);
>               
> response.getHTTPServletResponse().setHeader("Content-Disposition", 
> method + ";filename=" +fileName;
>
>               stream.write(bytes);
>
> line 446 in the code:  Here it comes up with the null pointer, 
> although the stream object exists as I checked that.
>
>               stream.flush();
>               stream.close();
>               return response;
>           }
>       } catch (Exception e) {
>            e.printStackTrace();
>       }
>       return new TextStreamResponse("text/plain", String.format("file 
> " + fileName+ " not found"));
>
> java.lang.NullPointerException
>        at 
> org.apache.tapestry5.internal.services.ResponseCompressionAnalyzerImpl.isCompressable(ResponseCompressionAnalyzerImpl.java:65) 
>
>        at 
> $ResponseCompressionAnalyzer_1236c9345b8.isCompressable($ResponseCompressionAnalyzer_1236c9345b8.java) 
>
>        at 
> org.apache.tapestry5.internal.gzip.BufferedGZipOutputStream.openResponseOutputStream(BufferedGZipOutputStream.java:77) 
>
>        at 
> org.apache.tapestry5.internal.gzip.BufferedGZipOutputStream.checkForCutover(BufferedGZipOutputStream.java:70) 
>
>        at 
> org.apache.tapestry5.internal.gzip.BufferedGZipOutputStream.write(BufferedGZipOutputStream.java:108) 
>
>        at 
> mobiquete.pages.SurveyDeploy.onActionFromGetParticipantsFile(SurveyDeploy.java:446) 
>
>        at 
> mobiquete.pages.SurveyDeploy.dispatchComponentEvent(SurveyDeploy.java)
>        at 
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:902) 
>
>        at 
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1081) 
>
>        at 
> org.apache.tapestry5.internal.services.ComponentEventRequestHandlerImpl.handle(ComponentEventRequestHandlerImpl.java:75) 
>
>        at 
> org.apache.tapestry5.internal.services.ImmediateActionRenderResponseFilter.handle(ImmediateActionRenderResponseFilter.java:42) 
>
>        at 
> $ComponentEventRequestHandler_1236c934654.handle($ComponentEventRequestHandler_1236c934654.java) 
>
>        at 
> org.apache.tapestry5.internal.services.AjaxFilter.handle(AjaxFilter.java:42) 
>
>        at 
> $ComponentEventRequestHandler_1236c934654.handle($ComponentEventRequestHandler_1236c934654.java) 
>
>        at 
> org.apache.tapestry5.upload.internal.services.UploadExceptionFilter.handle(UploadExceptionFilter.java:75) 
>
>        at 
> $ComponentEventRequestHandler_1236c934654.handle($ComponentEventRequestHandler_1236c934654.java) 
>
>        at 
> org.apache.tapestry5.services.TapestryModule$36.handle(TapestryModule.java:2164) 
>
>        at 
> $ComponentEventRequestHandler_1236c934654.handle($ComponentEventRequestHandler_1236c934654.java) 
>
>        at 
> $ComponentEventRequestHandler_1236c9345d9.handle($ComponentEventRequestHandler_1236c9345d9.java) 
>
>        at 
> org.apache.tapestry5.internal.services.ComponentRequestHandlerTerminator.handleComponentEvent(ComponentRequestHandlerTerminator.java:43) 
>
>        at 
> $ComponentRequestHandler_1236c9345cd.handleComponentEvent($ComponentRequestHandler_1236c9345cd.java) 
>
>        at 
> org.apache.tapestry5.internal.services.ComponentEventDispatcher.dispatch(ComponentEventDispatcher.java:46) 
>
>        at $Dispatcher_1236c9345cf.dispatch($Dispatcher_1236c9345cf.java)
>        at $Dispatcher_1236c9345c5.dispatch($Dispatcher_1236c9345c5.java)
>        at 
> org.apache.tapestry5.services.TapestryModule$RequestHandlerTerminator.service(TapestryModule.java:245) 
>
>        at mobiquete.services.AppModule$1.service(AppModule.java:96)
>        at 
> $RequestFilter_1236c9345c4.service($RequestFilter_1236c9345c4.java)
>        at 
> $RequestHandler_1236c9345c6.service($RequestHandler_1236c9345c6.java)
>        at 
> org.apache.tapestry5.internal.services.RequestErrorFilter.service(RequestErrorFilter.java:26) 
>
>        at 
> $RequestHandler_1236c9345c6.service($RequestHandler_1236c9345c6.java)
>        at 
> org.apache.tapestry5.services.TapestryModule$4.service(TapestryModule.java:778) 
>
>        at 
> $RequestHandler_1236c9345c6.service($RequestHandler_1236c9345c6.java)
>        at 
> org.apache.tapestry5.services.TapestryModule$3.service(TapestryModule.java:767) 
>
>        at 
> $RequestHandler_1236c9345c6.service($RequestHandler_1236c9345c6.java)
>        at 
> org.apache.tapestry5.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:85) 
>
>        at 
> $RequestHandler_1236c9345c6.service($RequestHandler_1236c9345c6.java)
>        at 
> org.equanda.tapestry5.services.EquandaModule$1.service(EquandaModule.java:84) 
>
>        at 
> $RequestFilter_1236c9345c0.service($RequestFilter_1236c9345c0.java)
>        at 
> $RequestHandler_1236c9345c6.service($RequestHandler_1236c9345c6.java)
>        at 
> org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:90) 
>
>        at 
> org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:81) 
>
>        at 
> org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier.withRead(ConcurrentBarrier.java:85) 
>
>        at 
> org.apache.tapestry5.internal.services.CheckForUpdatesFilter.service(CheckForUpdatesFilter.java:103) 
>
>        at 
> $RequestHandler_1236c9345c6.service($RequestHandler_1236c9345c6.java)
>        at 
> $RequestHandler_1236c9345ba.service($RequestHandler_1236c9345ba.java)
>        at 
> org.apache.tapestry5.services.TapestryModule$HttpServletRequestHandlerTerminator.service(TapestryModule.java:197) 
>
>        at 
> org.apache.tapestry5.internal.gzip.GZipFilter.service(GZipFilter.java:53)
>        at 
> $HttpServletRequestHandler_1236c9345bc.service($HttpServletRequestHandler_1236c9345bc.java) 
>
>        at 
> org.apache.tapestry5.upload.internal.services.MultipartServletRequestFilter.service(MultipartServletRequestFilter.java:44) 
>
>        at 
> $HttpServletRequestHandler_1236c9345bc.service($HttpServletRequestHandler_1236c9345bc.java) 
>
>        at 
> org.apache.tapestry5.internal.services.IgnoredPathsFilter.service(IgnoredPathsFilter.java:62) 
>
>        at 
> $HttpServletRequestFilter_1236c9345b9.service($HttpServletRequestFilter_1236c9345b9.java) 
>
>        at 
> $HttpServletRequestHandler_1236c9345bc.service($HttpServletRequestHandler_1236c9345bc.java) 
>
>        at 
> org.apache.tapestry5.services.TapestryModule$2.service(TapestryModule.java:726) 
>
>        at 
> $HttpServletRequestHandler_1236c9345bc.service($HttpServletRequestHandler_1236c9345bc.java) 
>
>        at 
> $HttpServletRequestHandler_1236c9345b6.service($HttpServletRequestHandler_1236c9345b6.java) 
>
>        at 
> org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:127)
>        at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 
>
>        at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
>
>        at 
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 
>
>        at 
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) 
>
>        at 
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) 
>
>        at 
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
>
>        at 
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 
>
>        at 
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263) 
>
>        at 
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) 
>
>        at 
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584) 
>
>        at 
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
>        at java.lang.Thread.run(Thread.java:619)
>
>
> Thiago H. de Paula Figueiredo schreef:
>> Em Sat, 29 Aug 2009 07:26:50 -0300, Marinus Maris 
>> <ma...@magiad.nl> escreveu:
>>
>>> Hi
>>
>> Hi!
>>
>>> To get a file from disk I wrote this code below. It works perfectly 
>>> in version 5.0.18 but it generates a null pointer in v5.1.0.5. I 
>>> checked the release notes to no avail. What's going on here?
>>
>> To begin with, where's the stack trace? In what line does the NPE 
>> happen?
>>
>> ------------------------------------------------------------------------
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - www.avg.com Version: 8.5.409 / Virus Database: 
>> 270.13.71/2332 - Release Date: 08/28/09 18:10:00
>>
>>   
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com 
> Version: 8.5.409 / Virus Database: 270.13.71/2335 - Release Date: 08/30/09 06:36:00
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: ServletOutputStream gives null pointer in v5.1.0.5 but not in v5.0.18

Posted by Marinus Maris <ma...@magiad.nl>.
I post this mail again, now with the stack trace added below the code:

To get a file from disk I wrote this code below. It works perfectly in 
version 5.0.18 but it generates a null pointer in v5.1.0.5. I checked 
the release notes to no avail. What's going on here? Apparently a gzip 
service is needed now?

   Object onActionFromGetParticipantsFile() {
       String method = "get";
       try {
           FileInputStream fInput = new FileInputStream(fileName);
           byte[] bytes = new byte[fInput.available()];
           fInput.read(bytes, 0, fInput.available());
           if (bytes != null) {
               ServletOutputStream stream = 
response.getHTTPServletResponse().getOutputStream();
               
response.getHTTPServletResponse().setContentType("text/plain");
               
response.getHTTPServletResponse().setContentLength(bytes.length);
               
response.getHTTPServletResponse().setHeader("Content-Disposition", 
method + ";filename=" +fileName;

               stream.write(bytes);

line 446 in the code:  Here it comes up with the null pointer, although 
the stream object exists as I checked that.

               stream.flush();
               stream.close();
               return response;
           }
       } catch (Exception e) {
            e.printStackTrace();
       }
       return new TextStreamResponse("text/plain", String.format("file " 
+ fileName+ " not found"));

java.lang.NullPointerException
        at 
org.apache.tapestry5.internal.services.ResponseCompressionAnalyzerImpl.isCompressable(ResponseCompressionAnalyzerImpl.java:65)
        at 
$ResponseCompressionAnalyzer_1236c9345b8.isCompressable($ResponseCompressionAnalyzer_1236c9345b8.java)
        at 
org.apache.tapestry5.internal.gzip.BufferedGZipOutputStream.openResponseOutputStream(BufferedGZipOutputStream.java:77)
        at 
org.apache.tapestry5.internal.gzip.BufferedGZipOutputStream.checkForCutover(BufferedGZipOutputStream.java:70)
        at 
org.apache.tapestry5.internal.gzip.BufferedGZipOutputStream.write(BufferedGZipOutputStream.java:108)
        at 
mobiquete.pages.SurveyDeploy.onActionFromGetParticipantsFile(SurveyDeploy.java:446)
        at 
mobiquete.pages.SurveyDeploy.dispatchComponentEvent(SurveyDeploy.java)
        at 
org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:902)
        at 
org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1081)
        at 
org.apache.tapestry5.internal.services.ComponentEventRequestHandlerImpl.handle(ComponentEventRequestHandlerImpl.java:75)
        at 
org.apache.tapestry5.internal.services.ImmediateActionRenderResponseFilter.handle(ImmediateActionRenderResponseFilter.java:42)
        at 
$ComponentEventRequestHandler_1236c934654.handle($ComponentEventRequestHandler_1236c934654.java)
        at 
org.apache.tapestry5.internal.services.AjaxFilter.handle(AjaxFilter.java:42)
        at 
$ComponentEventRequestHandler_1236c934654.handle($ComponentEventRequestHandler_1236c934654.java)
        at 
org.apache.tapestry5.upload.internal.services.UploadExceptionFilter.handle(UploadExceptionFilter.java:75)
        at 
$ComponentEventRequestHandler_1236c934654.handle($ComponentEventRequestHandler_1236c934654.java)
        at 
org.apache.tapestry5.services.TapestryModule$36.handle(TapestryModule.java:2164)
        at 
$ComponentEventRequestHandler_1236c934654.handle($ComponentEventRequestHandler_1236c934654.java)
        at 
$ComponentEventRequestHandler_1236c9345d9.handle($ComponentEventRequestHandler_1236c9345d9.java)
        at 
org.apache.tapestry5.internal.services.ComponentRequestHandlerTerminator.handleComponentEvent(ComponentRequestHandlerTerminator.java:43)
        at 
$ComponentRequestHandler_1236c9345cd.handleComponentEvent($ComponentRequestHandler_1236c9345cd.java)
        at 
org.apache.tapestry5.internal.services.ComponentEventDispatcher.dispatch(ComponentEventDispatcher.java:46)
        at $Dispatcher_1236c9345cf.dispatch($Dispatcher_1236c9345cf.java)
        at $Dispatcher_1236c9345c5.dispatch($Dispatcher_1236c9345c5.java)
        at 
org.apache.tapestry5.services.TapestryModule$RequestHandlerTerminator.service(TapestryModule.java:245)
        at mobiquete.services.AppModule$1.service(AppModule.java:96)
        at 
$RequestFilter_1236c9345c4.service($RequestFilter_1236c9345c4.java)
        at 
$RequestHandler_1236c9345c6.service($RequestHandler_1236c9345c6.java)
        at 
org.apache.tapestry5.internal.services.RequestErrorFilter.service(RequestErrorFilter.java:26)
        at 
$RequestHandler_1236c9345c6.service($RequestHandler_1236c9345c6.java)
        at 
org.apache.tapestry5.services.TapestryModule$4.service(TapestryModule.java:778)
        at 
$RequestHandler_1236c9345c6.service($RequestHandler_1236c9345c6.java)
        at 
org.apache.tapestry5.services.TapestryModule$3.service(TapestryModule.java:767)
        at 
$RequestHandler_1236c9345c6.service($RequestHandler_1236c9345c6.java)
        at 
org.apache.tapestry5.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:85)
        at 
$RequestHandler_1236c9345c6.service($RequestHandler_1236c9345c6.java)
        at 
org.equanda.tapestry5.services.EquandaModule$1.service(EquandaModule.java:84)
        at 
$RequestFilter_1236c9345c0.service($RequestFilter_1236c9345c0.java)
        at 
$RequestHandler_1236c9345c6.service($RequestHandler_1236c9345c6.java)
        at 
org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:90)
        at 
org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:81)
        at 
org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier.withRead(ConcurrentBarrier.java:85)
        at 
org.apache.tapestry5.internal.services.CheckForUpdatesFilter.service(CheckForUpdatesFilter.java:103)
        at 
$RequestHandler_1236c9345c6.service($RequestHandler_1236c9345c6.java)
        at 
$RequestHandler_1236c9345ba.service($RequestHandler_1236c9345ba.java)
        at 
org.apache.tapestry5.services.TapestryModule$HttpServletRequestHandlerTerminator.service(TapestryModule.java:197)
        at 
org.apache.tapestry5.internal.gzip.GZipFilter.service(GZipFilter.java:53)
        at 
$HttpServletRequestHandler_1236c9345bc.service($HttpServletRequestHandler_1236c9345bc.java)
        at 
org.apache.tapestry5.upload.internal.services.MultipartServletRequestFilter.service(MultipartServletRequestFilter.java:44)
        at 
$HttpServletRequestHandler_1236c9345bc.service($HttpServletRequestHandler_1236c9345bc.java)
        at 
org.apache.tapestry5.internal.services.IgnoredPathsFilter.service(IgnoredPathsFilter.java:62)
        at 
$HttpServletRequestFilter_1236c9345b9.service($HttpServletRequestFilter_1236c9345b9.java)
        at 
$HttpServletRequestHandler_1236c9345bc.service($HttpServletRequestHandler_1236c9345bc.java)
        at 
org.apache.tapestry5.services.TapestryModule$2.service(TapestryModule.java:726)
        at 
$HttpServletRequestHandler_1236c9345bc.service($HttpServletRequestHandler_1236c9345bc.java)
        at 
$HttpServletRequestHandler_1236c9345b6.service($HttpServletRequestHandler_1236c9345b6.java)
        at 
org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:127)
        at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
        at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
        at 
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:619)


Thiago H. de Paula Figueiredo schreef:
> Em Sat, 29 Aug 2009 07:26:50 -0300, Marinus Maris 
> <ma...@magiad.nl> escreveu:
>
>> Hi
>
> Hi!
>
>> To get a file from disk I wrote this code below. It works perfectly 
>> in version 5.0.18 but it generates a null pointer in v5.1.0.5. I 
>> checked the release notes to no avail. What's going on here?
>
> To begin with, where's the stack trace? In what line does the NPE happen?
>
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com 
> Version: 8.5.409 / Virus Database: 270.13.71/2332 - Release Date: 08/28/09 18:10:00
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: ServletOutputStream gives null pointer in v5.1.0.5 but not in v5.0.18

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Sat, 29 Aug 2009 07:26:50 -0300, Marinus Maris  
<ma...@magiad.nl> escreveu:

> Hi

Hi!

> To get a file from disk I wrote this code below. It works perfectly in  
> version 5.0.18 but it generates a null pointer in v5.1.0.5. I checked  
> the release notes to no avail. What's going on here?

To begin with, where's the stack trace? In what line does the NPE happen?

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org