I am working with camel-mail-starter
version 3.12.0
I have configured the route this way:
String from = protocol + "://" + host + ":" + port + "?username="
+ username + "&password=" + password + "&delete=" + removeAfterConsuming
+ "&mail.pop3.starttls.enable=true&debugMode=true";
RouteBuilder emailListener = new RouteBuilder () {
@Override
public void configure() throws Exception {
from (from)
.process (new EmailProcessor (body, client))
.log("${exchange.message}");
}
};
My Processor
public void process(Exchange exchange) throws Exception {
MailMessage message = exchange.getIn(MailMessage.class);
MimeMessageParser parser = new MimeMessageParser(
(IMAPMessage) message.getOriginalMessage()
);
try {
parser.parse();
} catch (Exception e) {
ApplicationException applicationException = new ApplicationException(
e.getStackTrace(),
Collections.singletonMap("process", " Inside camel mail"),
getClass(), "33"
);
applicationException.notifyViaEmail();
}
}
When I run this, I get the following exception
Caused by: org.apache.camel.component.bean.AmbiguousMethodCallException: Ambiguous method invocations possible: [public abstract org.apache.camel.Message org.apache.camel.Exchange.getMessage(), public abstract java.lang.Object org.apache.camel.Exchange.getMessage(java.lang.Class)] on the exchange: Exchange[166D4FAD964C49D-0000000000000000]
I don't know what I am doing wrong
Your mistake is in the simple language expression used in the log EIP, indeed the expression ${exchange.message}
asks Camel to call dynamically the method getMessage
on the current exchange but as mentioned in the error message, there are 2 existing methods called getMessage
in Exchange
which are getMessage()
and getMessage(java.lang.Class)
and Camel has no way to know which one to call which causes this specific exception.
I don't know what you wanted to log but if it is the body of your message the expected expression is rather ${body}
. Please refer to the doc about the simple language for more details.