Wildfly Jakarta EE 10 多部分表格缺失

问题描述 投票:0回答:1

在从 Wildfly 25 升级到 Wildfly 27(及更高版本)的过程中,我们不再看到多部分表单。

请求部分为空(见下面底部)。所以,我不知道它在哪里被吃掉。

这是 web.conf

<web-app
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
version="6.0">
<display-name>ESG WebApplication</display-name>

<context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>true</param-value>
</context-param>
<context-param>
    <param-name>resteasy.servlet.mapping.prefix</param-name>
    <param-value>/rest</param-value>
</context-param>

<listener>
    <listener-class>com.pearson.esg.server.PRMSContextListener</listener-class>
</listener>
<listener>
    <listener-class>
        org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
    </listener-class>
</listener>

<filter>
    <filter-name>SessionTimeoutCookieFilter</filter-name>
    <filter-class>com.oberon.esg.server.SessionTimeoutCookieFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>SessionTimeoutCookieFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
    <filter-name>ResponseHeaderFilter</filter-name>
    <filter-class>com.pearson.esg.server.ResponseHeaderFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>ResponseHeaderFilter</filter-name>
    <url-pattern>*</url-pattern>
</filter-mapping>

<servlet>
    <display-name>Initialize ESG Servlet</display-name>
    <servlet-name>esg.InitServlet</servlet-name>
    <servlet-class>com.oberon.esg.server.InitServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet>
    <display-name>ESG Request Servlet</display-name>
    <servlet-name>esg.RequestServlet</servlet-name>
    <servlet-class>com.oberon.esg.server.RequestServlet</servlet-class>
    <load-on-startup>3</load-on-startup>
</servlet>
<servlet>
    <display-name>ESG Client Servlet</display-name>
    <servlet-name>esg.ClientServlet</servlet-name>
    <servlet-class>com.oberon.esg.client.ClientServlet</servlet-class>
    <load-on-startup>4</load-on-startup>
</servlet>
<servlet>
    <servlet-name>Resteasy</servlet-name>
    <servlet-class>
        org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
    </servlet-class>
</servlet>


<servlet-mapping>
    <servlet-name>esg.InitServlet</servlet-name>
    <url-pattern>/init</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>esg.RequestServlet</servlet-name>
    <url-pattern>/request/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>esg.ClientServlet</servlet-name>
    <url-pattern>/client</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Resteasy</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

<mime-mapping>
    <extension>pdf</extension>
    <mime-type>application/pdf</mime-type>
</mime-mapping>

<mime-mapping>
    <extension>css</extension>
    <mime-type>text/css</mime-type>
</mime-mapping>

<mime-mapping>
    <extension>jar</extension>
    <mime-type>application/x-java-archive</mime-type>
</mime-mapping>
<mime-mapping>
    <extension>xml</extension>
    <mime-type>text/xml</mime-type>
</mime-mapping>


<welcome-file-list>
    <welcome-file>esg.jsp</welcome-file>
</welcome-file-list>


<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <trim-directive-whitespaces>true</trim-directive-whitespaces>
    </jsp-property-group>
</jsp-config>

<session-config>
    <session-timeout>120</session-timeout>
    <cookie-config>
        <http-only>true</http-only>
    </cookie-config>
</session-config>

