2009-03-10 8 views

Respuesta

9

Sé que esto es un hilo poco viejo, pero ya que es muy posible que las personas con la misma pregunta podría aterrizar hasta aquí pensé en compartir un post que escribí sobre cuatro Java bibliotecas cliente que encontré para acceder a Bugzilla: J2Bugzilla, B4J (Bugzilla para Java), Biblioteca Bugzilla, LightingBugAPI.

http://www.dzone.com/links/r/bugzilla_web_service_and_java_client_libraries.html

Best Regards, Nandana

+0

esto es una gran visión de conjunto, sólo es lamentable que la mayoría de las bibliotecas son tan incompletos. – Mauli

2

La biblioteca/API se llama JAX-WS (o JAXB), y le permite llamar de WS cualquier naturaleza Obtenga el esquema, genere los beans y los proxies, llámelos.

5

Hay Apache WS XML-RPC(ahora eso es un bocado) que es una implementación completa de XML-RPC que puede usar. No conozco muy bien a BugZilla, pero suponiendo que sea compatible con XML-RPC, no debería haber ningún problema con el monstruoso bocado que acabo de vincular.

1

También está Mylyn, que se supone que se ejecuta de forma independiente fuera de Eclipse. Sin embargo, no logré tenerlo de manera independiente. Puede darle una oportunidad a mi propia API Bugzilla Java, que trata de cubrir las necesidades más urgentes: http://techblog.ralph-schuster.eu/b4j-bugzilla-for-java/

1

Mylyn podría ser una buena opción para tú.

Si necesita una configuración más simple o un mejor control de cómo ocurren las cosas, puede escribir sus propias llamadas XML-RPC a la interfaz del servicio web Bugzilla. He resumido el proceso en mi blog: Chat to Bugzilla from Java using Apache XML-RPC.

Para resumir:

  • obtener las librerías Apache XML-RPC
  • conseguir que el cliente HTTP Apache de bienes comunes (versión anterior)

A continuación, utilice siguiente clase como una clase base (maneja las cookies, etc.) y anularlo:

/** 
* @author joshis_tweets 
*/ 
public class BugzillaAbstractRPCCall { 

    private static XmlRpcClient client = null; 

    // Very simple cookie storage 
    private final static LinkedHashMap<String, String> cookies = new LinkedHashMap<String, String>(); 

    private HashMap<String, Object> parameters = new HashMap<String, Object>(); 
    private String command; 

    // path to Bugzilla XML-RPC interface 
    private static final String BZ_PATH = "https://localhost/bugzilla/xmlrpc.cgi"; 

    /** 
    * Creates a new instance of the Bugzilla XML-RPC command executor for a specific command 
    * @param command A remote method associated with this instance of RPC call executor 
    */ 
    public BugzillaAbstractRPCCall(String command) { 
     synchronized (this) { 
      this.command = command; 
      if (client == null) { // assure the initialization is done only once 
       client = new XmlRpcClient(); 
       XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); 
       try { 
        config.setServerURL(new URL(BZ_PATH)); 
       } catch (MalformedURLException ex) { 
        Logger.getLogger(BugzillaAbstractRPCCall.class.getName()).log(Level.SEVERE, null, ex); 
       } 
       XmlRpcTransportFactory factory = new XmlRpcTransportFactory() { 

        public XmlRpcTransport getTransport() { 
         return new XmlRpcSunHttpTransport(client) { 

          private URLConnection conn; 

          @Override 
          protected URLConnection newURLConnection(URL pURL) throws IOException { 
           conn = super.newURLConnection(pURL); 
           return conn; 
          } 

          @Override 
          protected void initHttpHeaders(XmlRpcRequest pRequest) throws XmlRpcClientException { 
           super.initHttpHeaders(pRequest); 
           setCookies(conn); 
          } 

          @Override 
          protected void close() throws XmlRpcClientException { 
           getCookies(conn); 
          } 

          private void setCookies(URLConnection pConn) { 
           String cookieString = ""; 
           for (String cookieName : cookies.keySet()) { 
            cookieString += "; " + cookieName + "=" + cookies.get(cookieName); 
           } 
           if (cookieString.length() > 2) { 
            setRequestHeader("Cookie", cookieString.substring(2)); 
           } 
          } 

          private void getCookies(URLConnection pConn) { 
           String headerName = null; 
           for (int i = 1; (headerName = pConn.getHeaderFieldKey(i)) != null; i++) { 
            if (headerName.equals("Set-Cookie")) { 
             String cookie = pConn.getHeaderField(i); 
             cookie = cookie.substring(0, cookie.indexOf(";")); 
             String cookieName = cookie.substring(0, cookie.indexOf("=")); 
             String cookieValue = cookie.substring(cookie.indexOf("=") + 1, cookie.length()); 
             cookies.put(cookieName, cookieValue); 
            } 
           } 
          } 
         }; 
        } 
       }; 
       client.setTransportFactory(factory); 
       client.setConfig(config); 
      } 
     } 
    } 

    /** 
    * Get the parameters of this call, that were set using setParameter method 
    * @return Array with a parameter hashmap 
    */ 
    protected Object[] getParameters() { 
     return new Object[] {parameters}; 
    } 

    /** 
    * Set parameter to a given value 
    * @param name Name of the parameter to be set 
    * @param value A value of the parameter to be set 
    * @return Previous value of the parameter, if it was set already. 
    */ 
    public Object setParameter(String name, Object value) { 
     return this.parameters.put(name, value); 
    } 

    /** 
    * Executes the XML-RPC call to Bugzilla instance and returns a map with result 
    * @return A map with response 
    * @throws XmlRpcException 
    */ 
    public Map execute() throws XmlRpcException { 
     return (Map) client.execute(command, this.getParameters()); 
    } 
} 

Reemplace la clase proporcionando cus constructor de tom y por métodos de adición:

public class BugzillaLoginCall extends BugzillaAbstractRPCCall { 

    /** 
    * Create a Bugzilla login call instance and set parameters 
    */ 
    public BugzillaLoginCall(String username, String password) { 
     super("User.login"); 
     setParameter("login", username); 
     setParameter("password", password); 
    } 

    /** 
    * Perform the login action and set the login cookies 
    * @returns True if login is successful, false otherwise. The method sets Bugzilla login cookies. 
    */ 
    public static boolean login(String username, String password) { 
     Map result = null; 
     try { 
      // the result should contain one item with ID of logged in user 
      result = new BugzillaLoginCall(username, password).execute(); 
     } catch (XmlRpcException ex) { 
      Logger.getLogger(BugzillaLoginCall.class.getName()).log(Level.SEVERE, null, ex); 
     } 
     // generally, this is the place to initialize model class from the result map 
     return !(result == null || result.isEmpty()); 
    } 

} 
Cuestiones relacionadas