comparison flys-aft/src/main/java/de/intevation/aft/Sync.java @ 4095:da9df3641578

Send XML messages via HTTP POST around if the FLYS database has changed. flys-aft/trunk@3614 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 06 Jan 2012 12:10:40 +0000
parents b20b710aa86f
children cdcf98245e36
comparison
equal deleted inserted replaced
4094:b20b710aa86f 4095:da9df3641578
1 package de.intevation.aft; 1 package de.intevation.aft;
2 2
3 import java.io.File; 3 import java.io.File;
4 4
5 import java.net.URL;
6 import java.net.MalformedURLException;
7
5 import java.sql.SQLException; 8 import java.sql.SQLException;
6 9
7 import org.w3c.dom.Document; 10 import org.w3c.dom.Document;
11 import org.w3c.dom.NodeList;
12 import org.w3c.dom.Element;
8 13
9 import org.apache.log4j.Logger; 14 import org.apache.log4j.Logger;
10 15
11 import javax.xml.xpath.XPathConstants; 16 import javax.xml.xpath.XPathConstants;
12 17
21 public static final String FLYS = "flys"; 26 public static final String FLYS = "flys";
22 public static final String AFT = "aft"; 27 public static final String AFT = "aft";
23 28
24 public static final String XPATH_DIPS = "/sync/dips/file/text()"; 29 public static final String XPATH_DIPS = "/sync/dips/file/text()";
25 public static final String XPATH_REPAIR = "/sync/dips/repair/text()"; 30 public static final String XPATH_REPAIR = "/sync/dips/repair/text()";
31
26 public static final String XPATH_NOTIFICATIONS = 32 public static final String XPATH_NOTIFICATIONS =
27 "/sync/notifications/notification"; 33 "/sync/notifications/notification";
28 34
29 public static final String CONFIG_FILE = 35 public static final String CONFIG_FILE =
30 System.getProperty("config.file", "config.xml"); 36 System.getProperty("config.file", "config.xml");
37
38 public static void sendNotifications(Document config) {
39 NodeList notifications = (NodeList)XML.xpath(
40 config, XPATH_NOTIFICATIONS, XPathConstants.NODESET, null, null);
41
42 if (notifications == null) {
43 return;
44 }
45
46 for (int i = 0, N = notifications.getLength(); i < N; ++i) {
47 Element notification = (Element)notifications.item(i);
48 String urlString = notification.getAttribute("url");
49
50 URL url;
51 try {
52 url = new URL(urlString);
53 }
54 catch (MalformedURLException mfue) {
55 log.warn("Invalid URL '" + urlString + "'. Ignored.", mfue);
56 continue;
57 }
58
59 Notification n = new Notification(notification);
60
61 Document result = n.sendPOST(url);
62
63 if (result != null) {
64 log.info("Send notifcation to '" + urlString + "'.");
65 log.info(XML.toString(result));
66 }
67 }
68 }
31 69
32 public static void main(String [] args) { 70 public static void main(String [] args) {
33 71
34 File configFile = new File(CONFIG_FILE); 72 File configFile = new File(CONFIG_FILE);
35 73
114 if (syncContext != null) { 152 if (syncContext != null) {
115 syncContext.close(); 153 syncContext.close();
116 } 154 }
117 } 155 }
118 156
157 if (modified) {
158 sendNotifications(config);
159 }
160
119 if (exitCode != 0) { 161 if (exitCode != 0) {
120 System.exit(1); 162 System.exit(1);
121 } 163 }
122 } 164 }
123 } 165 }

http://dive4elements.wald.intevation.org