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