Changeset 8645
- Timestamp:
- 2004-11-24T10:11:00+13:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/notifier/NotifierManager.java
r8633 r8645 6 6 import java.net.*; 7 7 import java.sql.*; 8 import java.util.Calendar; 8 import java.text.SimpleDateFormat; 9 import java.util.*; 9 10 import java.util.Date; 10 import java.text.DateFormat; 11 import java.text.SimpleDateFormat; 11 import java.util.TreeMap; 12 12 13 import org.apache.soap.Constants; 14 import org.apache.soap.SOAPException; 15 import org.apache.soap.rpc.*; 16 import org.apache.soap.rpc.Call; 17 import org.apache.soap.rpc.Parameter; 13 18 import org.greenstone.gsdl3.gs3build.CollectionManager; 14 19 import org.greenstone.gsdl3.gs3build.util.GS3SQLConnection; … … 30 35 // AccessionDate >= CollectionLastRebuiltDate 31 36 ResultSet results = statement.executeQuery("SELECT DocID FROM document WHERE DocType != 'GSMETADATA' AND AccessionDate >= " + lastBuild); 32 notify(collectionName, host, results, collManager.getDatabase() );37 notify(collectionName, host, results, collManager.getDatabase(), "new_document"); 33 38 34 39 // detect modified documents. A document is modified if and only if … … 36 41 // ModifiedDate >= IndexedDate 37 42 results = statement.executeQuery("SELECT DocID FROM document WHERE DocType != 'GSMETADATA' AND AccessionDate < " + lastBuild + " AND ModifiedDate >= IndexedDate"); 38 notify(collectionName, host, results, collManager.getDatabase() );43 notify(collectionName, host, results, collManager.getDatabase(), "document_modified"); 39 44 } catch (SQLException e) { 40 45 // TODO Auto-generated catch block … … 47 52 * @param hostURL 48 53 * @param results 54 * @param eventType TODO 49 55 * @throws MalformedURLException 50 56 * @throws IOException … … 52 58 * @throws SQLException 53 59 */ 54 private void notify(String collName, String hostURL, ResultSet results, GS3SQLConnection database ) {60 private void notify(String collName, String hostURL, ResultSet results, GS3SQLConnection database, String eventType) { 55 61 try { 56 URL url = new URL("http://localhost:8080/alerting/service?receive"); 57 System.out.println("trying to POST to " + url); 58 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 59 conn.setDoOutput(true); 60 conn.setRequestMethod("POST"); 61 conn.setUseCaches(false); 62 URL url = new URL(hostURL); 63 System.out.println("trying to send (via SOAP) to " + url); 64 62 65 while(results.next()) { 63 66 System.out.println("new document: " + results.getString("DocID")); 67 Map event = new TreeMap(); 68 69 String documentID = results.getString("DocID"); 70 71 event.put("documentID", documentID); 72 event.put("type", eventType); 73 event.put("collectionID", collName); 74 event.put("host_url", hostURL); 75 event.put("document_title", getDocumentTitle(documentID, database)); 76 77 Call call = new Call(); 78 call.setTargetObjectURI("alerting"); 79 call.setMethodName("receiveEvent"); 80 call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); 81 Vector params = new Vector(); 82 params.addElement(new Parameter("event", Map.class, event, null)); 83 call.setParams(params); 64 84 try { 65 conn.connect(); 66 OutputStream toReceiver = conn.getOutputStream(); 67 OutputStreamWriter writeToReceiver = new OutputStreamWriter(toReceiver); 68 69 // TODO HTTP Post -> SOAP 70 String documentID = results.getString("DocID"); 71 72 writeToReceiver.write("type=new_document&"); 73 writeToReceiver.write("collectionID=" + collName + "&"); 74 writeToReceiver.write("host_url=" + hostURL + "&"); 75 writeToReceiver.write("document_title=" + getDocumentTitle(documentID, database) + "&"); 76 writeToReceiver.write("documentID=" + documentID + "\n"); 77 writeToReceiver.close(); 78 79 System.out.println(conn.getResponseCode()); 80 InputStream fromReceiver = conn.getInputStream(); 81 int i; 82 while ((i = fromReceiver.read()) != -1) System.out.write(i); 83 conn.disconnect(); 84 } catch (IOException e1) { 85 // TODO Auto-generated catch block 86 System.out.println("Error talking to server."); 87 e1.printStackTrace(); 88 } 85 Response resp = call.invoke(url, ""); 86 if (!resp.generatedFault()) { 87 System.out.println("successfully posted event"); 88 return; 89 } 90 System.err.println("Posting event was unsuccessful:"); 91 System.err.println(resp.getFault().getFaultString()); 92 } catch (SOAPException e1) { 93 System.err.println("Exception while posting event: "); 94 e1.printStackTrace(); 95 } 89 96 } 90 97 } catch (IOException e) {
Note:
See TracChangeset
for help on using the changeset viewer.