【发布时间】:2016-12-15 15:19:39
【问题描述】:
我需要在 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>
有什么可能导致这种奇怪行为的想法吗?
【问题讨论】:
-
在制作 uber JAR 时要小心,因为这样会搞砸。请参阅此常见问题解答:camel.apache.org/how-do-i-use-a-big-uber-jar.html
-
切换到 maven-shade-plugin。没变。 HttpServerletRequest 的转换仍然在 Intellij 之外返回 null。
标签: java maven intellij-idea apache-camel jetty