segunda-feira, 6 de setembro de 2010

Java x Bugzilla Webservice

Well, to create a bug using Java against Bugzilla Webservice:
Bem, para criar um Bug usando Java em face do Bugzilla Webservice:

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
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;

/**
*
* @author Cleórbete Santos
*/
public class BugCreator {
public static void main(String[] args){
HttpClient httpClient = new HttpClient();
XmlRpcClient rpcClient = new XmlRpcClient();
XmlRpcCommonsTransportFactory factory = new XmlRpcCommonsTransportFactory(rpcClient);
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
factory.setHttpClient(httpClient);
rpcClient.setTransportFactory(factory);
try {
config.setServerURL(new URL("http://server/bugzilla/xmlrpc.cgi"));
} catch (MalformedURLException ex) {
Logger.getLogger(BugCreate.class.getName()).log(Level.SEVERE, null, ex);
}
rpcClient.setConfig(config);

//User.login
Map map = new HashMap();
map.put("login", "arthurdent@galaxy.com");
map.put("password", "**********");
map.put("rememberlogin", "Bugzilla_remember");

Object result = null;
try {
result = rpcClient.execute("User.login", new Object[]{map});
} catch (XmlRpcException ex) {
Logger.getLogger(BugCreate.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println(result);

//Bug.create
Map map2 = new HashMap();
map2.put("product", "X-Files");
map2.put("component", "Component X");
map2.put("summary", "Bug creation test");
map2.put("version", "1.2");
map2.put("description", "Once a upon...");
map2.put("op_sys", "Linux");
map2.put("platform", "PC");
map2.put("priority", "Normal");
map2.put("severity", "major");
map2.put("status", "NEW");

result = null;
try {
result = rpcClient.execute("Bug.create", new Object[]{map2});
} catch (XmlRpcException ex) {
Logger.getLogger(BugCreate.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println(result);
}
}

Now I'm coding a BugList, to use in another app. After I'll post here.
Agora estou codando um listador de bugs, para usar em outra aplicação. Depois postarei aqui.

C ya.
Valeu.

Nenhum comentário:

Postar um comentário