POM文件:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.pearson.prms</groupId>
    <artifactId>PRMS</artifactId>
    <version>-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>esg</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.javadoc.failOnError>false</maven.javadoc.failOnError>
    </properties>

    <distributionManagement>
        <repository>
            <id>maven2</id>
            <name>Maven Central Repo</name>
            <url>https://repo1.maven.org/maven2/</url>
        </repository>
        <snapshotRepository>
            <id>PearsonSnapshot</id>
            <name>PearsonSnapshot</name>
            <url>https://nexus2.pearsondev.com/nexus/content/repositories/PearsonSnapshot/</url>
        </snapshotRepository>
    </distributionManagement>

    <build>
        <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
        <finalName>esg</finalName>
        <resources>
            <resource>
                <directory>${basedir}/src/main/java/com/oberon/esg/util</directory>
                <includes>
                    <include>build.number</include>
                </includes>
                <targetPath>${basedir}/target/esg/WEB-INF/classes/com/oberon/esg/util</targetPath>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
                <targetPath>${basedir}/target/esg</targetPath>
                <filtering>false</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <version>1.4</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.3</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.1.1</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>wagon-maven-plugin</artifactId>
                <version>2.0.0</version>
                <executions>
                    <execution>
                        <id>upload-war-to-server</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>upload</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <fromDir>${project.build.directory}</fromDir>
                    <includes>esg.war</includes>
                    <toDir>dev-tools/wildfly-11.0.0.Final/standalone/deployments</toDir>
                </configuration>
            </plugin>

        </plugins>
    </build>

    <dependencies>

        <!-- a copy of this connector needs to be in the static-content and needs to be updated in the Docker file -->
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <version>8.2.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.20.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.20.0</version>
        </dependency>


        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j2-impl</artifactId>
            <version>2.20.0</version>
        </dependency>

        <!-- Provided by Wildfly upgrade on each release ? -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-client</artifactId>
            <version>6.2.1.Final</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <version>6.0.0</version>
            <scope>provided</scope>
        </dependency>


        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>4.0.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>jakarta.platform</groupId>
            <artifactId>jakarta.jakartaee-api</artifactId>
            <version>10.0.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>jakarta.servlet.jsp.jstl</groupId>
            <artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
            <version>3.0.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>jakarta.mail</groupId>
            <artifactId>jakarta.mail-api</artifactId>
            <version>2.1.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-multipart-provider</artifactId>
            <version>6.2.3.Final</version>
            <scope>provided</scope>
        </dependency>


        <!-- End of provided by Wildfly -->

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.15.1</version>
        </dependency>

        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.5</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-fileupload2-jakarta</artifactId>
            <version>2.0.0-M1</version>
        </dependency>

        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>  <!-- wildfly seems to have commons-lang3-3.12.0 -->
        </dependency>

        <dependency>
            <groupId>org.owasp.antisamy</groupId>
            <artifactId>antisamy</artifactId>
            <version>1.7.4</version>
        </dependency>


        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>4.5.14</version>
        </dependency>

        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk</artifactId>
            <version>1.12.638</version>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.9</version>
        </dependency>

        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>5.4.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-text</artifactId>
            <version>1.10.0</version>
        </dependency>

    </dependencies>

</project>

这是 Chrome 中捕获的多部分表单:

------WebKitFormBoundary10g8buFFvhco7LAa
Content-Disposition: form-data; name="challenge"

a73152dadb6bd6d376f40590e4a...
------WebKitFormBoundary10g8buFFvhco7LAa
Content-Disposition: form-data; name="requestType"

downloadTooltip
------WebKitFormBoundary10g8buFFvhco7LAa--

这是被追踪的帖子

