gpt4 book ai didi

java - 在 Intellij 之外运行 Camel 时,HttpServletRequest 转换失败

转载 作者:行者123 更新时间:2023-11-29 08:39:46 32 4
gpt4 key购买 nike

我需要在 Camel 中实现一个简单的 Http-Proxy,以记录传入 WebService 请求的远程 IP 地址。

所以我定义了我的路线:

from("jetty:http://0.0.0.0:" + 8081 + "?matchOnUriPrefix=true&optionsEnabled=true")
.streamCaching()
.process(wiresharkInboundLogger)
.to("jetty:http://localhost:" + 8080 + "?bridgeEndpoint=true&throwExceptionOnFailure=false");

我有我的处理器“wiresharkInboundLogger”:

@Override
public void process(Exchange exchange) throws Exception {

// HttpServletRequest
HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);

if (request == null) {
LOG.warn("No HttpServletRequest available!");
} else {
LOG.info("Client IP: " + request.getRemoteAddr());
}
}

在 Inttelij 中运行时,这就像一个魅力。一旦我通过控制台命令(“java -jar my-camel-app.jar”)在 Intellij 之外运行相同的应用程序,HttpServletRequest 的转换就会返回“null”,当由相同的命令触发时来自 SOAP UI 的请求。

我已经用下面的 maven-plugin 打包了 jar:

<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>my.wireshark.Wireshark</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>

有什么想法可能会导致这种奇怪的行为吗?

最佳答案

Shade 插件需要合并 META-INF 条目。如果不只使用一个类型转换器注册表,而是需要所有类型转换器。

关于java - 在 Intellij 之外运行 Camel 时,HttpServletRequest 转换失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41167606/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com