0

I'm trying to upload a .csv file from a JSP to a servlet. It works perfectly on my local machine (Java 1.8 on Websphere 8.5.5.11), but when I move it to test environments (Java 1.6 on WebSphere 8.5.5.12), I get an error that says:

java.lang.UnsupportedOperationException: SRVE8020E: Servlet does not accept multipart requests

Which seems odd, because isMultipart comes back as true.

Here is my JSP form:

<form method="POST" name="batchForm" action="BatchTierProcessing" enctype="multipart/form-data">
    <input type="hidden" name="pageName" value="batchTierProcess"/>
    <text>Upload File for Batch Processing:</text>
    <input type="file" name="file" id="file"/>
    <input type="submit" value="Upload" name="upload" id="upload"/>
</form>

Here is my servlet:

 @WebServlet(name = "UWTSAS", urlPatterns = {"/UWTSAS"}, loadOnStartup = 1)
@MultipartConfig
public class PMSTandalone extends AWRServlet {

    @Override
    protected void doPost(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletException, IOException {
        boolean isMultipart = ServletFileUpload.isMultipartContent(aRequest);
        FileItem csv = null;
        String pageNameMultiPart = "";
        Exception fakeException = new Exception();
        PageNameEnum pageName = null;
        Part filePart = null;
        //if a multipart request (batch process) grab file before request is touched by anything else
        if(isMultipart) {
            LogMessageUtility.log("INFO", "Is multipart request", fakeException);
            filePart = aRequest.getPart("file");        
            pageName = PageNameEnum.getValue("pmSABTS");
            LogMessageUtility.log("INFO", "Page Name Multipart", fakeException);
        }
        else {          
            pageName = PageNameEnum.getValue(aRequest.getParameter("pageName"));
        }
        HttpSession aSession = aRequest.getSession(false);
        if(aSession == null) {
            aSession = aRequest.getSession(true);
        }
        buildUserSession(aRequest, aSession);

        boolean batchSuccessful = true;
        String destination = "PMStandBatchRes";
        LogMessageUtility.log("INFO", "Batch Processing Started", fakeException);
                    try {
                        batchSuccessful = getFinalScoresBatch(aRequest, aResponse, aSession, filePart);
                    }
                    catch(Exception e) {
                        LogMessageUtility.log("ERROR", e.getMessage(), e);
                    }
            }

        if(!destination.equals("") && batchSuccessful) {
            dispatchToResource(aRequest, aResponse, WebRatingProperty.getSetting(destination));
        }
    }

I've tried setting Eclipse to compile this project using Java 6, with no luck. As far as I know, I can't set my local WebSphere instance to run using 1.6. I tried using Apache Commons FileUpload and Commons IO instead of doing it natively through Java with no luck, and am starting to consider figuring out how to parse the request manually.

Anyone have any idea what's going on, or any ideas for things I should try? I've browsed through these questions and answers already:

How to upload files to server using JSP/Servlet?

Convenient way to parse incoming multipart/form-data parameters in a Servlet

How can I read other parameters in a multipart form with Apache Commons

How to upload files to server using JSP/Servlet?

Thanks in advance for any help or ideas.

trauch
  • 61
  • 8
  • Unrelated, but I don't understand the `aRequest.getSession()` code here: `getSession(true)` returns the current session if there is one, or creates a new one. Your check appears redundant. – Dave Newton Sep 07 '18 at 13:16
  • [1] Are you using WebSphere for Developers 8.5.5.11 when you test on your local machine, but a full WebSphere server 8.5.5.12 when running in the test environment? Is so, then there may be a difference in optional patches or functionality between the two flavors of WebSphere. [2] For this issue [UnsupportedOperationException: SRVE8020E: Servlet does not accept multipart requests](https://stackoverflow.com/q/29484747/2985643) the poster reported that they had to apply a patch to WebSphere 8.5.5.0. [3] Is there another app on the test server that is successfully uploading files? – skomisa Sep 09 '18 at 06:59

1 Answers1

0

I figured it out. Had to remove the @MultipartConfig annotation, and implement the javax.servlet.Servlet interface, and use the Apache Commons FileUpload library.

trauch
  • 61
  • 8