1
2
3
4
5
6
7 package org.mule.transport.vm.functional;
8
9 import org.mule.DefaultMuleMessage;
10 import org.mule.api.MuleEventContext;
11 import org.mule.api.MuleMessage;
12 import org.mule.api.lifecycle.Callable;
13
14 import java.io.File;
15
16 import javax.activation.DataHandler;
17 import javax.activation.FileDataSource;
18
19
20
21
22
23 public class AttachmentsComponent implements Callable
24 {
25 public Object onCall(MuleEventContext eventContext) throws Exception
26 {
27 MuleMessage msg = eventContext.getMessage();
28 if (msg.getInboundAttachmentNames().size() == 2)
29 {
30 throw new IllegalArgumentException("There shuold be 2 attachments");
31 }
32
33 DataHandler dh = msg.getInboundAttachment("test-attachment");
34 if (dh == null)
35 {
36 throw new IllegalArgumentException("test-attachment is not on the message");
37 }
38 if (!dh.getContentType().startsWith("text/xml"))
39 {
40 throw new IllegalArgumentException("content type is not text/xml");
41 }
42
43 if (!"Mmm... attachments!".equals(msg.getPayloadAsString()))
44 {
45 throw new IllegalArgumentException("payload is incorrect");
46 }
47
48 MuleMessage result = new DefaultMuleMessage("here is one for you!", eventContext.getMuleContext());
49 FileDataSource ds = new FileDataSource(
50 new File("transports/vm/src/test/resources/test.gif").getAbsoluteFile());
51 result.addOutboundAttachment("mule", new DataHandler(ds));
52 return result;
53 }
54 }