if (StringUtils.empty(userId) || StringUtils.empty(channelId)) {
response.sendError(404);
return;
}
IPullChannel channel = getChannel(channelId);
if (channel == null) {
response.sendError(404);
return;
}
IChannelPreferences prefs = channel.newDefaultPreferences();
if (prefs instanceof IRequestConfigurable) {
try {
Map<?, ?> queryParams = request.getParameterMap();
for (Map.Entry<?, ?> e : queryParams.entrySet()) {
Object value = e.getValue();
if (value != null && value.getClass().isArray()) {
String[] vals = (String[]) value;
value = vals.length > 0 ? vals[0] : null;
}
((IRequestConfigurable) prefs).setParam((String) e.getKey(), (String) value);
}
} catch (NotifyException e) {
response.sendError(404);
return;
}
}
if (channel.getNotificationTypes().contains(Type.PRIVATE) && !channel.isAuthorized(userId, prefs)) {
response.sendError(403);
} else if (channel.isConfigured(new Params(prefs.getParams()))) {
try {
String output = channel.pull(userId, prefs);
if (StringUtils.empty(output)) {
response.sendError(404);
} else {
response.getWriter().write(output);
}