Hi JB:

I am not exactly sure about the internals.

https://camel.apache.org/components/latest/others/attachments.html

>From the point of view of my code, it is:

...
Map<String, DataHandler> attachments = exchange.getIn().getAttachments();
...
for (String name : attachments.keySet()) {
                DataHandler dh = attachments.get(name);
                // get the file name
                String filename = dh.getName();

...
}

which basically gets the javax.activation.DataHandler instance of the
attachment

Do you know which particular package I need to import?

In my bundle, I had the following configuration as well

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
        <instructions>
            <Import-Package>
                javax.activation;version=1.1,
                *;resolution:=optional
            </Import-Package>
        </instructions>
    </configuration>
</plugin>

But, this also doesn't seem to help either.

Thank you.

Regards,
Cooshal.

On Thu, Jun 4, 2020 at 3:05 PM Jean-Baptiste Onofre <j...@nanthrax.net> wrote:

> Hi,
>
> How are you looking for the attachment ? In the class loader resource or
> using path ?
>
> I guess your attachement files are not found (either because it’s not
> private package of your bundle, or not imported correctly).
>
> Regards
> JB
>
> > Le 4 juin 2020 à 15:03, Kushal Gautam <kushal.gau...@gmail.com> a écrit
> :
> >
> > Camel Version: 2.20.3
> > Java: Open JDK 1.8.0_242
> > Karaf: 4.2.0
> >
> > Hi:
> >
> > Currently, I am using camel-mail to fetch mails via IMAP.
> >
> > The route is pretty simple and looks like:
> >
> > from("imaps://{{IMAP_SERVER_URL}}"
> >                + "?username={{IMAP_EMAIL_USER}}"
> >                + "&password={{IMAP_EMAIL_PASS}}"
> >                + "&unseen=true"
> >                + "&delete=false"
> >                + "&initialDelay=100"
> >                + "&delay={{IMAP_POLL_DURATION}}")
> > .....
> >
> > My custom processor looks something like below (most of the stuffs taken
> > from the attachments example):
> >
> > ...
> > @Override
> >    public void process(Exchange exchange) throws Exception {
> >
> >        exchange.getIn().setHeader("HAS_ATTACHMENTS", false);
> >
> >        Map<String, DataHandler> attachments =
> > exchange.getIn().getAttachments();
> >
> >        if (attachments.size() > 0) {
> >            for (String name : attachments.keySet()) {
> >                DataHandler dh = attachments.get(name);
> >                // get the file name
> >                String filename = dh.getName();
> >
> >                System.out.println(filename);
> >
> >                // check if the attachment is an xml file
> >                // if not continue to another attachment
> >                if(!filename.endsWith(".xml")) {
> >                    continue;
> >                }
> >
> >                System.out.println("email has an xml attachment");
> >
> >                // get the content and convert it to byte[]
> >                byte[] data = exchange
> >                        .getContext()
> >                        .getTypeConverter()
> >                        .convertTo(byte[].class, dh.getInputStream());
> >
> >                exchange.getIn().setHeader("FILE_NAME", filename);
> >                exchange.getIn().setHeader("HAS_ATTACHMENTS", true);
> >
> >                exchange.getIn().setBody(data);
> >                break;
> >            }
> >        }
> > ...
> >
> > If I send an email with some attachments, this code works perfectly fine
> > when I execute it via Netbeans. But, attachments.size() returns 0 for the
> > same code and same email inside Karaf.
> >
> > Do I need to configure something specific for this?
> >
> > Any inputs on this would be helpful.
> >
> > Thanks,
> > Cooshal.
>
>

Reply via email to