I have started to implement a blog pinging service in Java, using the Apache RPC Client libraries. However, I’m a little confused and I can’t seem to find a definitive specification for what a blog ping response should look like to check that it is successful.
I’ve looked at this, which appears to be an (official?) spec for a pingback.
http://www.hixie.ch/specs/pingback/pingback-1.0
However, this mentions that faultcodes will be returned, e.g.
http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
A number of RPC Servers such as Google Blog search, seem to return an ‘flerror’ and ‘message’ element in their XML response, which seems more akin to this:
http://xmlrpc.scripting.com/weblogsCom.html
Whats going on here? I realise pingback was something that the web kind of hacked together, and it became a standard – but I’m confused as to what to code against, or indeed trust in a response. Can I trust the below? and will it work for all blog ping servers?
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()) ;
}
The curt answer is no. Different server implementations will have bugs or misinterpret the spec, so you can’t write code that will work for all blog ping servers. The best you can do is to be liberal in what you accept, and try to deal with non standard/buggy servers as best you can.
The pingback spec says,
So a client expecting the server to comply to the spec would do something like,
If the server is following the pingback spec, it should return one of the following fault codes,
As you mentioned, several pingback servers return an error code, so you have to check for that as well with code like,