Our project uses Bugzilla for tracking issues. I was looking for solution how to submit occured exception programatically. I found quite simple solution using Groovy and I have adapted it to pure Java.
Here is the source code:
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.httpclient.HttpClient;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
public class Main {
public static void main(String s[])
throws MalformedURLException, XmlRpcException {
HttpClient httpClient = new HttpClient();
XmlRpcClient rpcClient = new XmlRpcClient();
XmlRpcCommonsTransportFactory factory = new XmlRpcCommonsTransportFactory(rpcClient);
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
factory.setHttpClient(httpClient);
rpcClient.setTransportFactory(factory);
config.setServerURL(new URL("http://bugzilla.example.com/xmlrpc.cgi"));
rpcClient.setConfig(config);
// map of the login data
Map loginMap = new HashMap();
loginMap.put("login", "tomas.hubalek@....");
loginMap.put("password", "*top*secret*");
loginMap.put("rememberlogin", "Bugzilla_remember");
// login to bugzilla
Object loginResult = rpcClient.execute("User.login", new Object[]{loginMap});
System.err.println ("loginResult=" + loginResult);
// map of the bug data
Map bugMap = new HashMap();
bugMap.put("product", "Playground");
bugMap.put("component", "Database");
bugMap.put("summary", "Bug created from groovy script");
bugMap.put("description", "This is text including stacktrace");
bugMap.put("version", "unspecified");
bugMap.put("op_sys", "Linux");
bugMap.put("platform", "PC");
bugMap.put("priority", "P2");
bugMap.put("severity", "Normal");
bugMap.put("status", "NEW");
// create bug
Object createResult = rpcClient.execute("Bug.create", new Object[]{bugMap});
System.err.println("createResult = " + createResult);
}
}
Usage of Apache XML RPC Client is quite straightforward, only gotcha is that mapped parameters must be set passed as new Object[]{bugMap}. Otherwise you get ClassCastException.