有没有java api可以访问bugzilla?

发布于 2024-07-14 17:56:30 字数 1542 浏览 9 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

飘落散花 2024-07-21 17:56:30

我知道这个话题有点老了,但很可能有同样问题的人会在这里找到答案,我想分享一篇我写的关于四个 Java 客户端库的博客文章,这些库是我发现用于访问 Bugzilla 的:J2Bugzilla、B4J(Bugzilla)对于 Java)、Bugzilla 库、LightingBugAPI。

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

此致,
南达那

I know this is a bit old thread but as it is quite possible that people with the same question could land up here I thought of sharing a blog post I wrote about four Java client libraries that I found for accessing Bugzilla: J2Bugzilla, B4J (Bugzilla for Java), Bugzilla Library, LightingBugAPI.

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

Best Regards,
Nandana

最初的梦 2024-07-21 17:56:30

Apache WS XML-RPC(现在太拗口了!)您可以使用的完整 XML-RPC 实现。 我不太了解 BugZilla,但假设它支持 XML-RPC,那么使用我刚刚链接的那些可怕的内容应该不会有任何问题。

There's Apache WS XML-RPC (now that's a mouthful!) which is a full XML-RPC implementation that you could use. I don't know BugZilla that well but assuming it supports XML-RPC, there shouldn't be any issues using the monstrous mouthful I just linked.

尹雨沫 2024-07-21 17:56:30

该库/API 称为 JAX-WS(或 JAXB),可让您调用任何性质的 WS。 获取模式,生成 Bean 和代理,然后调用它们。

The library/API is called JAX-WS (or JAXB), and lets you call WS of any nature. Get the schema, generate the beans and proxies, call them.

暗喜 2024-07-21 17:56:30

这是一个通过 Java 使用 bugzilla api 的简单示例。
http://codehelpline.blogspot.com/ 2010/08/如何访问-bugzilla-webservice-api.html

Here's a simple example for using bugzilla api with Java..
http://codehelpline.blogspot.com/2010/08/how-to-access-bugzilla-webservice-api.html

瑾夏年华 2024-07-21 17:56:30

还有 Mylyn,它应该在 Eclipse 之外独立运行。 然而,我还没有设法将它独立出来。 您可以尝试一下我自己的 Bugzilla Java API,它试图满足最紧迫的需求:http://techblog.ralph-schuster.eu/b4j-bugzilla-for-java/

There is also Mylyn which is supposed to run stand-alone outside Eclipse. However, I did not manage yet to have it stand-alone. You can give a try to my own Bugzilla Java API which tries to cover the most urgent needs: http://techblog.ralph-schuster.eu/b4j-bugzilla-for-java/

谁人与我共长歌 2024-07-21 17:56:30

Mylyn 可能是您不错的选择。

如果您需要更简单的设置或更好地控制事情的发生方式,您可以编写自己的 XML-RPC 调用来 Bugzilla Web 服务接口。 我在博客上总结了该过程: 使用 Apache XML-RPC 从 Java 与 Bugzilla 聊天

总结一下:

  • 获取 Apache XML-RPC 库
  • 从 commons(旧版本)获取 Apache HTTP 客户端

然后使用以下类作为基类(它处理 cookie 等)并覆盖它:

/**
 * @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());
    }
}

通过提供自定义构造函数和覆盖该类通过添加方法:

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());
    }

}

Mylyn could be a good choice for you.

If you need simpler setup or better control of how things happen, you can write your own XML-RPC calls to Bugzilla web-service interface. I have summarized the process on my blog: Chat to Bugzilla from Java using Apache XML-RPC.

To sum it up:

  • get the Apache XML-RPC libs
  • get the Apache HTTP Client from commons (older version)

Then use following class as a base class (it handles cookies etc.) and override it:

/**
 * @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());
    }
}

Override the class by providing custom constructor and by adding methods:

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());
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文