Hi I am adding a function to simple language so this can be done via simple in the future https://issues.apache.org/jira/browse/CAMEL-20127
At first its a bit long in the tooth ${messageAs(org.apache.camel.language.simple.MyAttachmentMessage).hasAttachments} On Sun, Nov 19, 2023 at 12:55 PM Claus Ibsen <claus.ib...@gmail.com> wrote: > Hi > > You can look in the source of camel-attachments and see how they are > stored and then do it by checking for exchange property > key CamelAttachmentObjects exists and is not empty > > On Tue, Nov 14, 2023 at 9:21 PM ski n <raymondmees...@gmail.com> wrote: > >> As a workaround, I implemented it as follows: >> >> public class MyBean { >> >> public boolean hasAttachements(Exchange exchange) { >> return >> exchange.getIn(AttachmentMessage.class).hasAttachments(); >> } >> >> } >> >> And then call it from the Java DSL as: >> >> <method beanType="org.assimbly.attachement.MyBean" >> method="hasAttachements"/> >> >> If there are better solution, I like to hear it. >> >> Raymond >> >> >> On Tue, Nov 14, 2023 at 8:12 PM ski n <raymondmees...@gmail.com> wrote: >> >> > >> > I need to check if a message has an attachment. >> > >> > In Camel2 I used the following expression: >> > >> > <simple>${exchange.getIn().hasAttachments}</simple> >> > >> > As attachment was modularized in Camel 3, the hasAttachments method >> isn't >> > directly available on the exchange anymore (it now extends Message). >> > >> > Based on the documentation: >> > >> > https://camel.apache.org/components/3.20.x/others/attachments.html >> > >> > I tried: >> > >> > >> <simple>${exchange.getIn(AttachmentMessage.class).hasAttachments}</simple> >> > >> > Using Java code directly this works, but from the XML DSL this gives: >> > >> > org.apache.camel.component.bean.ParameterBindingException: Error during >> > parameter binding on method: public abstract java.lang.Object >> > org.apache.camel.Exchange.getIn(java.lang.Class) at parameter #0 with >> type: >> > class java.lang.Class with value type: class java.lang.String and value: >> > AttachmentMessage.class >> > >> > The parameter is seen as a String object, instead of AttachmentMessage >> > object. How to properly pass the type parameter in the XML DSL with a >> > simple expression? If there is an alternative way to check attachments >> this >> > also fine, but I'm trying to avoid using processors or bean invocation >> > though. >> > >> > Raymond >> > >> > >> > > > -- > Claus Ibsen > ----------------- > @davsclaus > Camel in Action 2: https://www.manning.com/ibsen2 > -- Claus Ibsen ----------------- @davsclaus Camel in Action 2: https://www.manning.com/ibsen2