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 <dalewk...@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 <dalewk...@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.ib...@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 <dalewk...@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: cib...@redhat.com
>>> Twitter: davsclaus
>>> Blog: http://davsclaus.com
>>> Author of Camel in Action: http://www.manning.com/ibsen
>>>
>>
>
>
> --
> Dale King
>



-- 
Dale King

Reply via email to