mfqms.setDirectories(paths);
//make sure all the directories are rescanned each poll
mfqms.setScanEachPoll(false);
mfqms.afterPropertiesSet();
SourcePollingChannelAdapter spca = new SourcePollingChannelAdapter();
spca.setBeanName(platformType + "StatusFileSource");
spca.setBeanFactory(context.getBeanFactory());
spca.setMaxMessagesPerPoll(1);
DynamicTrigger trigger;
if (props.containsKey(platformType + ".scanRate")) {
trigger = new DynamicTrigger(Integer.parseInt(props.getProperty(platformType + ".scanRate")), TimeUnit.MILLISECONDS);
}
else {
trigger = new DynamicTrigger(600000, TimeUnit.MILLISECONDS);
}
trigger.setFixedRate(false);
spca.setTrigger(trigger);
spca.setSource(mfqms);
spca.setOutputChannel(channelResolver.resolveChannelName(platformType + "StatusFileInputChannel"));
spca.setAutoStartup(false);
spca.afterPropertiesSet();
DirectChannel outputChannel = (DirectChannel) channelResolver.resolveChannelName(platformType + "StatusChannel");
outputChannel.setBeanName(platformType + "StatusChannel");
outputChannel.setBeanFactory(context.getBeanFactory());
if (props.containsKey("wiretap.enabled") && "true".equals(props.get("wiretap.enabled"))) {
//set up wire tap
DirectChannel wireTapChannel = (DirectChannel) channelResolver.resolveChannelName("wireTapChannel");
wireTapChannel.setBeanName("wireTapChannel");
wireTapChannel.setBeanFactory(context.getBeanFactory());
LoggingHandler wireTapLogger = new LoggingHandler("TRACE");
wireTapLogger.setBeanName("OutputWireTapper");
wireTapLogger.setBeanFactory(context.getBeanFactory());
wireTapLogger.setLoggerName("wiretap");
wireTapLogger.setShouldLogFullMessage(true);
wireTapLogger.afterPropertiesSet();
wireTapChannel.subscribe(wireTapLogger);
List<ChannelInterceptor> ints = new ArrayList<ChannelInterceptor>();
WireTap wt = new WireTap(wireTapChannel);
ints.add(wt);
outputChannel.setInterceptors(ints);
}
DirectChannel signChannel = (DirectChannel)channelResolver.resolveChannelName(platformType+"MessageSignerChannel");
signChannel.setBeanFactory(context.getBeanFactory());
DirectChannel splitterChannel = (DirectChannel)channelResolver.resolveChannelName(platformType+"SplitterChannel");
splitterChannel.setBeanFactory(context.getBeanFactory());
if (props.containsKey(platformType + ".http.statusEndpointURIs")) {
log.debug("Resolving " + platformType + ".http.statusEndpointURIs ...");
String statusEndpointURIs = props.getProperty(platformType + ".http.statusEndpointURIs");
for (String uri : statusEndpointURIs.split(",")) {
//split into multiple messages
MethodInvokingSplitter mis = new MethodInvokingSplitter(notificationUtils, "splitMessage");
mis.setBeanName(platformType + "Splitter");
mis.setBeanFactory(context.getBeanFactory());
mis.setChannelResolver(channelResolver);
mis.setOutputChannel(signChannel);
splitterChannel.subscribe(mis);
//sign messages and inject url into message headers via HeaderEnricher
Map<String, SignedHeaderValueMessageProcessor<String>> urlHeaderToSign = new HashMap<String, SignedHeaderValueMessageProcessor<String>>();
URI su = URI.create(uri);
urlHeaderToSign.put("x-url", new SignedHeaderValueMessageProcessor<String>(su.getPath()));
urlHeaderToSign.put("x-user", new SignedHeaderValueMessageProcessor<String>("notification"));
NotificationMessageEnricher signer = new NotificationMessageEnricher(urlHeaderToSign);
signer.setMessageProcessor(new MethodInvokingMessageProcessor(notificationUtils, "signMessageHeaders"));
MessageTransformingHandler mth = new MessageTransformingHandler(signer);
mth.setBeanName(platformType + "Signer");
mth.setBeanFactory(context.getBeanFactory());
mth.setChannelResolver(channelResolver);
mth.setOutputChannel(outputChannel);
mth.setRequiresReply(false);
signChannel.subscribe(mth);
DefaultHttpHeaderMapper hm = new DefaultHttpHeaderMapper();
hm.setUserDefinedHeaderPrefix("");
String[] names = {"Accept", "x-url", "x-signature", "x-user"};
hm.setBeanFactory(context.getBeanFactory());
hm.setOutboundHeaderNames(names);
hm.setInboundHeaderNames(names);
HttpRequestExecutingMessageHandler statusNotifier = new HttpRequestExecutingMessageHandler(uri);
statusNotifier.setBeanName(platformType + "StatusNotifier");
statusNotifier.setBeanFactory(context.getBeanFactory());
statusNotifier.setChannelResolver(channelResolver);
statusNotifier.setHttpMethod(HttpMethod.POST);
statusNotifier.setCharset("UTF-8");
statusNotifier.setHeaderMapper(hm);
statusNotifier.setExtractPayload(true);
statusNotifier.setOrder(3);
statusNotifier.setRequiresReply(false);
statusNotifier.setExpectReply(false);
outputChannel.subscribe(statusNotifier);
}
}
if (props.containsKey(platformType + ".tcp.host") && props.containsKey(platformType + ".tcp.port")) {
String host = props.getProperty(platformType + ".tcp.host");
int port = Integer.parseInt(props.getProperty(platformType + ".tcp.port"));
TcpNetClientConnectionFactory tnccf = new TcpNetClientConnectionFactory(host, port);
tnccf.setSoTimeout(10000);
tnccf.setSingleUse(true);
TcpOutboundGateway tog = new TcpOutboundGateway();
tog.setBeanName(platformType + "StatusNotifier");
tog.setBeanFactory(context.getBeanFactory());
tog.setChannelResolver(channelResolver);
tog.setConnectionFactory(tnccf);
tog.setRequestTimeout(10000);
tog.setRequiresReply(false);
tog.setOutputChannel(outputChannel);
outputChannel.subscribe(tog);
}
if ((!props.containsKey(platformType + ".tcp.host") || !props.containsKey(platformType + ".tcp.port")) && !props.containsKey(platformType + ".http.statusEndpointURIs")) {
log.error("You have specified a list of paths to scan, but no valid endpoint to notify. Please add a <platform>.http.statusEndpointURIs property and/or <platform>.tcp.host/port properties in notification.properties");
}
else {
spca.start();
}
}
else {
log.warn("You have not specified a list of " + platformType + " paths to scan. Please add a " + platformType.toLowerCase() + ".dataPaths property in notification.properties if you wish to track this platform");
}