- 追加された行はこの色です。
- 削除された行はこの色です。
// 下階層用テンプレート
#topicpath
----
//ここにコンテンツを記述します。
まずは単純なところから。Pingをうつクライアント[[PingClient:http://www.masatom.in/document/pingweb/javadoc/nu/mine/kino/servlets/ping/PingClient.html]]を作りました。
まずは単純なところから。Pingをうつクライアント[[PingClient:http://www.masatom.in/document/pingweb/javadoc/nu/mine/kino/ping/PingClient.html]]を作りました。
[[ソースコードはこちら:http://www.masatom.in/cgi-bin/viewcvs.cgi/PingWeb/source/nu/mine/kino/servlets/ping/PingClient.java]]
[[ソースコードはこちら:http://www.masatom.in/cgi-bin/viewvc.cgi/PingWeb/source/nu/mine/kino/ping/PingClient.java?root=cvs]]
このクラスは、フィールドにセットされたPingサーバたちにPingをうちます。
[[PingClient#doPing:http://www.masatom.in/document/pingweb/j2h/nu/mine/kino/servlets/ping/PingClient.java.html#46]]メソッドで、ブログ名やブログのURLを指定することができます。
[[PingClient#doPing:http://www.masatom.in/document/pingweb/j2h/nu/mine/kino/ping/PingClient.java.html#42]]メソッドで、ブログ名やブログのURLを指定することができます。
XML-RPC形式のPingリクエストの生成は、[[XML-RPCのページ>XML/XML-RPC]]にあるとおり[[Apache XML-RPC:http://ws.apache.org/xmlrpc/]]を用いています。
/*******************************************************************************
* Copyright (c) 2005 Masatomi KINO.
* All rights reserved.
* $Id: PingClient.java,v 1.5 2006/02/20 16:51:48 cvsuser Exp $
*******************************************************************************/
//作成日: 2005/10/29
package nu.mine.kino.servlets.ping;
/**
* PingサーバにweblogUpdates.pingを打つクライアントです。
*
* @author Masatomi KINO
* @version $Revision: 1.5 $
* @spring.bean id = "pingClient"
*/
public class PingClient {
private static final Logger logger = Logger.getLogger(PingClient.class);
private List endpointURLList = new ArrayList();
/**
* {@link PingClient#addEndpoint(String)} で指定された
* エンドポイントのPingサーバにPingを打ちます。
*
* @param weblogname Blogの名前
* @param weblogurl BlogのURL
*/
public void doPing(String weblogname, String weblogurl) {
logger.info("doPing(String, String) - start");
Iterator iterator = endpointURLList.iterator();
while (iterator.hasNext()) {
String destination = (String) iterator.next();
logger.info(destination + " : にPingを打ちます。");
logger.info("Weblog Name: " + weblogname);
logger.info("URL: " + weblogurl);
doPing(weblogname, weblogurl, destination); <-後述
}
logger.info("doPing(String, String) - end");
}
/**
* @param endpointURLList
* @spring.property list = "http://ping.cocolog-nifty.com/xmlrpc"
*/
public void setEndpointURLList(List endpointURLList) {
this.endpointURLList = endpointURLList;
}
}
実際にApache XML-RPCを使ったPingの処理は以下の通りになっています。
private void doPing(String weblogname, String weblogurl, String destination) {
logger.debug("doPing(String, String) - start");
// weblogUpdates.ping に渡すパラメタを順番通りVectorに入れる
Vector parameterList = new Vector();
parameterList.addElement(weblogname);
parameterList.addElement(weblogurl);
try {
XmlRpcClient client = null;
XmlRpc.setEncoding("UTF-8");
client = new XmlRpcClient(destination);
// さっきのエンドポイントの、weblogUpdates.ping と
// いうメソッドをコールする。パラメタはVectorに格納。
Hashtable response = (Hashtable) client.execute(
"weblogUpdates.ping", parameterList);
if (response != null) {
Enumeration e = response.keys();
while (e.hasMoreElements()) {
Object key = e.nextElement();
logger
.debug("KEY=" + key + " : VALUE="
+ response.get(key));
}
}
} catch (MalformedURLException e1) {
logger.error("doPing(String, String)", e1);
} catch (XmlRpcException e) {
logger.error("doPing(String, String)", e);
} catch (IOException e) {
logger.error("doPing(String, String)", e);
}
logger.debug("doPing(String, String) - end");
}
以上でPingをうつクライアントは完成です。これで試しにPingをうってみたところ以下のリクエストがPostされました。
<?xml version="1.0"?>
<methodCall>
<methodName>weblogUpdates.ping</methodName>
<params>
<param><value>[weblogname]</value></param>
<param><value>[weblogurl]</value></param>
</params>
</methodCall>
----
この記事は
#vote(おもしろかった[1],そうでもない[0])
#vote(おもしろかった[4],そうでもない[0])
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}