In attempting to implement fileUpload using the streaming API I get an error described below: As I gather from the Streaming API web page that the "traditional FileItemFactory is completely ignored," I'm wondering what I'm doing wrong. So I've defined a basic method as follows:
/**
*
* @param
* @return
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
// Check that we have a file upload request
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) {
ServletFileUpload upload = new ServletFileUpload(); // Create a new file upload handler
// Parse the request
try {
Line 39 --> List items = upload.parseRequest(request); // FileItem
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItemStream item = (FileItemStream) iter.next();
if (!item.isFormField()) {
this.processFITSFile(item);
}
}
} catch (FileUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
But that leads to the error below:
SEVERE: Servlet.service() for servlet FitsFileProcessorServlet threw exception
java.lang.NullPointerException: No FileItemFactory has been set.
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:353)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
at controller.FITSFileProcessor.doPost(FITSFileProcessor.java:39)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
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:191)
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:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Unknown Source)