camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: OGNL property syntax in documentation does not work
Date Mon, 30 Sep 2013 12:14:05 GMT
Hi

I suggest you send an ICLA to Apache and help fix/improve the docs.
Apache depend on people contributing on the projects.

If you want X fixed on page Y, then please make it super easy for
others to fix/do. Eg post a link and have replace FROM to TO so ppl
can do it easily.



On Fri, Sep 20, 2013 at 3:52 PM, Dale King <dalewking@gmail.com> wrote:
> FYI, probably a better syntax to use for accessing properties that does
> work is properties.foo. Might want to put that in the documentation for
> OGNL. Similarly, request.headers.foo would work for request headers.
>
>
> On Fri, Sep 20, 2013 at 9:49 AM, Dale King <dalewking@gmail.com> wrote:
>
>> To be a little more concrete, according to the documentation you linked
>> to, the following route should log "def" every second:
>>
>>         from("timer:foo")
>>             .setProperty("foo").constant("abcdef")
>>             .setBody().ognl("property('foo').substring(3)")
>>             .log("${body}");
>>
>> Instead it throws an exception every:
>>
>>  [java.lang.NoSuchMethodException:
>> org.apache.camel.language.ognl.RootObject.property(java.lang.String)]
>>
>> If I change property('foo') to properties['foo'] or to getProperty('foo')
>> then it works
>>
>> None of the camel-ognl unit tests cover this use case.
>>
>>
>> On Fri, Sep 20, 2013 at 8:24 AM, Dale King <dalewking@gmail.com> wrote:
>>
>>> The last 2 rows of the variables table shows ways that are supposed to
>>> get properties by name, but I tried to use it and it throws an exception.
>>> The RootObject passed to OGNL has getProperty methods, but OGNL will not
>>> match up property(...) to getProperty() method. OGNL 4 can match
>>> property[name] to getProperty, but that is not released yet and is square
>>> brackets instead of parens.
>>>
>>> You could make property(...) methods but that would only work for reading
>>> the property, not setting the property.
>>>
>>> As it stands now the syntax that works is:
>>>
>>> properties -- Gets map of all properties
>>> properties[name] -- specific property, can be used to get or set
>>> getProperty(name) -- Get specific property
>>> getProperty(name, type) -- Get specific property as type
>>>
>>> I just realized that RootObject is missing any setter methods, e.g.
>>> setProperty. The only way to set a property from within OGNL is using:
>>>
>>>     properties['name'[ = value
>>>
>>> But then again you have the DSL support for setting properties.
>>>  On Sep 20, 2013 1:57 AM, "Claus Ibsen" <claus.ibsen@gmail.com> wrote:
>>>
>>>> Can you post the link to where you found this "mistake". I cannot see
>>>> a problem at
>>>> http://camel.apache.org/ognl
>>>>
>>>> On Fri, Sep 20, 2013 at 12:57 AM, Dale King <dalewking@gmail.com> wrote:
>>>> > In the documentation for the Camel OGNL component it shows the
>>>> following
>>>> > syntax:
>>>> >
>>>> > property(name) Object the property by the given name property(name,
>>>> type) the
>>>> > property by the given name as the given type
>>>> > This syntax does not actually work in camel and I do not see any tests
>>>> that
>>>> > tried to test that it worked.
>>>> >
>>>> > If you change those to getProperty they work. properties[name] also
>>>> works.
>>>> >
>>>> > In OGNL 4, which has not been released yet, property[name] should work.
>>>> > --
>>>> > Dale King
>>>>
>>>>
>>>>
>>>> --
>>>> Claus Ibsen
>>>> -----------------
>>>> Red Hat, Inc.
>>>> Email: cibsen@redhat.com
>>>> Twitter: davsclaus
>>>> Blog: http://davsclaus.com
>>>> Author of Camel in Action: http://www.manning.com/ibsen
>>>>
>>>
>>
>>
>> --
>> Dale King
>>
>
>
>
> --
> Dale King



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Mime
View raw message