parsePostRequestInputs:62, RequestInputs (com.oberon.esg.client)
doPost:95, ClientServlet (com.oberon.esg.client)
service:547, HttpServlet (jakarta.servlet.http)
service:614, HttpServlet (jakarta.servlet.http)
handleRequest:74, ServletHandler (io.undertow.servlet.handlers)
doFilter:129, FilterHandler$FilterChainImpl (io.undertow.servlet.handlers)
doFilter:72, ResponseHeaderFilter (com.pearson.esg.server)
doFilter:67, ManagedFilter (io.undertow.servlet.core)
doFilter:131, FilterHandler$FilterChainImpl (io.undertow.servlet.handlers)
doFilter:64, SessionTimeoutCookieFilter (com.oberon.esg.server)
doFilter:67, ManagedFilter (io.undertow.servlet.core)
doFilter:131, FilterHandler$FilterChainImpl (io.undertow.servlet.handlers)
handleRequest:84, FilterHandler (io.undertow.servlet.handlers)
handleRequest:62, ServletSecurityRoleHandler (io.undertow.servlet.handlers.security)
handleRequest:68, ServletChain$1 (io.undertow.servlet.handlers)
handleRequest:36, ServletDispatchingHandler (io.undertow.servlet.handlers)
lambda$handleRequest$1:68, ElytronRunAsHandler (org.wildfly.elytron.web.undertow.server)
call:-1, 468564214 (org.wildfly.elytron.web.undertow.server.ElytronRunAsHandler$$Lambda$1005)
apply:-1, 1566944025 (org.wildfly.security.auth.server.Scoped$$Lambda$1006)
apply:-1, 1023282428 (org.wildfly.security.auth.server.Scoped$$Lambda$1007)
runAsFunctionEx:103, FlexibleIdentityAssociation (org.wildfly.security.auth.server)
runAsFunctionEx:161, Scoped (org.wildfly.security.auth.server)
runAs:73, Scoped (org.wildfly.security.auth.server)
handleRequest:67, ElytronRunAsHandler (org.wildfly.elytron.web.undertow.server)
handleRequest:68, RedirectDirHandler (io.undertow.servlet.handlers)
handleRequest:117, SSLInformationAssociationHandler (io.undertow.servlet.handlers.security)
handleRequest:57, ServletAuthenticationCallHandler (io.undertow.servlet.handlers.security)
handleRequest:43, PredicateHandler (io.undertow.server.handlers)
handleRequest:46, AbstractConfidentialityHandler (io.undertow.security.handlers)
handleRequest:64, ServletConfidentialityConstraintHandler (io.undertow.servlet.handlers.security)
handleRequest:43, AbstractSecurityContextAssociationHandler (io.undertow.security.handlers)
handleRequest:38, CleanUpHandler (org.wildfly.elytron.web.undertow.server.servlet)
handleRequest:43, PredicateHandler (io.undertow.server.handlers)
handleRequest:44, JACCContextIdHandler (org.wildfly.extension.undertow.security.jacc)
handleRequest:43, PredicateHandler (io.undertow.server.handlers)
handleRequest:54, RewriteCorrectingHandlerWrappers$PostWrapper$1 (org.wildfly.extension.undertow.deployment)
handleRequest:141, PredicatesHandler (io.undertow.predicate)
handleRequest:35, RewriteCorrectingHandlerWrappers$PreWrapper$1 (org.wildfly.extension.undertow.deployment)
handleRequest:51, GlobalRequestControllerHandler (org.wildfly.extension.undertow.deployment)
handleRequest:52, SendErrorPageHandler (io.undertow.servlet.handlers)
handleRequest:43, PredicateHandler (io.undertow.server.handlers)
handleFirstRequest:276, ServletInitialHandler (io.undertow.servlet.handlers)
call:135, ServletInitialHandler$2 (io.undertow.servlet.handlers)
call:132, ServletInitialHandler$2 (io.undertow.servlet.handlers)
call:48, ServletRequestContextThreadSetupAction$1 (io.undertow.servlet.core)
call:43, ContextClassLoaderSetupAction$1 (io.undertow.servlet.core)
lambda$create$0:1413, UndertowDeploymentInfoService$UndertowThreadSetupAction (org.wildfly.extension.undertow.deployment)
call:-1, 1680829687 (org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$876)
lambda$create$0:1413, UndertowDeploymentInfoService$UndertowThreadSetupAction (org.wildfly.extension.undertow.deployment)
call:-1, 1680829687 (org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$876)
lambda$create$0:1413, UndertowDeploymentInfoService$UndertowThreadSetupAction (org.wildfly.extension.undertow.deployment)
call:-1, 1680829687 (org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$876)
lambda$create$0:1413, UndertowDeploymentInfoService$UndertowThreadSetupAction (org.wildfly.extension.undertow.deployment)
call:-1, 1680829687 (org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$876)
dispatchRequest:256, ServletInitialHandler (io.undertow.servlet.handlers)
handleRequest:101, ServletInitialHandler$1 (io.undertow.servlet.handlers)
executeRootHandler:393, Connectors (io.undertow.server)
run:859, HttpServerExchange$1 (io.undertow.server)
run:35, ContextClassLoaderSavingRunnable (org.jboss.threads)
safeRun:1990, EnhancedQueueExecutor (org.jboss.threads)
doRunTask:1486, EnhancedQueueExecutor$ThreadBody (org.jboss.threads)
run:1377, EnhancedQueueExecutor$ThreadBody (org.jboss.threads)
run:1282, XnioWorker$WorkerThreadFactory$1$1 (org.xnio)
run:829, Thread (java.lang)

