我需要在Camel中實現一個簡單的Http-Proxy來記錄傳入的WebService請求的遠程IP地址。在Intellij外運行Camel時,HttpServletRequest強制轉換失敗
所以,我有我的路線定義:
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的插件的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>
任何想法可能會導致奇怪的行爲?
請注意製作超級JAR,因爲您可以搞砸了。看到這個FAQ:http://camel.apache.org/how-do-i-use-a-big-uber-jar.html –
切換到maven-shade-plugin。不用找了。 HttpServerletRequest的轉換仍然在Intellij之外返回null。 –