1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.endpoint; |
8 | |
|
9 | |
import org.mule.MessageExchangePattern; |
10 | |
import org.mule.api.MuleContext; |
11 | |
import org.mule.api.MuleException; |
12 | |
import org.mule.api.MuleMessage; |
13 | |
import org.mule.api.construct.FlowConstruct; |
14 | |
import org.mule.api.endpoint.EndpointMessageProcessorChainFactory; |
15 | |
import org.mule.api.endpoint.EndpointURI; |
16 | |
import org.mule.api.endpoint.InboundEndpoint; |
17 | |
import org.mule.api.lifecycle.LifecycleException; |
18 | |
import org.mule.api.processor.MessageProcessor; |
19 | |
import org.mule.api.retry.RetryPolicyTemplate; |
20 | |
import org.mule.api.routing.filter.Filter; |
21 | |
import org.mule.api.security.EndpointSecurityFilter; |
22 | |
import org.mule.api.transaction.TransactionConfig; |
23 | |
import org.mule.api.transformer.Transformer; |
24 | |
import org.mule.api.transport.Connector; |
25 | |
import org.mule.config.i18n.CoreMessages; |
26 | |
import org.mule.transport.ConnectException; |
27 | |
|
28 | |
import java.util.List; |
29 | |
import java.util.Map; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public class DynamicURIInboundEndpoint implements InboundEndpoint |
35 | |
{ |
36 | |
|
37 | |
private static final long serialVersionUID = -2814979100270307813L; |
38 | |
|
39 | |
protected InboundEndpoint endpoint; |
40 | |
private EndpointURI dynamicEndpointURI; |
41 | |
private MessageProcessor listener; |
42 | |
private FlowConstruct flowConstruct; |
43 | |
|
44 | |
public DynamicURIInboundEndpoint(InboundEndpoint endpoint) |
45 | |
{ |
46 | 0 | this(endpoint, null); |
47 | 0 | } |
48 | |
|
49 | |
public DynamicURIInboundEndpoint(InboundEndpoint endpoint, EndpointURI dynamicEndpointURI) |
50 | 0 | { |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | 0 | this.endpoint = endpoint; |
57 | 0 | setEndpointURI(dynamicEndpointURI); |
58 | 0 | } |
59 | |
|
60 | |
public EndpointURI getEndpointURI() |
61 | |
{ |
62 | 0 | if (dynamicEndpointURI != null) |
63 | |
{ |
64 | 0 | return dynamicEndpointURI; |
65 | |
} |
66 | |
else |
67 | |
{ |
68 | 0 | return endpoint.getEndpointURI(); |
69 | |
} |
70 | |
} |
71 | |
|
72 | |
public String getAddress() |
73 | |
{ |
74 | 0 | EndpointURI uri = getEndpointURI(); |
75 | 0 | if (uri != null) |
76 | |
{ |
77 | 0 | return uri.getUri().toString(); |
78 | |
} |
79 | |
else |
80 | |
{ |
81 | 0 | return null; |
82 | |
} |
83 | |
} |
84 | |
|
85 | |
public void setEndpointURI(EndpointURI dynamicEndpointURI) |
86 | |
{ |
87 | 0 | this.dynamicEndpointURI = dynamicEndpointURI; |
88 | 0 | } |
89 | |
|
90 | |
public RetryPolicyTemplate getRetryPolicyTemplate() |
91 | |
{ |
92 | 0 | return endpoint.getRetryPolicyTemplate(); |
93 | |
} |
94 | |
|
95 | |
public Connector getConnector() |
96 | |
{ |
97 | 0 | return endpoint.getConnector(); |
98 | |
} |
99 | |
|
100 | |
public String getEncoding() |
101 | |
{ |
102 | 0 | return endpoint.getEncoding(); |
103 | |
} |
104 | |
|
105 | |
public String getMimeType() |
106 | |
{ |
107 | 0 | return endpoint.getMimeType(); |
108 | |
} |
109 | |
|
110 | |
public Filter getFilter() |
111 | |
{ |
112 | 0 | return endpoint.getFilter(); |
113 | |
} |
114 | |
|
115 | |
public String getInitialState() |
116 | |
{ |
117 | 0 | return endpoint.getInitialState(); |
118 | |
} |
119 | |
|
120 | |
public MuleContext getMuleContext() |
121 | |
{ |
122 | 0 | return endpoint.getMuleContext(); |
123 | |
} |
124 | |
|
125 | |
public String getName() |
126 | |
{ |
127 | 0 | return endpoint.getName(); |
128 | |
} |
129 | |
|
130 | |
public Map getProperties() |
131 | |
{ |
132 | 0 | return endpoint.getProperties(); |
133 | |
} |
134 | |
|
135 | |
public Object getProperty(Object key) |
136 | |
{ |
137 | 0 | return endpoint.getProperty(key); |
138 | |
} |
139 | |
|
140 | |
public String getProtocol() |
141 | |
{ |
142 | 0 | return endpoint.getProtocol(); |
143 | |
} |
144 | |
|
145 | |
public int getResponseTimeout() |
146 | |
{ |
147 | 0 | return endpoint.getResponseTimeout(); |
148 | |
} |
149 | |
|
150 | |
public List<Transformer> getResponseTransformers() |
151 | |
{ |
152 | 0 | return endpoint.getResponseTransformers(); |
153 | |
} |
154 | |
|
155 | |
public EndpointMessageProcessorChainFactory getMessageProcessorsFactory() |
156 | |
{ |
157 | 0 | return endpoint.getMessageProcessorsFactory(); |
158 | |
} |
159 | |
|
160 | |
public List <MessageProcessor> getMessageProcessors() |
161 | |
{ |
162 | 0 | return endpoint.getMessageProcessors(); |
163 | |
} |
164 | |
|
165 | |
public List<MessageProcessor> getResponseMessageProcessors() |
166 | |
{ |
167 | 0 | return endpoint.getResponseMessageProcessors(); |
168 | |
} |
169 | |
|
170 | |
public EndpointSecurityFilter getSecurityFilter() |
171 | |
{ |
172 | 0 | return endpoint.getSecurityFilter(); |
173 | |
} |
174 | |
|
175 | |
public TransactionConfig getTransactionConfig() |
176 | |
{ |
177 | 0 | return endpoint.getTransactionConfig(); |
178 | |
} |
179 | |
|
180 | |
public List<Transformer> getTransformers() |
181 | |
{ |
182 | 0 | return endpoint.getTransformers(); |
183 | |
} |
184 | |
|
185 | |
public boolean isDeleteUnacceptedMessages() |
186 | |
{ |
187 | 0 | return endpoint.isDeleteUnacceptedMessages(); |
188 | |
} |
189 | |
|
190 | |
public boolean isReadOnly() |
191 | |
{ |
192 | 0 | return endpoint.isReadOnly(); |
193 | |
} |
194 | |
|
195 | |
public MessageExchangePattern getExchangePattern() |
196 | |
{ |
197 | 0 | return endpoint.getExchangePattern(); |
198 | |
} |
199 | |
|
200 | |
public MuleMessage request(long timeout) throws Exception |
201 | |
{ |
202 | 0 | return getConnector().request(this, timeout); |
203 | |
} |
204 | |
|
205 | |
public String getEndpointBuilderName() |
206 | |
{ |
207 | 0 | return endpoint.getEndpointBuilderName(); |
208 | |
} |
209 | |
|
210 | |
public boolean isProtocolSupported(String protocol) |
211 | |
{ |
212 | 0 | return getConnector().supportsProtocol(protocol); |
213 | |
} |
214 | |
|
215 | |
public boolean isDisableTransportTransformer() |
216 | |
{ |
217 | 0 | return endpoint.isDisableTransportTransformer(); |
218 | |
} |
219 | |
|
220 | |
@Override |
221 | |
public int hashCode() |
222 | |
{ |
223 | 0 | final int prime = 31; |
224 | 0 | int result = 1; |
225 | 0 | result = prime * result + ((dynamicEndpointURI == null) ? 0 : dynamicEndpointURI.hashCode()); |
226 | 0 | result = prime * result + ((endpoint == null) ? 0 : endpoint.hashCode()); |
227 | 0 | return result; |
228 | |
} |
229 | |
|
230 | |
@Override |
231 | |
public boolean equals(Object obj) |
232 | |
{ |
233 | 0 | if (this == obj) |
234 | |
{ |
235 | 0 | return true; |
236 | |
} |
237 | 0 | if (obj == null) |
238 | |
{ |
239 | 0 | return false; |
240 | |
} |
241 | 0 | if (getClass() != obj.getClass()) |
242 | |
{ |
243 | 0 | return false; |
244 | |
} |
245 | 0 | final DynamicURIInboundEndpoint other = (DynamicURIInboundEndpoint) obj; |
246 | 0 | if (dynamicEndpointURI == null) |
247 | |
{ |
248 | 0 | if (other.dynamicEndpointURI != null) |
249 | |
{ |
250 | 0 | return false; |
251 | |
} |
252 | |
} |
253 | 0 | else if (!dynamicEndpointURI.equals(other.dynamicEndpointURI)) |
254 | |
{ |
255 | 0 | return false; |
256 | |
} |
257 | 0 | if (endpoint == null) |
258 | |
{ |
259 | 0 | if (other.endpoint != null) |
260 | |
{ |
261 | 0 | return false; |
262 | |
} |
263 | |
} |
264 | 0 | else if (!endpoint.equals(other.endpoint)) |
265 | |
{ |
266 | 0 | return false; |
267 | |
} |
268 | 0 | return true; |
269 | |
} |
270 | |
|
271 | |
public void start() throws MuleException |
272 | |
{ |
273 | |
try |
274 | |
{ |
275 | 0 | getConnector().registerListener(this, listener, flowConstruct); |
276 | |
} |
277 | |
|
278 | 0 | catch (ConnectException ce) |
279 | |
{ |
280 | 0 | throw ce; |
281 | |
} |
282 | 0 | catch (Exception e) |
283 | |
{ |
284 | 0 | throw new LifecycleException(CoreMessages.failedToStartInboundEndpoint(this), e, this); |
285 | 0 | } |
286 | 0 | } |
287 | |
|
288 | |
public void stop() throws MuleException |
289 | |
{ |
290 | |
try |
291 | |
{ |
292 | 0 | getConnector().unregisterListener(this, flowConstruct); |
293 | |
} |
294 | 0 | catch (Exception e) |
295 | |
{ |
296 | 0 | throw new LifecycleException(CoreMessages.failedToStartInboundEndpoint(this), e, this); |
297 | 0 | } |
298 | 0 | } |
299 | |
|
300 | |
public void setFlowConstruct(FlowConstruct flowConstruct) |
301 | |
{ |
302 | 0 | this.flowConstruct = flowConstruct; |
303 | 0 | } |
304 | |
|
305 | |
public void setListener(MessageProcessor listener) |
306 | |
{ |
307 | 0 | this.listener = listener; |
308 | 0 | } |
309 | |
} |