首页 > 解决方案 > Camel - 基于 HTTP 请求内容的重定向

问题描述

我正在尝试使用骆驼根据请求正文的内容重定向 http 请求。

我已经创建了一个用于接收 http 请求的端点,并且我能够使用以下路由成功地将我的请求重定向到不同的 URL;

<route>
    <from uri="servlet:myapptest2?matchOnUriPrefix=true"/>  
    <to uri="http://sampleurl/test?bridgeEndpoint=true&amp;throwExceptionOnFailure=false" />
</route>

但我无法找到检查 http 请求正文的方法。我的 HTTP 请求将具有与此类似的 JSON 正文;

{
    "testLoginRequest": {
            "sampleData1": [{
                    "key1": "val1",
                    "key2": "val2"          
            }],
            "sampleData2": [{
                    "key1": "val1",
                    "key2": "val2"
            }]
    }
}

如果 JSON 包含值“testLoginRequest”,我想将请求重定向到特定 URL。我读到这应该是可能的;

from("direct:test"). 
    choice().
    when(body().contains("javainuse1"))
    .to("jms:queue:javainuse1").       
    otherwise().
    to("jms:queue:otherwise");

由于我必须使用 XML DSL,我尝试实现以下路由,但它似乎不起作用;

<route>
    <from uri="servlet:myapptest3?matchOnUriPrefix=true" /> 
    <choice>
        <when>
            <simple>${body} contains 'testLoginRequest' </simple>
            <to uri="http://sampleurlforlogin/test?bridgeEndpoint=true&amp;throwExceptionOnFailure=false" />
        </when>                         
    </choice>
</route>

我是否遵循正确的方法。我在这里做错了什么?

标签: apache-camelspring-camelspring-dslcamel-http

解决方案


推荐阅读