这是我想查看多部分数据的地方。

    @MultipartForm
    public void parsePostRequestInputs(HttpServletRequest request, InputValidation validator) throws IOException
    {
        _filesToUpload = new HashMap<String, Part>();

        if (request.getContentType().contains("urlencoded"))
        {
            //
            // read the request
            //
            Map<String, String[]> params = request.getParameterMap();
            _entries = new String[params.keySet().size()];
            int pos = 0;
            for (String param : params.keySet()) {
               _entries[pos] = param + "=" + URLDecoder.decode(params.get(param)[0], StandardCharsets.UTF_8);
               pos++;
            }
        }
        else
        {
            _log.debug("Checking for multipart.");

            try {
                request.getParts();
            } catch (Exception e) {
                _entries = new String[0];
                return;
            }

            try
            {
                final Collection<Part> parts = request.getParts();
                List<String> temp = new ArrayList<String>();
                for (final Part part : parts)
                {
                    String fileItemFieldName = part.getSubmittedFileName();
                    if (!(fileItemFieldName.startsWith("fileUpload")))
                    {
                        temp.add(part.getName() + "=" + fileItemFieldName);
                    }
                    else
                    {
                        String index = part.getName().substring(10);
                        _filesToUpload.put(index, part);

                        String fileItemName = part.getName();
                        if (fileItemName.length() > 30)
                        {
                            fileItemName = fileItemName.substring(0, 30);
                        }
                        temp.add("uploadPixName" + index + "=" + fileItemName);
                    }
                }
                _entries = temp.toArray(new String[temp.size()]);
            }
            catch (FileUploadException | ServletException e)
            {
                _log.error("There was an issue uploading files for the POST request. " + e);
            }
        }
    }

请求在调试器中看起来像这样:

request = {HttpServletRequestImpl@16372} "HttpServletRequestImpl [ POST /esg/client ]"
 exchange = {HttpServerExchange@16383} "HttpServerExchange{ POST /esg/client}"
 originalServletContext = {ServletContextImpl@16384} 
 servletContext = {ServletContextImpl@16384} 
 attributes = null
 servletInputStream = null
 reader = null
 cookies = null
 parts = null
 asyncStarted = false
 asyncContext = null
 queryParameters = null
 parsedFormData = null
 formParsingException = null
 characterEncoding = null
 readStarted = false
 sessionCookieSource = null

我们所有的多部分数据请求都会发生这种情况。这也许是最简单的要求。如果我们将 get 与 URL 编码一起使用,一切都会正常。有什么想法多部分数据去了哪里吗?

蒂亚!

jsp servlets jakarta-ee jboss wildfly
1个回答
0
投票

看来多部分 servlet 需要定义多部分配置(或有适当的注释)。我不确定何时需要这样做。然而,它出现在我们从 Wildfly 26 到 Wildfly 27 的迁移中。

通过修改我的 web.xml 来定义多部分配置,一切开始工作。

<servlet>
    <display-name>ESG Client Servlet</display-name>
    <servlet-name>esg.ClientServlet</servlet-name>
    <servlet-class>com.oberon.esg.client.ClientServlet</servlet-class>
    <load-on-startup>4</load-on-startup>
    <multipart-config>
        <location>/tmp</location>
        <max-file-size>20848820</max-file-size>
        <max-request-size>418018841</max-request-size>
        <file-size-threshold>1048576</file-size-threshold>
    </multipart-config>
</servlet>
© www.soinside.com 2019 - 2024. All rights reserved.