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.module.ibeans.spi;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.MuleRuntimeException;
11  import org.mule.api.transport.PropertyScope;
12  
13  import java.util.Set;
14  
15  import javax.activation.DataHandler;
16  
17  import org.ibeans.api.IBeanInvocationData;
18  import org.ibeans.api.Request;
19  
20  /**
21   * An implementation of an IBeans {@link org.ibeans.api.Request} that adapts to a {@link org.mule.api.MuleMessage}
22   */
23  public class MuleRequestMessage implements Request
24  {
25      private MuleMessage message;
26      private int timeout = 0;
27      private IBeanInvocationData data;
28  
29      public MuleRequestMessage(IBeanInvocationData data, MuleMessage message)
30      {
31          this.message = message;
32          this.data = data;
33      }
34  
35      public Object getPayload()
36      {
37          return message.getPayload();
38      }
39  
40      public void setPayload(Object payload)
41      {
42          message.setPayload(payload);
43      }
44  
45      public void addHeader(String name, Object value)
46      {
47          message.setOutboundProperty(name, value);
48      }
49  
50      public Object removeHeader(String name)
51      {
52          return message.removeProperty(name, PropertyScope.OUTBOUND);
53      }
54  
55      public Object getHeader(String name)
56      {
57          return message.getOutboundProperty(name);
58      }
59  
60      public Set<String> getHeaderNames()
61      {
62          return message.getOutboundPropertyNames();
63      }
64  
65      public void addAttachment(String name, DataHandler handler)
66      {
67          try
68          {
69              message.addOutboundAttachment(name, handler);
70          }
71          catch (Exception e)
72          {
73              throw new MuleRuntimeException(e);
74          }
75      }
76  
77      public DataHandler removeAttachment(String name)
78      {
79          DataHandler dh = message.getOutboundAttachment(name);
80          try
81          {
82              if(dh!=null)
83              message.removeOutboundAttachment(name);
84          }
85          catch (Exception e)
86          {
87              throw new MuleRuntimeException(e);
88          }
89          return dh;
90      }
91  
92      public DataHandler getAttachment(String name)
93      {
94          return message.getOutboundAttachment(name);
95      }
96  
97      public Set<String> getAttachmentNames()
98      {
99          return message.getOutboundAttachmentNames();
100     }
101 
102     public int getTimeout()
103     {
104         return timeout;
105     }
106 
107     public void setTimeout(int timeout)
108     {
109         this.timeout = timeout;
110     }
111 
112     public IBeanInvocationData getIBeanInvocationData()
113     {
114         return data;
115     }
116 
117     public MuleMessage getMessage()
118     {
119         return message;
120     }
121 }