1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.transport.ajax.container; |
11 | |
|
12 | |
import org.mule.api.MuleContext; |
13 | |
import org.mule.api.MuleException; |
14 | |
import org.mule.api.construct.FlowConstruct; |
15 | |
import org.mule.api.endpoint.ImmutableEndpoint; |
16 | |
import org.mule.api.endpoint.InboundEndpoint; |
17 | |
import org.mule.api.transport.MessageReceiver; |
18 | |
import org.mule.api.transport.ReplyToHandler; |
19 | |
import org.mule.transport.AbstractConnector; |
20 | |
import org.mule.transport.ajax.AjaxMessageReceiver; |
21 | |
import org.mule.transport.ajax.AjaxReplyToHandler; |
22 | |
import org.mule.transport.ajax.BayeuxAware; |
23 | |
import org.mule.transport.ajax.embedded.AjaxConnector; |
24 | |
import org.mule.transport.servlet.ServletConnector; |
25 | |
|
26 | |
import org.cometd.DataFilter; |
27 | |
import org.mortbay.cometd.AbstractBayeux; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
public class AjaxServletConnector extends ServletConnector implements BayeuxAware |
34 | |
{ |
35 | |
public static final String PROTOCOL = "ajax-servlet"; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | private int interval = INT_VALUE_NOT_SET; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | private int maxInterval = INT_VALUE_NOT_SET; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | 0 | private int multiFrameInterval = INT_VALUE_NOT_SET; |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | 0 | private int logLevel = INT_VALUE_NOT_SET; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | 0 | private int timeout = INT_VALUE_NOT_SET; |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | 0 | private boolean jsonCommented = true; |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
private String filters; |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | 0 | private boolean requestAvailable = true; |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | 0 | private int refsThreshold = INT_VALUE_NOT_SET; |
90 | |
|
91 | |
|
92 | |
protected AbstractBayeux bayeux; |
93 | |
|
94 | |
public AjaxServletConnector(MuleContext context) |
95 | |
{ |
96 | 0 | super(context); |
97 | 0 | registerSupportedProtocolWithoutPrefix(AjaxConnector.PROTOCOL); |
98 | |
|
99 | 0 | setInitialStateStopped(true); |
100 | 0 | } |
101 | |
|
102 | |
public AbstractBayeux getBayeux() |
103 | |
{ |
104 | 0 | return bayeux; |
105 | |
} |
106 | |
|
107 | |
public void setBayeux(AbstractBayeux bayeux) throws MuleException |
108 | |
{ |
109 | 0 | this.bayeux = bayeux; |
110 | 0 | this.getBayeux().setJSONCommented(isJsonCommented()); |
111 | 0 | if(getLogLevel() != AbstractConnector.INT_VALUE_NOT_SET) this.getBayeux().setLogLevel(getLogLevel()); |
112 | 0 | if(getMaxInterval() != AbstractConnector.INT_VALUE_NOT_SET) this.getBayeux().setMaxInterval(getMaxInterval()); |
113 | 0 | if(getInterval() != AbstractConnector.INT_VALUE_NOT_SET) this.getBayeux().setInterval(getMaxInterval()); |
114 | 0 | if(getMultiFrameInterval() != AbstractConnector.INT_VALUE_NOT_SET) this.getBayeux().setMultiFrameInterval(getMultiFrameInterval()); |
115 | 0 | if(getTimeout() != AbstractConnector.INT_VALUE_NOT_SET) this.getBayeux().setTimeout(getMultiFrameInterval()); |
116 | |
|
117 | 0 | this.setInitialStateStopped(false); |
118 | |
|
119 | 0 | for (Object receiver : receivers.values()) |
120 | |
{ |
121 | 0 | ((AjaxMessageReceiver)receiver).setBayeux(getBayeux()); |
122 | |
} |
123 | 0 | start(); |
124 | 0 | } |
125 | |
|
126 | |
@Override |
127 | |
public String getProtocol() |
128 | |
{ |
129 | 0 | return PROTOCOL; |
130 | |
} |
131 | |
|
132 | |
public int getInterval() |
133 | |
{ |
134 | 0 | return interval; |
135 | |
} |
136 | |
|
137 | |
public void setInterval(int interval) |
138 | |
{ |
139 | 0 | this.interval = interval; |
140 | 0 | } |
141 | |
|
142 | |
public int getMaxInterval() |
143 | |
{ |
144 | 0 | return maxInterval; |
145 | |
} |
146 | |
|
147 | |
public void setMaxInterval(int maxInterval) |
148 | |
{ |
149 | 0 | this.maxInterval = maxInterval; |
150 | 0 | } |
151 | |
|
152 | |
public int getMultiFrameInterval() |
153 | |
{ |
154 | 0 | return multiFrameInterval; |
155 | |
} |
156 | |
|
157 | |
public void setMultiFrameInterval(int multiFrameInterval) |
158 | |
{ |
159 | 0 | this.multiFrameInterval = multiFrameInterval; |
160 | 0 | } |
161 | |
|
162 | |
public int getLogLevel() |
163 | |
{ |
164 | 0 | return logLevel; |
165 | |
} |
166 | |
|
167 | |
public void setLogLevel(int logLevel) |
168 | |
{ |
169 | 0 | this.logLevel = logLevel; |
170 | 0 | } |
171 | |
|
172 | |
public int getTimeout() |
173 | |
{ |
174 | 0 | return timeout; |
175 | |
} |
176 | |
|
177 | |
public void setTimeout(int timeout) |
178 | |
{ |
179 | 0 | this.timeout = timeout; |
180 | 0 | } |
181 | |
|
182 | |
public boolean isJsonCommented() |
183 | |
{ |
184 | 0 | return jsonCommented; |
185 | |
} |
186 | |
|
187 | |
public void setJsonCommented(boolean jsonCommented) |
188 | |
{ |
189 | 0 | this.jsonCommented = jsonCommented; |
190 | 0 | } |
191 | |
|
192 | |
public String getFilters() |
193 | |
{ |
194 | 0 | return filters; |
195 | |
} |
196 | |
|
197 | |
public void setFilters(String filters) |
198 | |
{ |
199 | 0 | this.filters = filters; |
200 | 0 | } |
201 | |
|
202 | |
public boolean isRequestAvailable() |
203 | |
{ |
204 | 0 | return requestAvailable; |
205 | |
} |
206 | |
|
207 | |
public void setRequestAvailable(boolean requestAvailable) |
208 | |
{ |
209 | 0 | this.requestAvailable = requestAvailable; |
210 | 0 | } |
211 | |
|
212 | |
public int getRefsThreshold() |
213 | |
{ |
214 | 0 | return refsThreshold; |
215 | |
} |
216 | |
|
217 | |
public void setRefsThreshold(int refsThreshold) |
218 | |
{ |
219 | 0 | this.refsThreshold = refsThreshold; |
220 | 0 | } |
221 | |
|
222 | |
@Override |
223 | |
public ReplyToHandler getReplyToHandler(ImmutableEndpoint endpoint) |
224 | |
{ |
225 | 0 | return new AjaxReplyToHandler(getDefaultResponseTransformers(endpoint), this); |
226 | |
} |
227 | |
|
228 | |
@Override |
229 | |
protected MessageReceiver createReceiver(FlowConstruct flowConstruct, InboundEndpoint endpoint) throws Exception |
230 | |
{ |
231 | 0 | AjaxMessageReceiver receiver = (AjaxMessageReceiver) super.createReceiver(flowConstruct, endpoint); |
232 | |
|
233 | 0 | receiver.setBayeux(getBayeux()); |
234 | 0 | return receiver; |
235 | |
} |
236 | |
} |