【问题标题】:Apache Tomcat Maven Plugin uriEncoding not working with httpsApache Tomcat Maven 插件 uriEncoding 不适用于 https
【发布时间】:2016-04-09 17:22:53
【问题描述】:

我正在使用 tomcat7-maven-plugin 运行我的应用程序 (tomcat7:run)。我在没有 https 的配置中使用<uriEncoding>utf-8</uriEncoding>,一切正常。但是一旦我添加了 https,编码就会停止工作。

当我在客户端发出这样的请求时:https://localhost:8443/ROOT/checkName?mediaName=%C3%A7%C3%A7

我在服务器上收到这个:çç

这是我的一些 pom.xml:

            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <warSourceDirectory>src/main/webapp</warSourceDirectory>
                    <path>/${project.warname}</path>
                    <warFile>target/${project.warname}##${maven.build.timestamp}-${project.name}-v${project.version}</warFile>
                    <uriEncoding>utf-8</uriEncoding>

                    <!-- HTTPS -->
                    <httpsPort>8443</httpsPort>
                    <keystoreFile>${user.home}/.mvnkeystore</keystoreFile>
                    <keystorePass>changeit</keystorePass>
                    <!-- HTTPS -->

                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.25</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat.embed</groupId>
                        <artifactId>tomcat-embed-core</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                </dependencies>
            </plugin>

还有 web.xml:

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>securedapp</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

如果我删除 https 标签,uriEncondig 会再次开始工作。

【问题讨论】:

  • 要去试试,还没来得及。感谢您的回答

标签: maven tomcat utf-8 https maven-tomcat-plugin


【解决方案1】:

这是 Apache Tomcat Maven 插件的一个报告错误 - MTOMCAT-264。 有一个开放的PR in github 来修复它。

您可能可以通过使用 serverXml 参数和文档中提到的警告来解决它。

serverXml: 使用 server.xml 注意如果你使用这个,你必须在这个文件中配置你的 webapp 路径。

【讨论】:

  • @Abdelhak 你认为这是good answer吗?如果您改进它,我将删除反对票。否决我的报复答案毫无意义。
  • 这有什么更新吗?好像开了很久了
【解决方案2】:

我认为您需要在服务器中配置 HTTPS 连接器。请参阅here 相关问题。事实上,您在 httpsPort 属性上分配了一个值,这意味着您只需启用连接器(我猜有一些默认值) - 作为 plugin documentation suggests

您需要使用以下内容配置连接器:

<Connector port="443" protocol="HTTP/1.1"
           maxThreads="150" connectionTimeout="20000"
           SSLEnabled="true" scheme="https" secure="true"
           keystoreFile="conf/.keystore"
           keystorePass="changeit"
           clientAuth="false" sslProtocol="TLS"
           URIEncoding="UTF-8" compression="on"/>

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2020-05-20
    • 2015-01-09
    • 1970-01-01
    • 1970-01-01
    • 2016-12-24
    • 2018-11-25
    • 1970-01-01
    • 1970-01-01
    • 2019-03-23
    相关资源
    最近更新 更多