我正在生成一个项目站点
mvn site
Linkcheck 作为报告插件激活
<reporting>
<plugins>
(...)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-linkcheck-plugin</artifactId>
<version>1.2</version>
</plugin>
</plugins>
</reporting>
代码是用 Java 编写的。
例如,类文件的注释标题包含指向 StackOverflow 问题的链接
/**
* Example written by Bruno Lowagie in answer to:
* https://stackoverflow.com/questions/26853894/continue-field-output-on-second-page-with-itextsharp
*/
在网站生成的链接检查阶段,我收到如下警告:
[ WARN] Cookie rejected: "$Version=0; __cfduid=dab443ca4b7fc1de5130856b7401f83cb1455551507; $Path=/; $Domain=.stackoverflow.com". Illegal domain attribute ".stackoverflow.com". Domain of origin: "stackoverflow.com"
[ WARN] Cookie rejected: "$Version=0; logged_in=no; $Path=/; $Domain=.github.com". Illegal domain attribute ".github.com". Domain of origin: "github.com"
我已经看过一些关于“Cookie 被拒绝:非法域属性”的其他 SO 问题。根据this aswer ,问题不在我这边,是 StackOverflow 和 GitHub 设置了不允许发送的 cookie,maven-linkcheck-plugin
的底层 http 库告诉我这一点。此行为完全符合 RFC 2109 的规定。 .
链接的问题提供了一个解决方法:在 httpclient
中设置一个 cookie 策略,基本上说,我不关心坏 cookie,给我给我给我。我需要对不兼容的服务器有容忍度,所以我需要使用 cookie guide 中描述的浏览器兼容性 cookie 规范.
我的问题是:因为我不是在使用 httpclient
,而是在使用 maven
,所以我要在 pom.xml
中添加什么摆脱这些 cookie 警告?我没有发现任何有用的东西
- maven-linkcheck-plugin documentation
- Doxia LinkCheck documentation (Maven插件使用Doxia)
- This Doxia JIRA query作为背景信息读起来很有趣,但仍然没有 Maven 解决方案
最佳答案
我也受到这个问题的影响。
您提到的链接检查文档显示有一个 httpClientParameters configuration option .
httpClientParameters:
The extra HttpClient parameters to be used when fetching links. For instance:
<httpClientParameters> <property> <name>http.protocol.max-redirects</name> <value>10</value> </property> </httpClientParameters>
底部的链接显示 http.protocol.cookie-policy
是 HttpClient 参数之一。
理论上,您可以在您的pom中执行以下操作来配置底层的httpclient:
<reporting>
<plugin>
<artifactId>maven-linkcheck-plugin</artifactId>
<version>1.2</version>
<configuration>
<httpClientParameters>
<property>
<name>http.protocol.cookie-policy</name>
<value>ignoreCookies</value>
</property>
</httpClientParameters>
</configuration>
</plugin>
</reporting>
其中 ignoreCookies
是 CookiePolicy.IGNORE_COOKIES 的字符串值.
在实践中,这是行不通的。正如你提到的,这里有层,maven-linkcheck-plugin -> doxia-linkcheck -> httpclient。调试报告生成,我可以看到 MLP 将参数传递给 doxia-linkcheck 但是 right about here不幸的事情发生了。
if ( this.cl == null )
{
initHttpClient();
}
if ( this.http.getHttpClientParameters() != null )
{
for ( Map.Entry<Object, Object> entry : this.http.getHttpClientParameters().entrySet() )
{
if ( entry.getValue() != null )
{
System.setProperty( entry.getKey().toString(), entry.getValue().toString() );
}
}
}
cl
是将发出请求的 httpclient,http
是 bean它保存着在 pom.xml 中配置的值。 bean 属性没有将它们放在一起,而是被转储到系统属性空间中,而 httpclient 并不在那里。有一个值得注意的异常(exception),http.protocol.max-redirects
在代码的其他地方得到特殊处理,巧合的是 maven‑linkcheck‑plugin 文档中使用的示例。所以看起来这个通用功能实际上是针对特定的东西,而忽略了通用用例。
那么,我们已经用尽了正确配置它的能力,还剩下什么?我们可以让记录器静音。 Maven 使用 SLF4J与 SimpleLogger这些天,但 doxia‑linkcheck 正在使用带有 log4j 1.2.14 的 commons‑logging。旧的 log4j 对于我们作为外部用户重新配置不是很容易,但是我们可以通过将 maven‑linkcheck‑plugin 添加到 pluginManagement 部分并添加桥接依赖项来填充到 SLF4J 上:
<pluginManagement>
<plugin>
<artifactId>maven-linkcheck-plugin</artifactId>
<version>1.2</version>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.28</version>
</dependency>
</dependencies>
</plugin>
</pluginManagement>
您现在可以通过提高相关记录器的日志级别来隐藏警告:
mvn site -Dorg.slf4j.simpleLogger.log.org.apache.commons.httpclient.HttpMethodBase=error
作为奖励,插件中剩余的日志现在使用 maven 的日志系统而不是 log4j,因此您可以获得彩色输出和一致的格式。
但是,您可能不想在每次生成站点时都指定该系统属性来调整日志。我推荐.mvn/jvm.config文件:
mkdir -p .mvn && cd .mvn
echo "-Dorg.slf4j.simpleLogger.log.org.apache.commons.httpclient.HttpMethodBase=error" >>jvm.config
如果你真的想把它全部保存在 pom 中,还有 properties-maven-plugin .
这一切都是为了在 doxia-linkcheck 中更好地修复的东西,但最近没有看到太多发展。
关于java - 链接检查期间的 maven-linkcheck-plugin 警告 : cookie rejected, 非法域属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35414355/