英文:
Cannot use Fileupload Multipart on Weblogic server
问题
在请求 Weblogic 12.2.1.4-dev 上的 servlet 部分时,我遇到了阻塞异常。(请注意,这在 Wildfly 服务器上是正常工作的)
**我正在使用的 Java 代码是:**
```java
import javax.servlet.http.*;
protected void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException {
...
Collection<Part> parts = request.getParts();
...
}
我在 server.log 中遇到的错误:
<Oct 2, 2020 9:17:59,302 AM GMT> <Warning> <HTTP> <BEA-101394> <在处理 ServletRequest 的 multipart 值的 getParameter 或 getParameterValues 时出现了异常 "请求内容类型不是 multipart/form-data">
javax.servlet.ServletException: 请求内容类型不是 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)
以及 Google Chrome 中的 Http 请求细节:
// GENERAL
请求 URL: http://172.21.1.1:8310/backoffice/service
请求方法: PUT
状态码: 400 Bad Request
远程地址: 172.1.1.1:8310
引荐政策: strict-origin-when-cross-origin
// 请求头部
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
// 表单数据
subside-velo-pedelec25.pdf: (二进制数据)
actionId: 98c6e900-0289-4bb6-8e98-2b967b2ee363
windowId: YbVZr0XiCFHxU7K4hUlmBJmLoXwzY6
英文:
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
答案1
得分: 1
我遇到了同样的问题。
FileUpload的servlet实现仅允许在WebLogic核心库中的"POST"方法下处理多部分请求:
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 (!isMultipart())
throw new ServletException("请求内容类型不是multipart/form-data");
因此,我将我的方法从PUT更改为POST。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论