View Javadoc

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