Hi,

maybe I'm wrong but I think it's not possible to set the Id of an Endpoint
even if you would cast the:

org.apache.camel.Endpoint

reference you've got inside your route to:

org.apache.camel.impl.DefaultEndpoint

as the id field is declared to be final so that there's no setter method
provided...

Of course you could still set it through the reflection-API (since JDK 1.6
it's possible to set even a final field) but that would be IMHO really a
hack:

        CamelContext context = new DefaultCamelContext();
        DefaultEndpoint endpoint =
(DefaultEndpoint)context.getEndpoint("file:foo");

        System.out.println(endpoint.getId());

        Field id = DefaultEndpoint.class.getDeclaredField("id");
        id.setAccessible(true);
        id.set(endpoint, "endpoint2");

        System.out.println(endpoint.getId());

Which prints:

endpoint1
endpoint2

But again, this's really not nice.

Babak


Babak

--
View this message in context: 
http://camel.465427.n5.nabble.com/How-to-set-endpoint-id-in-Java-dsl-tp5080518p5080679.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to