Airomega
Airomega

Reputation: 594

Camel AmbiguousMethodCallException Abstract Classes

I've got three classes

public abstract FoundationReport
{
    public abstract FoundationDetails getDetails();
}

public abstract BaseReport extends FoundationReport
{
    public abstract BaseDetails getDetails();
}

public Report extends BaseReport
{

    ReportDetails reportDetails;

    public ReportDetails getDetails()
    {
        return reportDetails
    }
}

ReportDetails extends BaseDetails, BaseDetails extends FoundationDetails.

In my camel xml I've got a section:

<convertBodyTo type="path.to.Report" />
        <when>
            <simple>${body.details.type} == 'myself'</simple>
...

However the call to body.details.type results in:

Caused by: org.apache.camel.component.bean.AmbiguousMethodCallException:     
Ambiguous method invocations possible: 
[public path.to.ReportDetails  path.to.Report.getDetails(), 
public abstract path.to.BaseDetails path.to.BaseReport.getDetails(), 
public abstract path.to.FoundationDetails path.to.FoundationReport()]

I had assumed (incorrectly) that the only concrete implementation of getDetails in the Report class would be used. Why am I getting this exception and how do I work around?

Upvotes: 3

Views: 1515

Answers (2)

Airomega
Airomega

Reputation: 594

* UPDATE *

I've marked this as the answer as this has solved my problem using the current version of camel. However Claus Ibsen's answer/bug fix will likely address this situation in subsequent camel releases.


I believe I've found a workaround by using ognl instead of simple - it's not pretty but it works.

I've replaced <simple>${body.details.type} == 'myself'</simple>

with

<ognl>exchange.getIn().getBody().getDetails().getType() == 'myself'</ognl>

My thinking was that I need to access the object itself rather than rely on expected getter signatures based on variable name. It seems to work!

Upvotes: 0

Claus Ibsen
Claus Ibsen

Reputation: 55555

Its a bug in Apache Camel. I have reproduced it, and logged a ticket to get this fixed: https://issues.apache.org/jira/browse/CAMEL-9032

Upvotes: 1

Related Questions