4

Apache RPC クライアント ライブラリを使用して、Java でブログ ping サービスの実装を開始しました。しかし、私は少し混乱しており、ブログの ping 応答が成功したかどうかを確認するための明確な仕様を見つけることができないようです。

これは、pingback の (公式の?) 仕様のようです。
http://www.hixie.ch/specs/pingback/pingback-1.0

ただし、これはフォルトコードが返されることに言及しています。

http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php

Google ブログ検索などの多くの RPC サーバーは、XML 応答で 'flerror' および 'message' 要素を返すようです。これは、次のように思われます。

http://xmlrpc.scripting.com/weblogsCom.html

何が起きてる?私はpingbackがウェブの一種のハッキングであり、それが標準になったことを理解しています-しかし、何に対してコーディングするか、または実際に応答を信頼するかについて混乱しています. 以下は信頼できますか?また、すべてのブログの ping サーバーで機能しますか?

public  boolean ping( String urlToPing, String title, String url, String urlChanges, String urlRSS ) throws MalformedURLException, XmlRpcException
{
    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    config.setServerURL( new URL( urlToPing ) );

    XmlRpcClient client = new XmlRpcClient();
    client.setConfig( config );

    Object[] params = new Object[] { title, url, urlChanges, urlRSS };
    HashMap result = ( HashMap )client.execute( "weblogUpdates.extendedPing", params );

    try
    {
        errors.put( url, Boolean.parseBoolean( result.get( "flerror" ).toString() ) );
    }
    catch( Exception e )
    {
        log.error( "RPC Problem Parsing response to Boolean trying: " + result.get( "flerror" ) );
    }

    return Boolean.parseBoolean( result.get( "flerror").toString()) ;
}
4

1 に答える 1

2

以下は信頼できますか?また、すべてのブログの ping サーバーで機能しますか?

率直な答えはノーです。さまざまなサーバーの実装にはバグがあったり、仕様を誤って解釈したりすることがあるため、すべてのブログ ping サーバーで機能するコードを書くことはできません。あなたができる最善のことは、受け入れるものに寛容になり、非標準/バグのあるサーバーにできる限り対処することです.

ピンバック仕様によると、

pingback 要求が成功した場合、戻り値は、サーバーが有用と見なす限りの情報を含む単一の文字列でなければなりません。この文字列は、デバッグ目的でのみ使用されることが想定されています。

結果が失敗した場合、サーバーは RPC フォールト値で応答する必要があります。障害コードは、上記のコードのいずれか、またはサーバーが正しい障害コードを判別できない場合の一般的な障害コード ゼロのいずれかである必要があります。

したがって、サーバーが仕様に準拠することを期待するクライアントは、次のようなことを行います。

try {
     client.execute( "weblogUpdates.extendedPing", params );
} catch(XmlRpcException e) {
    //check the code of the rpc exception as shown below,
    //log the error, or perhaps rethrow it?
    return false;
} 

サーバーが pingback 仕様に従っている場合、次の障害コードのいずれかを返す必要があります。

0
A generic fault code. Servers MAY use this error code instead of any of the others if they do not have a way of determining the correct fault code.
0×0010 (16)
The source URI does not exist.
0×0011 (17)
The source URI does not contain a link to the target URI, and so cannot be used as a source.
0×0020 (32)
The specified target URI does not exist. This MUST only be used when the target definitely does not exist, rather than when the target may exist but is not recognised. See the next error.
0×0021 (33)
The specified target URI cannot be used as a target. It either doesn't exist, or it is not a pingback-enabled resource. For example, on a blog, typically only permalinks are pingback-enabled, and trying to pingback the home page, or a set of posts, will fail with this error.
0×0030 (48)
The pingback has already been registered.
0×0031 (49)
Access denied.
0×0032 (50)

あなたが言及したように、いくつかのpingbackサーバーはエラーコードを返すので、次のようなコードでそれを確認する必要があります.

try {
    Object rpcRVal = client.execute( "weblogUpdates.extendedPing", params );
    if(rpcRVal instanceof Map) {
        Object flError = ((Map) rpcRVal ).get("flerror");
        if(flError != null && flError instanceof Boolean) {
            return ((Boolean) flError).booleanValue());        
        }
    }
    return true;
} catch(XmlRpcException e) ...
于 2012-07-22T04:02:21.340 に答える