1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.module.ibeans.spi.support; |
11 | |
|
12 | |
import org.mule.api.MuleContext; |
13 | |
import org.mule.api.MuleException; |
14 | |
import org.mule.api.MuleMessage; |
15 | |
import org.mule.api.endpoint.EndpointBuilder; |
16 | |
import org.mule.api.endpoint.MalformedEndpointException; |
17 | |
import org.mule.api.transformer.Transformer; |
18 | |
import org.mule.config.endpoint.AnnotatedEndpointData; |
19 | |
import org.mule.config.i18n.CoreMessages; |
20 | |
import org.mule.transport.AbstractConnector; |
21 | |
import org.mule.util.UriParamFilter; |
22 | |
|
23 | |
import java.util.ArrayList; |
24 | |
import java.util.HashMap; |
25 | |
import java.util.List; |
26 | |
import java.util.Map; |
27 | |
|
28 | |
import org.apache.commons.logging.Log; |
29 | |
import org.apache.commons.logging.LogFactory; |
30 | |
import org.ibeans.api.channel.CHANNEL; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public class CallRequestEndpoint extends DynamicRequestEndpoint |
41 | |
{ |
42 | |
|
43 | |
|
44 | |
|
45 | 0 | protected transient final Log logger = LogFactory.getLog(CallRequestEndpoint.class); |
46 | |
|
47 | |
private static final long serialVersionUID = 1861985949279708458L; |
48 | |
|
49 | |
|
50 | |
|
51 | 0 | private static List<Transformer> transformers = new ArrayList<Transformer>(); |
52 | 0 | private static List<Transformer> responseTransformers = new ArrayList<Transformer>(); |
53 | |
|
54 | 0 | private UriParamFilter filter = new UriParamFilter(); |
55 | |
|
56 | |
public CallRequestEndpoint(MuleContext context, AnnotatedEndpointData epData) throws MalformedEndpointException |
57 | |
{ |
58 | 0 | super( context, createInboundBuilder(context, epData), epData.getAddress()); |
59 | 0 | } |
60 | |
|
61 | |
@Override |
62 | |
protected void validateUriTemplate(String uri) throws MalformedEndpointException |
63 | |
{ |
64 | 0 | if (uri.indexOf(parser.getStyle().getPrefix()) > -1 && uri.indexOf(":") > uri.indexOf(parser.getStyle().getPrefix())) |
65 | |
{ |
66 | 0 | throw new MalformedEndpointException(CoreMessages.dynamicEndpointsMustSpecifyAScheme(), uri); |
67 | |
} |
68 | 0 | } |
69 | |
|
70 | |
private static EndpointBuilder createInboundBuilder(MuleContext context, AnnotatedEndpointData epData) |
71 | |
{ |
72 | |
try |
73 | |
{ |
74 | 0 | EndpointBuilder builder = context.getEndpointFactory().getEndpointBuilder("dynamic://null"); |
75 | 0 | builder.setExchangePattern(epData.getMep()); |
76 | 0 | builder.setConnector(epData.getConnector()); |
77 | 0 | builder.setName(epData.getName()); |
78 | 0 | builder.setProperties(epData.getProperties() == null ? new HashMap() : epData.getProperties()); |
79 | |
|
80 | 0 | return builder; |
81 | |
} |
82 | 0 | catch (MuleException e) |
83 | |
{ |
84 | 0 | throw new RuntimeException(e); |
85 | |
} |
86 | |
} |
87 | |
|
88 | |
@Override |
89 | |
protected String parseURIString(String uri, MuleMessage message) |
90 | |
{ |
91 | |
|
92 | 0 | Map<String, Object> props = getPropertiesForTemplate(message); |
93 | |
|
94 | 0 | String newUriString = parser.parse(props, uri); |
95 | |
|
96 | 0 | newUriString = filter.filterParamsByValue(newUriString, CallOutboundEndpoint.NULL_PARAM); |
97 | |
|
98 | 0 | return super.parseURIString(newUriString, message); |
99 | |
} |
100 | |
|
101 | |
@Override |
102 | |
protected Map<String, Object> getPropertiesForTemplate(MuleMessage message) |
103 | |
{ |
104 | 0 | Map<String, Object> props = (Map) message.findPropertyInAnyScope(CHANNEL.URI_PARAM_PROPERTIES, null); |
105 | 0 | if (props == null) |
106 | |
{ |
107 | 0 | throw new IllegalStateException(CHANNEL.URI_PARAM_PROPERTIES + " not set on message"); |
108 | |
} |
109 | 0 | return props; |
110 | |
} |
111 | |
|
112 | |
@Override |
113 | |
public List getTransformers() |
114 | |
{ |
115 | 0 | if (transformers.size() == 0) |
116 | |
{ |
117 | |
try |
118 | |
{ |
119 | 0 | transformers.addAll(((AbstractConnector)getConnector()).getDefaultInboundTransformers(this)); |
120 | 0 | for (Transformer tran : transformers) |
121 | |
{ |
122 | 0 | tran.setEndpoint(this); |
123 | 0 | tran.setMuleContext(getMuleContext()); |
124 | 0 | tran.initialise(); |
125 | |
} |
126 | |
} |
127 | 0 | catch (MuleException e) |
128 | |
{ |
129 | 0 | throw new RuntimeException(e); |
130 | 0 | } |
131 | |
} |
132 | 0 | return transformers; |
133 | |
} |
134 | |
|
135 | |
@Override |
136 | |
public List getResponseTransformers() |
137 | |
{ |
138 | 0 | if (responseTransformers.size() == 0) |
139 | |
{ |
140 | |
try |
141 | |
{ |
142 | 0 | responseTransformers.addAll(((AbstractConnector)getConnector()).getDefaultResponseTransformers(this)); |
143 | 0 | for (Transformer tran : responseTransformers) |
144 | |
{ |
145 | 0 | tran.setEndpoint(this); |
146 | 0 | tran.setMuleContext(getMuleContext()); |
147 | 0 | tran.initialise(); |
148 | |
} |
149 | |
} |
150 | 0 | catch (MuleException e) |
151 | |
{ |
152 | 0 | throw new RuntimeException(e); |
153 | 0 | } |
154 | |
} |
155 | 0 | return transformers; |
156 | |
} |
157 | |
} |