Monday, August 30, 2010

Java sample client for Bugzilla webservice API

I recently had to use bugzilla's webservice API in a Java based project. And I was surprised to see that there was almost no sample code available for using bugzilla's webservice API especially for Java. So in the end I used the XmlRpcClient provided by Apache. Here's the sample code...

private XmlRpcClient getClient(String serverURL) {
    try {
        String apiURL = serverURL + "xmlrpc.cgi";
        XmlRpcClient rpcClient;
        XmlRpcClientConfigImpl config;
        config = new XmlRpcClientConfigImpl();
        config.setServerURL(new URL(apiURL));
        rpcClient = new XmlRpcClient();
        return rpcClient;
    } catch (MalformedURLException e) {
    return null;
public HashMap login(String serverURL, String login, String password) {
    try {
        XmlRpcClient rpcClient = getClient(serverURL);
        ArrayList<Object> params = new ArrayList<Object>();
        Hashtable<String, Object> executionData = new Hashtable<String, Object>();
        executionData.put("login", login);
        executionData.put("password", password);
        executionData.put("remember", true);
        HashMap result = (HashMap) rpcClient.execute("User.login", params);
        return result;
    } catch (XmlRpcException e) {
    return null;

Here are the maven dependencies required by this code…


Or if you don’t use maven you can just download these libraries form Apache’s website…

  1. xmlrpc-client

  2. xmlrpc-common

  3. ws-commons-util
The complete documentation for Bugzilla API is available here...


  1. Hey thanks for the code! This is REALLY helpful! I can't make it work, I'm having the following exception:

    org.apache.xmlrpc.client.XmlRpcHttpTransportException: HTTP server returned unexpected status: Not Found
    at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.getInputStream(
    at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(
    at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(
    at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(
    at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(
    at org.apache.xmlrpc.client.XmlRpcClient.execute(
    at org.apache.xmlrpc.client.XmlRpcClient.execute(
    at org.apache.xmlrpc.client.XmlRpcClient.execute(
    at com.bugzillaClient.controller.BugzillaController.login(
    at com.bugzillaClient.controller.BugzillaController.runYSEProcessXls(
    at com.bugzillaClient.runner.Launcher.main(

  2. Hi
    It looks like a problem with your bugzilla configuration. My guess is that you need to enable the webservice API or perhaps the API module is missing in your installation.

  3. Hi,
    I am getting one exception when using Bug.create API.

    java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
    at org.apache.xmlrpc.parser.XmlRpcResponseParser.addResult(
    at org.apache.xmlrpc.parser.RecursiveTypeParserImpl.endValueTag(
    at org.apache.xmlrpc.parser.XmlRpcResponseParser.endElement(

    Any Idea?


  4. Try Integer.parseInt(string)
    BTW this is not a problem with bugzilla..

  5. I am sorry.get method is working fine.some prob with array initialization.


  6. some rare piece of info it is. gr8 work ...

  7. hi..
    can u tell me how to start for it ...from the initial...

  8. Hi,I am trying to develop java code for reporting bugs in bugzilla and i am using bugzilla rest api. Can any one provide me sample code and necessary environment to run the code.Thanks in advance.

  9. Q:: I am trying to develop code in java which automatically reports bugs in

    Bugzilla using j2BugZilla API. My Bugzilla Version is 2.16.4 and j2BugZilla

    Version is 2.2. I am able to connect to BugZilla but after that i am not

    able to login into bugzilla. Code is :

    public class CreateBugInBugZilla {
    public BugzillaConnector connector;
    private String bugzillaurl="";

    public void connect() throws ConnectionException, BugzillaException {
    BugZillaConnector connector;
    connector = new BugzillaConnector();

    LogIn login=new LogIn(bugzillaUsername,bugzillaPassword);

    System.out.println("logged in");
    GetLegalValues get=new GetLegalValues(GetLegalValues.Fields.COMPONENT);
    Set values=get.getLegalValues();
    BugSearch search = new BugSearch(new BugSearch.SearchQuery

    List searchResults=search.getSearchResults();
    for(Bug bug:searchResults)

    public static void main(String[]args) throws ConnectionException,

    BugzillaException {

    CreateBugInBugZilla createBugInBugZilla=new CreateBugInBugZilla();


    Exception StackTrace is:---------------------------------------------

    Exception in thread "main" com.j2bugzilla.base.BugzillaException: An unknown

    error was encountered; fault code: 0
    at com.j2bugzilla.base.XmlExceptionHandler.handleFault

    at com.j2bugzilla.base.BugzillaConnector.executeMethod

    at CreateBugInBugZilla.connect(
    at CreateBugInBugZilla.main(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke

    at sun.reflect.DelegatingMethodAccessorImpl.invoke

    at java.lang.reflect.Method.invoke(
    at com.intellij.rt.execution.application.AppMain.main(
    Caused by: org.apache.xmlrpc.client.XmlRpcHttpTransportException: HTTP

    server returned unexpected status: Service Unavailable
    at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.getInputStream

    at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest

    at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest

    at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest

    at org.apache.xmlrpc.client.XmlRpcClientWorker.execute

    at org.apache.xmlrpc.client.XmlRpcClient.execute(
    at org.apache.xmlrpc.client.XmlRpcClient.execute(
    at org.apache.xmlrpc.client.XmlRpcClient.execute(
    at com.j2bugzilla.base.BugzillaConnector.executeMethod

    ... 7 more