1

I'm having a blocking exception while requesting the servlet parts in Weblogic 12.2.1.4-dev on docker.(please note that this is working on Wildfly server)

The Java code i'm using is:

import javax.servlet.http.*;

protected void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException {
    ...
    Collection<Part> parts = request.getParts();
    ...
}

the error i'm having in the server.log:

<Oct 2, 2020 9:17:59,302 AM GMT> <Warning> <HTTP> <BEA-101394> <The exception "The request content-type is not a multipart/form-data" occurred when processing getParameter or getParameterValues from a multipart value of a ServletRequest.> 
javax.servlet.ServletException: The request content-type is not a multipart/form-data
    at weblogic.servlet.utils.fileupload.Multipart.getParts(Multipart.java:158)
    at weblogic.servlet.internal.ServletRequestImpl$RequestParameters.getParts(ServletRequestImpl.java:2497)
    at weblogic.servlet.internal.ServletRequestImpl$RequestParameters.access$3000(ServletRequestImpl.java:2181)
    at weblogic.servlet.internal.ServletRequestImpl.getParts(ServletRequestImpl.java:3652)
    at javax.servlet.http.HttpServletRequestWrapper.getParts(HttpServletRequestWrapper.java:375)

And the Http request details on google chrome:

// GENERAL
Request URL: http://172.21.1.1:8310/backoffice/service
Request Method: PUT
Status Code: 400 Bad Request
Remote Address: 172.1.1.1:8310
Referrer Policy: strict-origin-when-cross-origin
// REQUEST HEADERS
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-BE,en;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6,es;q=0.5,it;q=0.4
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 647482
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryoCBB96YNI9S3vXob
Cookie: JSESSIONID=XIjomkiRAVxEtEn0qwlILe46arjsphNNibL00t2dHEhj75oc167A!-481127499
Host: 172.1.1.1:8310
Origin: http://172.1.1.1:8310
Pragma: no-cache
Referer: http://172.1.1.1:8310/backoffice/products/edit?id=MA01
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
X-Requested-With: XMLHttpRequest
// FORM DATA
subside-velo-pedelec25.pdf: (binary)
actionId: 98c6e900-0289-4bb6-8e98-2b967b2ee363 
windowId: YbVZr0XiCFHxU7K4hUlmBJmLoXwzY6
Raouf Gharbi
  • 11
  • 1
  • 2
  • Did you check the Content-Type value of arrived request in container with method request.getContentType();? – Rok Prodan Oct 02 '20 at 10:14
  • @RokProdan request.getContentType(): "multipart/form-data; boundary=----WebKitFormBoundaryDmBj9xylsJG9ik0D" – Raouf Gharbi Oct 02 '20 at 11:02
  • Which version of Servlet API are you using? Is your servlet class annotated with @MultipartConfig as described in https://stackoverflow.com/a/2424824/7394988? – Rok Prodan Oct 02 '20 at 11:20
  • i'm using : `javax.servlet-api v3.1.0` and my servlet class has this 2 annotations: `@WebServlet(value = "/service", loadOnStartup = 1) @MultipartConfig(location = "/tmp", fileSizeThreshold = 1024 * 1024, maxFileSize = 1024 * 1024 * 30, maxRequestSize = 1024 * 1024 * 5 * 5)` – Raouf Gharbi Oct 02 '20 at 11:30
  • please note that the file upload is working fine on Widlfly server – Raouf Gharbi Oct 02 '20 at 11:34
  • If your current implementation is working on Wildfly server (this detail must be mentioned in the question IMHO) I would recommend you examine the differences between two environments. If the client request is the same in both cases I would continue my investigation on server side, topology and additional configuration. – Rok Prodan Oct 02 '20 at 11:48

1 Answers1

1

I faced the same issue.

FileUpload's servlet implementation from WebLogic core libs only allow multipart requests under "POST" method:

  private boolean isMultipart() {
    if (!this.request.getMethod().toLowerCase().equals("post"))
      return false; 
    String contentType = this.request.getContentType();
    if (contentType == null)
      return false; 
    if (contentType.toLowerCase().startsWith("multipart/form-data"))
      return true; 
    return false;
  }

If this validation fails, it will throw an exception including a message that does not have any relation with the actual error:

    if (!isMultipart())
      throw new ServletException("The request content-type is not a multipart/form-data"); 

So I switched my method from PUT to POST.

Dharman
  • 30,962
  • 25
  • 85
  • 135
dejarikbcn
  • 11
  • 1