org.apache.camel.Processor 获取源ip地址 [英] org.apache.camel.Processor get source ip address

查看:24
本文介绍了org.apache.camel.Processor 获取源ip地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样调用处理器的camelContext拦截器.您可以在此处查看我的 spring.xml.

I have a camelContext interceptor that calls a Processor like this. You can see my spring.xml here.

import org.apache.camel.Processor;

public class CaptureProcessor implements Processor
{
    @Override
    public void process(Exchange exch) throws Exception
    {
            ....
    }    

是否可以在 Exchange 对象中找到客户端的源 IP 地址?

Is it possible to find the Client's Source IP address in the Exchange object?

请注意,本文通过将 Message 正文提取为 HttpServerletRequest 不适用,因为我的是一个简单的 REST 服务并且没有实现 serverlet.我的输入消息正文是一个字符串.

Note that this article that finds the IP addrerss by extracting the Message body as an HttpServerletRequest is not applicable because mine is a simple REST service and does not implement a serverlet. My input Message body is a String.

推荐答案

您可以提取 ip 与属性 X-forwarded-for 交换头的ip :

You can extract the ip in exchange header's with property X-forwarded-for :

String ip=exchange.getIn().getHeader("X-forwarded-for");

这篇关于org.apache.camel.Processor 获取源ip地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