1 9 10 package org.roller.presentation.pings; 11 12 import org.apache.commons.logging.Log; 13 import org.apache.commons.logging.LogFactory; 14 import org.apache.xmlrpc.XmlRpcClient; 15 import org.apache.xmlrpc.XmlRpcException; 16 import org.roller.RollerException; 17 import org.roller.model.RollerFactory; 18 import org.roller.pojos.PingTargetData; 19 import org.roller.pojos.WebsiteData; 20 21 import java.io.IOException ; 22 import java.net.MalformedURLException ; 23 import java.net.UnknownHostException ; 24 import java.util.Hashtable ; 25 import java.util.Vector ; 26 27 33 public class WeblogUpdatePinger 34 { 35 public static final Log logger = LogFactory.getLog(WeblogUpdatePinger.class); 36 37 40 public static class PingResult 41 { 42 boolean error; 43 String message; 44 45 public PingResult(Boolean error, String message) 46 { 47 this.error = error != null ? error.booleanValue() : false; 48 this.message = message; 49 } 50 51 public boolean isError() 52 { 53 return error; 54 } 55 56 public void setError(boolean error) 57 { 58 this.error = error; 59 } 60 61 public String getMessage() 62 { 63 return message; 64 } 65 66 public void setMessage(String message) 67 { 68 this.message = message; 69 } 70 71 public String toString() 72 { 73 return "PingResult{" + 74 "error=" + error + 75 ", message='" + message + "'" + 76 "}"; 77 } 78 } 79 80 private WeblogUpdatePinger() 82 { 83 } 84 85 96 public static PingResult sendPing(String absoluteContextUrl, PingTargetData pingTarget, WebsiteData website) 97 throws RollerException, IOException , XmlRpcException 98 { 99 String websiteUrl = 101 RollerFactory.getRoller().getWeblogManager().getUrl(website.getUser(), absoluteContextUrl); 102 103 Vector params = new Vector (); 105 params.addElement(website.getName()); 106 params.addElement(websiteUrl); 107 if (logger.isDebugEnabled()) 108 { 109 logger.debug("Executing ping to '" + pingTarget.getPingUrl() + "' for website '" + 110 websiteUrl + "' (" + website.getName() + ")"); 111 } 112 113 XmlRpcClient client = new XmlRpcClient(pingTarget.getPingUrl()); 115 Hashtable result = (Hashtable ) client.execute("weblogUpdates.ping", params); 116 PingResult pingResult = new PingResult((Boolean ) result.get("flerror"), (String ) result.get("message")); 117 if (logger.isDebugEnabled()) logger.debug("Ping result is: " + pingResult); 118 return pingResult; 119 } 120 121 127 public static boolean shouldRetry(Exception ex) 128 { 129 if (ex instanceof UnknownHostException ) 133 { 134 return false; 136 } 137 else if (ex instanceof MalformedURLException ) 138 { 139 return false; 141 } 142 return true; 143 } 144 145 } 146 | Popular Tags |