View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.api.annotations.param;
8   
9   import org.mule.util.StringDataSource;
10  
11  import java.util.List;
12  import java.util.Map;
13  
14  import javax.activation.DataHandler;
15  
16  /**
17   * Tests various cases for how attachments can added to an outbound message through a generic map by injecting the
18   * map into a component invocation
19   */
20  public class OutboundAttachmentsAnnotationComponent
21  {
22      public Map<?, ?> processAttachments(@OutboundAttachments Map<String, DataHandler> attachments)
23      {
24          attachments.put("bar", new DataHandler(new StringDataSource("barValue")));
25          //Verify that we receive any outbound attachments already set on the message
26          if (attachments.containsKey("foo"))
27          {
28              //Overwrite the existing attachment to signal that we received it
29              attachments.put("foo", new DataHandler(new StringDataSource("fooValue")));
30          }
31          return attachments;
32      }
33  
34      //Can only use the {@link OutboundAttachments} annotation on Map parameters
35      public List<?> invalidParamType(@OutboundAttachments List<?> attachments)
36      {
37          return attachments;
38      }
39  }