One Star

[resolved] Only 1 attachment detected in CXF Soap headers

Hello,
In the mediation view I created a CXF SOAP endpoint (payload) that I route to a job. In the Job I set the routeinput to pass the headers as a raw format (object type) that I connect to a tJavaFlex. In the tJavaFlex I then search for attachments. Everything works ok for 1 attachment. But if I send 2 attachments only the first one is detected.
Here is the code of the tJavaFlex (part of it I found in the forums) :

CaseInsensitiveMap headers = (CaseInsensitiveMap)to_attachment.headers;
Iterator<Object> it = headers.values().iterator();
SoapMessage msg = null;
while (it.hasNext()) {
    Object obj = it.next();
    if (obj instanceof SoapMessage) {
        msg = (SoapMessage)obj;
    }
}
if (msg != null) {
    Collection<Attachment> attachments = (Collection<Attachment>)msg.getAttachments();
    if (attachments != null) {
        System.out.println("Found Attachments-->");
        File dataDir = new File(context.appdir + "/" + to_attachment.flowid);
        dataDir.mkdir();
        Iterator<Attachment> iter = attachments.iterator();
        while (iter.hasNext()) {
            Attachment attachment = iter.next();
            DataHandler data = attachment.getDataHandler();
            InputStream is = data.getInputStream();
            File dataFile = new File(dataDir + "/" + data.getName());
            System.out.println("Writing data to:\n\t" + dataFile.toString());    
            FileOutputStream fos = new FileOutputStream(dataFile);
            IOUtils.copy(is, fos);
            fos.close();  
        }
    } else System.out.println("No Attachment!");
}

Product : "Talend Open Studio for ESB" Version: 5.6.1 Build id: V5.6.1_20141207_1530
Product :TESB_SE-V5.6.1
Is there anything I can do or is it a bug ?
Thanks,
JGS
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] Only 1 attachment detected in CXF Soap headers

Just a reply to myself, it is not a bug : the attachment can be a MultiPart object that has to parsed for every Part contained.
Done!
2 REPLIES
One Star

Re: [resolved] Only 1 attachment detected in CXF Soap headers

Just a reply to myself, it is not a bug : the attachment can be a MultiPart object that has to parsed for every Part contained.
Done!
Community Manager

Re: [resolved] Only 1 attachment detected in CXF Soap headers

Thanks for sharing the resolution before we had the time to step in! Smiley Happy
Elisa