Pergunta

Here is a code to create a new bug in Bugzilla using Java. But I am getting following error.

BugCreator2.java:20: error: cannot find symbol factory.setHttpClient(httpClient); ^ symbol: method setHttpClient(HttpClient) location: variable factory of type XmlRpcCommonsTransportFactor Note: BugCreator2.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error

Following Jar Files I have used: commons-httpclient-3.0.1 java-rt-jar-stubs-1.5.0 ws-commons-util-1.0.1 ws-commons-util-1.0.1-sources xmlrpc-3.0 xmlrpc-3.0-common

I don't knnow if all of them are required.

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 BugCreator2 {
   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://URL/bugzilla/xmlrpc.cgi"));
    rpcClient.setConfig(config);

    // map of the login data
    Map loginMap = new HashMap();
    loginMap.put("login", "username@abc.com");
    loginMap.put("password", "*********");
    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", "Demo");
    bugMap.put("component", "Demo_project");
    bugMap.put("summary", "Bug created for test");
    bugMap.put("description", "This is text ");
    bugMap.put("version", "unspecified");
    bugMap.put("op_sys", "Windows");
    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);
 }

}

Foi útil?

Solução

After much efforts i came to know there is problem with versions of JARs. You need to use exact JARS as come other versions are not supporting some methods. Jars Used:

  • commons-httpclient-3.0.1
  • commons-logging-1.1.3
  • java-rt-jar-stubs-1.5.0
  • org.apache.commons.codec_1.3.0.v201101211617
  • ws-commons-util-1.0.2
  • xmlrpc-client-3.1.3
  • xmlrpc-common-3.1.3
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top