On 28 October 2010 09:23, Bruno Dusausoy <[email protected]> wrote:
> Hi,
>
> I have a small question about Endpoint construction.
> I'm trying to construct an endpoint programmatically.
> But I am missing something and I don't know what it is.
>
> Take, for example, a simple case :
>
> public class FileRouteBuilder extends RouteBuilder {
>
>        public void configure() throws Exception {
>
>                FileEndpoint input = new FileEndpoint();
>                input.setCamelContext(getContext());
>                input.setFile(new File("c:/post"));
>                input.setDelete(true);
>
>                FileEndpoint output = new FileEndpoint();
>                output.setCamelContext(getContext());
>                output.setFile(new File("c:/backup"));
>
>                from(input).to(output);
>        }
> }
>
> The endpoint URI for the input is shown, in the log, as :
> [...]
> INFO: Route: route1 started and consuming from: Endpoint[file://c:\post]
> [...]
>
> But, if I use string representation for the same endpoint - at least what
> I'm thinking is the same endpoint -, such as
>
> public class FileRouteBuilder extends RouteBuilder {
>
>        public void configure() throws Exception {
>
>                from("file://c:/post?delete=true").to("file://c:/backup");
>        }
>
> }
>
> I'm getting another URI :
> [...]
> INFO: Route: route1 started and consuming from:
> Endpoint[file://c:/post?delete=true]
> [...]
>
> So, it seems the options are missing.
> Should I call a certain method in order to correctly build the Endpoint
> after setting the options ?

The only real difference is the 2nd version you specify the URI; the
first case the URI is auto-generated. Typically the auto-generated
URIs don't necessarily know which properties to add to the URI as
query arguments (as many properties have smart defaults etc).

You can always set the URI you want it to look like in log statements
if you want; but typically its the same Endpoint object being used
under the covers; so its more a logging issue rather than a
functionality issue.

e.g. you could replace...

  FileEndpoint input = new FileEndpoint();

with

  FileEndpoint input = new FileEndpoint("file://c:/post?delete=true",
new FileComponent());

to get the same logging output

-- 
James
-------
FuseSource
Email: [email protected]
Web: http://fusesource.com
Twitter: jstrachan
Blog: http://macstrac.blogspot.com/

Open Source Integration

Reply via email to