在尝试在bugzilla中创建一个新bug时,我收到了一个错误 “你必须在使用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} 但是在创建新错误时会发生错误
`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时似乎存在一些问题。
答案 0 :(得分:0)
首先感谢你,我正在搜索与你一样的代码......
如果您仍然遇到该错误,您应该知道您还需要为create方法发送登录名和密码参数。
试试这个..
添加此
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");