使用 Java 在 Bugzilla 中创建错误时出错

Error while creating bug in Bugzilla using Java

尝试在 bugzilla 中创建新错误时,出现错误 "You must log in before using this part of Bugzilla"

代码看起来像

`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://192.168.0.203/xmlrpc.cgi"));
    rpcClient.setConfig(config);

    // map of the login data
    Map<String, String> loginMap = new HashMap<String, String>();
    loginMap.put("login", "bugzilla.admin@abcd.com");
    loginMap.put("password", "bugzilla@admin");
    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<String, String> bugMap = new HashMap<String, String>();

    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);
 `

起初我能够登录,我得到的响应是:loginResult={id=1, token=1-AJ4uG13zlJ} 但是创建新bug时出现错误

`Exception in thread "main" org.apache.xmlrpc.XmlRpcException: You must log in before using this part of Bugzilla.
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:197)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:137)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:126)
at com.abcd.BugCreator2.main(BugCreator2.java:52)`

为什么我已经登录了,却再次出现这个登录错误。

编辑-:

上面的代码在 https://bugzilla.mozilla.org 上试用时工作正常 在本地服务器上配置 Bugzilla 时似乎存在一些问题。

首先要感谢你,我正在搜索和你一样的代码...

如果您仍然遇到该错误,您应该知道您还需要为创建方法发送登录名和密码参数。

就这样试试..

添加这个

bugMap.put("login", "bugzilla.admin@abcd.com");
bugMap.put("password", "bugzilla@admin");

在此之前

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");