Camel Route from Jetty to Absolute URL
Asked Answered
N

2

8

I have an OSGi bundle deployed on Apache Karaf. I have a simple camel route:

    <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>

I can not get it working. When I invoke http://localhost:8282/services it should route to the uri specified in below the setHeader. Instead I am getting this exception:

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/]

It says that I need to enable bridge endpoint, but this is not an endpoint, it is an absolute URL to which I am trying to point my route.

I have tried to set up Spring as shown here but this did not work either.I have also tried to change this:

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

to this:

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

No success as well. Maybe someone knows how to route from jetty uri to absolute url?

Nikolia answered 21/8, 2012 at 15:41 Comment(1)
Can you please post how you solved your problemSoapstone
T
7

Have you tried bridgeEndpoint? As described below:

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

Your target url will look like:

<to uri="jetty//http://172.28.128.158:8983/solr/targetjobs.co.uk.gtimedia.test/select?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>
Toilette answered 22/8, 2012 at 9:33 Comment(1)
I've solved the problem the other way around, but anyway, thanks, I think I will need that in future, so I will try that :)Nikolia
B
0

Worked for me:

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

}

Note the .componet("jetty") in rest configuration

Botvinnik answered 12/4, 2019 at 20:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.