有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

从Jetty到绝对URL的java驼峰路线

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

    <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时,它应该路由到setHeader下面指定的uri。相反,我得到了一个例外:

java.lang.IllegalArgumentException: Invalid uri: /services. If you are forwarding/bridging http endpoints, then enable the bridgeEndpoint option on the endpoint: Endpoint[http://172.28.128.158:8983/solr/targetjobs.co.uk.gtimedia.test/select/]

它说我需要启用网桥端点,但这不是一个端点,而是一个我试图指向的绝对URL

我试图设置Spring,如图所示here,但这也不起作用。我还试图改变这一点:

<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{}路由到绝对url


共 (2) 个答案

  1. # 2 楼答案

    为我工作:

    @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");
    
    }
    

    请注意。rest配置中的componet(“jetty”)