You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Frank W. Zammetti" <fz...@omnytex.com> on 2006/08/17 03:25:48 UTC

Re: Exception with Download Action

Hi Eric... I hope you don't mind but I copied this to the Struts @user 
list so that others have the opportunity to help... I'm afraid I'm about 
to go out of town in a few hours and so don't really have the time to 
figure this out... I haven't used or even thought about DownloadAction 
for some time, so the problem isn't immediately apparent to me, but 
maybe it will be to someone else out there.  If not, I'll ping you back 
in a few days and if you still need help, I'll work through it with you.

Frank

eric.hough@eds.com wrote:
> Hi Frank,
> 
> Please bare with me as I am new to Java, Struts, etc. my primary background is .NET, however I have just joined a new Java/Web develepment project team.
> 
> Anyhow, I too am getting a java.lang.NullPointerException when I try to implement the DownloadAction Class when attempting to return a ResourceStreamInfo class. 
> 
> This exception is the root cause of a higher level javax.servlet.ServletException which is actually being thrown when I execute the getStreamInfo method of my DownloadAction class implementation.
> 
> The code from my implementation is as follows:
> 
> ==============================================================================
> import javax.servlet.ServletContext;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import org.apache.struts.action.ActionForm;
> import org.apache.struts.action.ActionMapping;
> import org.apache.struts.actions.DownloadAction;
> 
> public class DownloadStreamAction extends DownloadAction{
> 
>     protected StreamInfo getStreamInfo(ActionMapping mapping, 
>                                        ActionForm form,
>                                        HttpServletRequest request, 
>                                        HttpServletResponse response)
>             throws Exception {
>             	
>         String contentType = "image/jpeg";
>         String path = mapping.getParameter();
>         String FileNameOnly = path.substring(path.lastIndexOf("\\") + 1);
>         
>          //ServletContext application = servlet.getServletContext();
> 
>         ServletContext application = request.getSession().getServletContext();
>         
>         System.out.println("Content Type: " + contentType);
>         
>         //System.out.println("Path: " + path);
>         System.out.println("File Name Only: " + FileNameOnly);
>    
>         if (application == null){
>             System.out.println("Servlet Context: null");       	
>         }
>         else{
>             System.out.println("Servlet Context: not null");        	
>         }
>       
>         //response.setHeader("Content-disposition", "inline; filename=" + FileNameOnly);
>         
>         //ResourceStreamInfo MyResStream = new ResourceStreamInfo("image/jpeg", application, "test.jpg");
>         
> //        if (MyResStream == null){
> //            System.out.println("My Resource Stream : null");       	
> //        }
> //        else{
> //            System.out.println("My Resource Stream: not null");        	
> //        }
>         //return MyResStream;
>         return new ResourceStreamInfo(contentType, application, "/test.jpg");
>     }
> }
> 
> ==============================================================================
> 
> As you can see from the commented out code i have tried all sorts to get this working but with no joy.
> 
> 
> The full stacktrace of the exception is as follows:
> 
> ==============================================================================
> javax.servlet.ServletException
> 	at org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
> 	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
> 	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
> 	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
> 	at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:696)
> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
> 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
> 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
> 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
> 	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
> 	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
> 	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
> 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
> 	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
> 	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
> 	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
> 	at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
> 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
> 	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
> 	at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
> 	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
> 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
> 	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
> 	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
> 	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
> 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
> 	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
> 	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
> 	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
> 	at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
> 	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
> 	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
> 	at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
> 	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
> 	at java.lang.Thread.run(Thread.java:534)
> 
> 
> root cause 
> 
> java.lang.NullPointerException
> 	at org.apache.struts.actions.DownloadAction.copy(DownloadAction.java:139)
> 	at org.apache.struts.actions.DownloadAction.execute(DownloadAction.java:112)
> 	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
> 	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
> 	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
> 	at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:696)
> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
> 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
> 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
> 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
> 	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
> 	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
> 	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
> 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
> 	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
> 	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
> 	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
> 	at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
> 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
> 	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
> 	at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
> 	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
> 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
> 	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
> 	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
> 	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
> 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
> 	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
> 	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
> 	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
> 	at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
> 	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
> 	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
> 	at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
> 	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
> 	at java.lang.Thread.run(Thread.java:534)
> 
> ==============================================================================
> 
> 
> Any help that you can offer would be greatly appreciated!
> 
> Regards
> 
> 
> Eric
> 
> 
> --
> This message was sent on behalf of eric.hough@eds.com at openSubscriber.com
> http://www.opensubscriber.com/message/user@struts.apache.org/1977913.html
> 
> 
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
  (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
  Supplying the wheel, so you don't have to reinvent it!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org