从码头到绝对URL的骆驼路线

问题描述 投票:7回答:2

我在OSGi部署了一个Apache Karaf包。我有一个简单的骆驼路线:

    <camelContext trace="true" xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="jetty:http://0.0.0.0:8282/services?handlers=securityHandler&amp;matchOnUriPrefix=true"/>
            <setHeader headerName="CamelHttpQuery">
                <constant>wt=xml&amp;rows=1000000&amp;fl=nid,title&amp;fq=sm_vid_Third_parties_with_which_this_organisation_s_content_can_be_shared:%22Indeed%22</constant>
            </setHeader>
            <to uri="http://172.28.128.158:8983/solr/targetjobs.co.uk.gtimedia.test/select/?"/>

<!--        <split>
                <xpath>//int[@name='nid']</xpath>
            </split>-->
            <convertBodyTo type="java.lang.String" />
        </route>
    </camelContext>

我无法让它发挥作用。当我调用http://localhost:8282/services时,它应该路由到uri下面指定的setHeader。相反,我得到这个例外:

java.lang.IllegalArgumentException:无效的uri:/ services。如果要转发/桥接http端点,则在端点上启用bridgeEndpoint选项:Endpoint [http://172.28.128.158:8983/solr/targetjobs.co.uk.gtimedia.test/select/]

它说我需要启用桥接端点,但这不是端点,它是我试图指向我的路由的绝对URL。

我试图设置Springhere所示,但这也不起作用。我也试图改变这个:

<to uri="http://172.28.128.158:8983/solr/targetjobs.co.uk.gtimedia.test/select/?"/>

对此:

<to uri="jetty//http://172.28.128.158:8983/solr/targetjobs.co.uk.gtimedia.test/select/?"/>

也没有成功。也许有人知道如何从jetty uri路线到绝对url

java routing osgi apache-camel apache-karaf
2个回答
6
投票

你试过bridgeEndpoint吗?如下所述:

http://camel.apache.org/how-to-use-camel-as-a-http-proxy-between-a-client-and-server.html

您的目标网址如下所示:

<to uri="jetty//http://172.28.128.158:8983/solr/targetjobs.co.uk.gtimedia.test/select?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>

0
投票

为我工作:

@Override
public void configure() throws Exception {

  restConfiguration()
    .host("localhost")
    .component("jetty")
    .port("8085");

  rest("/api")

    //NEW ROUTE
    .get("/getResidences")
    .produces("application/json")

    //OLD ROUTE
    .to("http://localhost:3000/api/residences?bridgeEndpoint=true&throwExceptionOnFailure=false");

}

请注意休息配置中的.component(“jetty”)

© www.soinside.com 2019 - 2024. All rights reserved.