1 37 38 package org.jahia.blogs; 39 40 import org.apache.xmlrpc.XmlRpcClient; 41 import org.apache.xmlrpc.XmlRpcException; 42 43 import java.io.IOException ; 44 45 import java.util.Vector ; 46 47 import org.apache.commons.httpclient.HttpClient; 48 import org.apache.commons.httpclient.methods.PostMethod; 49 50 import org.apache.log4j.Logger; 51 52 57 public class BlogTester { 58 59 public static final String SERVER = "http://localhost:8080/jahia/blogs"; 60 public static final String TB_PING_SERVLET = 61 "http://localhost:8080/jahia/trackbacks"; 62 63 static Logger log = Logger.getLogger(BlogTester.class); 64 65 66 public BlogTester() { 67 } 68 69 72 private static Object execute(XmlRpcClient xmlrpc, String methodName, 73 Vector params) throws XmlRpcException, IOException { 74 return xmlrpc.execute(methodName, params); 75 } 76 77 80 private static Vector toVector(String [] params) { 81 Vector result = new Vector (params.length); 82 83 for (int i=0; i<params.length; i++) { 84 result.addElement(params[i]); 85 } 86 return result; 87 } 88 89 92 private static String sendPing(String postID) throws IOException { 93 HttpClient client = new HttpClient(); 94 PostMethod post = new PostMethod(TB_PING_SERVLET); 95 96 post.setRequestHeader("Content-type", 97 "application/x-www-form-urlencoded; charset=utf-8"); 98 99 post.addParameter("entryID", postID); 100 post.addParameter("url", "http://test.com/12"); 101 post.addParameter("title", "Le titre"); 102 post.addParameter("excerpt", "Un court résumé"); 103 post.addParameter("blog_name", "Le nom du blog"); 104 105 int status = client.executeMethod(post); 106 String body = post.getResponseBodyAsString(); 107 108 StringBuffer buff = new StringBuffer (); 109 buff.append("StatusCode: "); 110 buff.append(status); 111 buff.append("; "); 112 buff.append(body); 113 114 return buff.toString(); 115 } 116 117 120 public static void main(String [] args) throws Exception { 121 122 String postID = "27"; 123 124 if (args == null || args.length == 0) { 125 log.info("Need to specify a postID to ping as argument"); 126 log.info("Using postID "+postID); 127 } else { 128 postID = args[0]; 129 } 130 131 XmlRpcClient xmlrpc = new XmlRpcClient(SERVER); 132 133 String [] params = {postID}; 134 String name = "mt.getTrackbackPings"; 135 136 log.info("Sending ping..."); 137 String result = sendPing(postID); 138 log.info("Result of ping: "+result); 139 140 log.info("Executing "+name); 141 result = execute(xmlrpc, name, toVector(params)).toString(); 142 log.info("Result of "+name+": "+result); 143 } 144 } 145 | Popular Tags |