Developer’s Instructions

Please notice: This page describes the current version of B4J. If you are using version 1.x, please refer to the earlier version of this document.

How to create a Bugzilla session (XML configuration)

You basically need to instantiate BugzillaHttpSession and feed it with configuration data:

import org.apache.commons.configuration.XMLConfiguration;
import java.io.File;
import java.util.Iterable;
import b4j.core.session.BugzillaHttpSession;
import b4j.core.DefaultSearchData;
import b4j.core.Issue;
 
// Configure from file
XMLConfiguration myConfig = new XMLConfiguration(new File("myConfig.xml"));
 
// Create the session
BugzillaHttpSession session = new BugzillaHttpSession();
session.configure(myConfig);
 
// Open the session
if (session.open()) {
    // Search abug
    DefaultSearchData searchData = new DefaultSearchData();
    searchData.add("classification", "Java Projects");
    searchData.add("product", "Bugzilla for Java");
 
    // Perform the search
    Iterable i = session.searchBugs(searchData, null);
    for (Issue issue : i) {
       System.out.println("Bug found: "+issue.getId()+" - "+issue.getShortDescription());
    }
 
    // Close the session
    session.close();
}

where your config file is an XML file like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<bugzilla-session class="b4j.core.session.BugzillaHttpSession">
   <bugzilla-home>http://your-bugzilla.your-domain.com/<bugzilla-home>
   <AuthorizationCallback>
      <login>your-name</login>
      <password>your-password</password>
   </AuthorizationCallback>
   <Issue class="b4j.core.DefaultIssue"</Issue>
<bugzilla-session>

In case you need a proxy, please add:

<?xml version="1.0" encoding="ISO-8859-1"?>
<bugzilla-session class="b4j.core.session.BugzillaHttpSession">
   ...
   <proxy-host>192.168.0.250:8080</proxy-host>
   ...
<bugzilla-session>

If your proxy requires authorization, add the following snippet:

<?xml version="1.0" encoding="ISO-8859-1"?>
<bugzilla-session class="b4j.core.session.BugzillaHttpSession">
   ...
   <ProxyAuthorizationCallback>
      <login>your-proxy-name</login>
      <password>your-proxy-password</password>
   </ProxyAuthorizationCallback>
   ...
<bugzilla-session>

How to create a Bugzilla session (configuration by coding)

An alternative option for above configuration is done via programming only. We begin with configuring the net address where Bugzilla is available and the class we want to use for Bug instances:

// Create the session
BugzillaHttpSession session = new BugzillaHttpSession();
session.setBaseUrl(new URL("http://www.mybugzilla.com"));
session.setBugzillaBugClass(DefaultIssue.class);

The next steps depend on your specific Bugzilla instance and the network routing. If you require a login, create the appropriate callback.

AuthorizationCallback authCallback = new SimpleAuthorizationCallback("username", "password");
session.setAuthorizationCallback(authCallback);

If you sit behind a proxy, then you will need this snippet:

session.getHttpSessionParams().setProxyHost("192.168.0.250");
session.getHttpSessionParams().setProxyPort(8080);

If your proxy requires authorization:

AuthorizationCallback proxyAuthCallback = new SimpleAuthorizationCallback("username", "password");
session.getHttpSessionParams().setProxyAuthorizationCallback(proxyAuthCallback);
Please notice a bug in version 2.0.0 that causes ignorance of this parameters. Please use session.setProxy(Proxy) and session.setProxyAuthorizationCallback(AuthorizationCallback) for configuration of your proxy.The problem is fixed with version 2.0.1.

We have successfully configured how B4J connects to your Bugzilla instance. The remaining steps are identical to the first (XML) option.

// Open the session
if (session.open()) {
    // Search abug
    DefaultSearchData searchData = new DefaultSearchData();
    searchData.add("classification", "Java Projects");
    searchData.add("product", "Bugzilla for Java");
 
    // Perform the search
    Iterable i = session.searchBugs(searchData, null);
    for (Issue issue : i) {
       System.out.println("Bug found: "+issue.getId()+" - "+issue.getShortDescription());
    }
 
    // Close the session
    session.close();
}

You should check out the various Issue API methods to understand how to retrieve various information from a specific issue.

48 Responses to “Developer’s Instructions”

  1. Brandon Says:

    If I want to execute this example, what imports should I include?

  2. Ralph Says:

    You will need to include the Apache Commons Configuration and Commons Logging JAR files (delivered with B4J in lib directory) in your classpath. For the example above, you just need to “import org.apache.commons.configuration.*” and “import b4j.core.*”

  3. Ragunath Says:

    Could you please let me know what entry should be given in

    for login and password.

  4. Ragunath Says:

    Could you please let me know what entry should be given in

    for login and password in “ProxyAuthorizationCallback” tag in report-config.xml

  5. Ralph Says:

    Hi Ragunath!

    This basically depends on what your proxy id and password is. If you do not use any proxy then just remove the ProxyAuthorizationCallback and proxy-host tag.

  6. Ragunath Says:

    Hi Ralph,

    In bugzilla, we have “Status” , “Resolution”, “Severity”,”Priority”. But these thing are not captured in your xml file while creating a report. Please tell me wether these features are there in your tool.

    Thanks
    Ragunath.S

  7. Ragunath Says:

    Hi Ralph,

    Is ther anyway to export the http:url of the serach list to a file.please let me know.

    Thanks
    Ragunath.S
    9176060120

  8. Ralph Says:

    Hi Ragunath,

    if you are looking for configuring search criteria, you need to use <bug_status>NEW</bug_status>, <bug_severity>blocker</bug_severity> and <bug_priority>1</bug_priority> tags, see the example-report-config.xml. Multiple tags of the same name work like a “OR” condition.

    The URL cannot be exported currently. However, if you enable debug level in Commons Logging, the URL will be given in your log. Usually it is <root -path-of-bugzilla>/buglist.cgi?<search -param-name>=<value>, e.g. http://mydomain.com/buglist.cgi?bug_status=NEW

    Regards

    Ralph

  9. Ben Says:

    Hi,

    I would like to know more about the way to configure the search criterias ( what are the available tags ). Where is this example-report-config.xml you mentioned above ? I can’t find it in the archive you provide.

    Thanks,
    Ben

  10. Ralph Says:

    Hi Ben,

    The file is actually called report-config-example.xml and located in the conf sub directory. The tags are actually the GET parameter names that Bugzilla takes. So if you want to add some more search criteria, test it with your local Bugzilla app and use the parameter name.

    E.g. you make a query for bugs opened against PC hardware. You’ll find this part in your Bugzilla URL after querying: &rep_platform=PC&. That’s why you would need to use the tag <rep_platform>PC</rep_platform> 🙂

  11. prabhu Says:

    I am getting the exception. java.lang.ClassCastException: org.apache.commons.configuration.XMLConfiguration cannot be cast to org.apache.commons.configuration.SubnodeConfiguration

    1
    2
    3
    
    XMLConfiguration myConfig = new XMLConfiguration(new File("src/myConfig.xml"));
    HttpBugzillaSession session = new HttpBugzillaSession();
    session.configure(myConfig); //exception here
    1
    2
    3
    4
    5
    6
    
       <bugzilla-home>http://localhost/</bugzilla-home>
       <AuthorizationCallback>
          <login>p2@ss.com</login>
          <password>password</password>
       </AuthorizationCallback>
       <Issue class="b4j.core.DefaultBugzillaBug"/>
  12. Elmar Says:

    working myConfig.xml:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    <?xml version="1.0" encoding="UTF-8"?>
    <bugzilla-session class="b4j.core.session.HttpBugzillaSession">
    	<bugzilla-home>http://bugzilla.example.com/</bugzilla-home>
    	<AuthorizationCallback class="">
    		<your-name>user@example.com</your-name>
    		<your-password>password</your-password>
    	</AuthorizationCallback>
    	<BugzillaBug class="b4j.core.DefaultBugzillaBug"/>
    </bugzilla-session>
  13. Ralph Says:

    Please notice that you don’t need to use an XML config when configuring programmatically. There are setter methods available on the session classes that can be used.

    I will take care of the ClassCastException next :o)

  14. Ralph Says:

    Found it. Fixed with 1.4.0 🙂

  15. Praveen GB Says:

    Ralph,

    This seems like excellent work in the lines of PMO needs. However, would you please be able to write a note about configuration and usage of the Reports module? I see there is a main in b4j.GenerateReports class. Is that the main entry point in to reports?

    I’m seeing the following without knowing what is expected

    java -classpath $b4jlibs b4j.GenerateReports –xml-file conf/report-config-example.xml

    praveen.gb@msi-l338 /cygdrive/d/work/tools/bugzilla/b4j-1.4.0
    $ ./runreport.sh
    2013-06-22 06:33:16,612 [INFO ] b4j.GenerateReports – GenerateReports started
    2013-06-22 06:33:18,207 [INFO ] b4j.core.session.HttpBugzillaSession – Session opened: https://bugzilla.metric
    2013-06-22 06:33:21,579 [INFO ] b4j.core.session.HttpBugzillaSession – Session closed
    2013-06-22 06:33:21,580 [INFO ] b4j.GenerateReports – GenerateReports finished

  16. Ralph Says:

    Hi Praveen,

    thank you for the hint. I added more documentation at User’s Instruction Page (not completed though).

    Ralph

  17. Thomas Shippey Says:

    Hi Ralph

    Thank you for your great work. Using this tool I have managed to get bug information from Eclipse . But currently it seems be limited to return only 500 bugs per query. Is there any way I can change this?

    Thanks for your help in advance.

    Regards

    Thomas

  18. Thomas Shippey Says:

    Hi Ralph

    No worries. I have worked out how to do this.

    For others wondering. You just need to add to the DefaultSearchData.

    1
    2
    
    DefaultSearchData dsd = new DefaultSearchData();
    dsd.add("limit", "0");

    Keep up the good work =)

    Thomas

  19. Sofi Says:

    Hi Ralph,

    Thank you for this useful page.
    I face a problem here and would be very grateful for any help.

    When I get result of searchBug, which is an Iterator and contains some bug info (available bugs list is empty, bugs list contains items), on next() operation program hangs for some time then throws exception:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    Exception in thread "Thread-0" java.lang.NullPointerException
    	at b4j.core.session.AbstractAuthorizedSession.createIssue(AbstractAuthorizedSession.java:172)
    	at b4j.core.session.HttpBugzillaSession$XmlParser.startElement(HttpBugzillaSession.java:556)
    	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506)
    	at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:745)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1323)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2717)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
    	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
    	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
    	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
    	at b4j.core.session.HttpBugzillaSession$XmlParser.run(HttpBugzillaSession.java:530)
    	at java.lang.Thread.run(Thread.java:722)

    Thanks!

  20. Ralph Says:

    Hello Sofi,

    I just checked the code. It looks like the BugzillaBugClass was not specified. You can fix it by either specifiying <BugzillaBug class="b4j.core.DefaultIssue"/> within the <bugzilla-session> tag, or by calling setBugzillaBugClass(DefaultIssue.class) in your code. Depends on which config way you had chosen. I also just fixed the documentation.

    I will assign a default value in the next version. Thank you for the hint!

    Regards

    Ralph

  21. Sofi Says:

    Hi Ralph,

    Thank you for the help, that really resolved the issue.

    Regards,
    Sofi

  22. Michael Says:

    Hi Ralph,

    I’m using b4j 2.0.0 using the configuration by coding.

    I was asking myself if b4j also supports accessing Bugzilla servers via “https”. Does it? I couldn’t find something in the docu or via google. I feel that I get an exception due to that:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    
    2014-03-17 16:41:43,540 [ERROR] b4j.core.session.BugzillaHttpSession - Cannot perform search
    javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    	at sun.security.ssl.Alerts.getSSLException(Unknown Source)
    	at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
    	at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
    	at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
    	at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
    	at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
    	at sun.security.ssl.Handshaker.processLoop(Unknown Source)
    	at sun.security.ssl.Handshaker.process_record(Unknown Source)
    	at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
    	at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
    	at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    	at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    	at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
    	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
    	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    	at java.net.HttpURLConnection.getResponseCode(Unknown Source)
    	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
    	at b4j.core.session.BugzillaHttpSession.searchBugs(BugzillaHttpSession.java:291)
    	at com.bosch.devmeth.bugzilla2rtc.Bugzilla2RTC.main(Bugzilla2RTC.java:51)
    Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    	at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
    	at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
    	at sun.security.validator.Validator.validate(Unknown Source)
    	at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source)
    	at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
    	at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
    	... 15 more
    Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    	at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
    	at java.security.cert.CertPathBuilder.build(Unknown Source)
    	... 21 more

    And one more hint: Your docu (including the javadoc free text) says that searchBugs returns an Iterator, but it returns an Iterable.

    Best regards
    Michael

  23. Ralph Schuster Says:

    Hello Michael,

    thanks for the information.

    Regarding SSL problem: In general, B4J makes no special handling of SSL connections because Java handles this internally. However, if your server presents a SSL certificate that cannot be verified successfully, this Java handling fails. The following link suggests two ways how to prevent this to fail: http://stackoverflow.com/questions/11164324/sending-http-request-to-server-have-exception-sometimes-happen

    1.) Add the certificate to your trust store
    2.) Configure a different X509TrustManager (as explained here: http://stackoverflow.com/questions/2694281/ignore-certificate-errors-when-requesting-a-url-in-java ) – best is to override BugzillaHttpSession.HttpURLConnection getConnection(int bugzillaPage, String getParams) in your own session class and install the manager there.

    I will think about an easier way to manage SSL certificates from within the session object.

    PS: I fixed this doc page and the Javadoc as, it will come with next release. Thanks for the hint (this was a B4J 2.0 change)

  24. Michael Says:

    Hi Ralph,

    thanks for the hint and thanks for the very short response time. I really enjoy.

    In fact for the moment I followed http://stackoverflow.com/a/876785, which I just copied and it worked ;-).

    Now having access I found that I don’t get private comments. I checked the login and session.isLoggedIn() returns true. The user name I used is member of the insidergroup (and I even tried with the admin group).
    I used:

    1
    2
    3
    
    		AuthorizationCallback authCallback = new SimpleAuthorizationCallback(
    				"email", "password");
    		session.setProxyAuthorizationCallback(authCallback);

    to log in. Also I could not find a documentation or functions handling private comments.

    And one more question: Is it possible to add comments into bugzilla? I found:#

    1
    2
    
    		setComments(Collection comments)
    		Sets the comments for this issue.

    Is this an internal function or does it allow to add comments? I really would like to have an example for writing comments or setting a different state.

    Best Regards
    Michael

  25. Ralph Schuster Says:

    Hi Michael,

    it looks like u have set the Proxy Authorization, not the Bugzilla Authorization: session.setAuthorizationCallback(). The isLoggedIn() method returns true when the session with Bugzilla was established. This is true for anonymous sessions too.

    This shall then also reveal “private” comments. Although I cannot confirm that they will appear. The BugzillaHttpSession relies on the XML format of a search request – You can verify the existance of these comments when you login to your Bugzilla and perform a search there. Click on “XML Format” to see whether the comments are in there.

    B4J is a pure reporting tool. It does not support any modifications. The forementioned setComments() method is currently for internal use. The BugzillaRpcSession will support modifications in one of the future releases.

    Regards

    Ralph

  26. Jan Says:

    Hi Ralph,
    is it possible to get a list of all products in my bugzilla instance with your b4j API? I didn’t find a way.
    Or is the b4j API only for bug search and creating reports?

    Best Regards, Jan

  27. Ralph Schuster Says:

    Hello Jan,

    yes, the V2.0 introduces the REST API client. It offers a special method for listing “accessible” product: BugzillaProductRestClient.html#getAccessibleProducts()

    An example of how to use it can be seen from the unit test, see AsyncBugzillaProductRestClientTest

  28. Jan Says:

    Hi Ralph,
    Thx for your quick answer, I brought it to work with your help.
    Here is my code:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    	URL baseUrl = new URL("https://bugzilla.domain.de");
    	URI serverUri = baseUrl.toURI();
    	HttpSessionParams httpSessionParams = new HttpSessionParams();
    	HttpClient httpClient = HttpClients.createAtlassianClient(serverUri, httpSessionParams);
    	BugzillaRestClientFactory factory = new AsyncBugzillaRestClientFactory();
    	BugzillaClient bugzillaClient = factory.create(serverUri, httpClient);
    	bugzillaClient.login("username", "password");
    	BugzillaProductRestClient bugzillaProductRestClient = bugzillaClient.getProductClient();
    	Promise<Iterable> accessibleProducts = bugzillaProductRestClient.getAccessibleProducts();
    	for (Project project : accessibleProducts.get()) {
    		System.out.println(project.getName());
    	}

    Another question:
    Is it normal that the Bugzilla REST API is so slow? For my code above it takes around 30 seconds for getting the list which contains 40 products. Other Bugzilla REST calls are also so slow. Or is there a problem in my Bugzilla configuration? We use Bugzilla 4.2.1

  29. Ralph Schuster Says:

    Hi Jan,

    the Bugzilla WebService API is not very handy. A lot of information is missing when you retrieve product information, such as versions, components etc. That’s why a LazyRetriever exists to request the data once it is required. The LazyRetriever tries to collect all requests to optimize the performance. However, iterating on issues or products may cause that such a bulk request is not possible.

    I tested the code you posted with my Bugzilla instance and it is quite fast on just returning the names.

    So your performance bottleneck probably is caused by other requests. Can you give me your code where you iterate over the products? I can try to optimize the retrieval for the next release which is planned in a few days anyway.

  30. Jan Says:

    Hey Ralph,
    i’ve isolated my code to this test code:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    
    public class BugzillaTest {
     
    	@Test
    	public void testGetAcessibleProducts() throws MalformedURLException, URISyntaxException, InterruptedException, ExecutionException {
    		URL baseUrl = new URL("https://bugzilla.de");
    		URI serverUri = baseUrl.toURI();
    		HttpSessionParams httpSessionParams = new HttpSessionParams();
    		HttpClient httpClient = HttpClients.createAtlassianClient(serverUri, httpSessionParams);
    		BugzillaRestClientFactory factory = new AsyncBugzillaRestClientFactory();
    		BugzillaClient bugzillaClient = factory.create(serverUri, httpClient);
    		bugzillaClient.login("user", "password");
    		BugzillaProductRestClient bugzillaProductRestClient = bugzillaClient.getProductClient();
    		Promise<Iterable> accessibleProducts = bugzillaProductRestClient.getAccessibleProducts();
    		for (Project project : accessibleProducts.get()) {
    			System.out.println("");
    			System.out.println(project.getName());
    			System.out.println("Components: " + project.getComponents());
    			System.out.println("Versions: " + project.getVersions());
    		}
    	}
    }

    This needs only 4-6 seconds for one run (with 40 products) and I think thats ok? I don’t know where my first 30 seconds come from ;-). We’re using this code to fill a jsf combobox with content.
    Thanks for your help and your offer to review my code.

    Keep going on with b4j!
    Jan

  31. Ralph Schuster Says:

    Hi Jan,

    Good to hear that the code runs fast enough for you. Nevertheless, I noticed some potential problems in my code regarding components and versions while I was fixing issues from static code analysis. I will publish a fix (V2.0.1) this night so it will be available by tomorrow. This could further improve performance – although I cannot promise. 🙂

  32. Christian Richter Says:

    Hi Ralph,

    is there a reason why you cannot retrieve more than 10.000 Tickets?

    Thanks & regards
    Christian

  33. Ralph Schuster Says:

    Hi Christian,

    I assume you hit a limit on Bugzilla?! The B4J does not make any assumption or maximum number of tickets (unless I forgot something, hmmm).

    What makes you think that there is such a limit?

    Regards

    Ralph

  34. Christian Richter Says:

    Hi Ralph,

    I try to retrieve all tickets for a product from the bugzilla (I’ve tried apache/eclipse/kde) and when I set the limit to “0” as mentioned aboth, I can not get more then 10k tickets from the trackers.

    Maybe you are right that I hit a limit from the remote tracker I am not sure.

  35. saidou Says:

    Hi Ralph,

    I’m using J4B 2.0.1 for collecting bugs from bugzilla and Jira. Its work find for many Jira ITS servers but i cannot retrieve issue from issue.apache.org/jira (jira 6.3.4). I got this message exception “Cannot retrieve issue: AMQ-2556” from JiraRpcSession.java:208 .

    Thaank’s for helpping me to resolve it.

  36. saidou Says:

    Hi Ralph,
    Thanks for your quick answer.

    Here is the code:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    public class JiraITS {
            public static void main(String[] args) throws URISyntaxException, IOException {
                    // TODO Auto-generated method stub
                    AbstractHttpSession session = new JiraRpcSession();
                    ((JiraRpcSession) session).setBaseUrl(new URL("https://issues.apache.org/jira"));
                    session.setBugzillaBugClass(DefaultIssue.class);
                    if (session.open()){
                            DefaultSearchData searchData = new DefaultSearchData();
                        searchData.add("jql", "project = AMQ AND issuetype = Bug AND status in (Resolved, Closed) AND resolution = Fixed");
                            Iterator i = session.searchBugs(searchData, null).iterator();               
                        while (i.hasNext()) {
                              Issue issue= i.next();
                              System.out.println(issue.getId());
                        }
                    }
            }
    }

    and here is the stacktrace:

    Exception in thread "main" java.lang.RuntimeException: Cannot retrieve issue: AMQ-5632
            at b4j.core.session.JiraRpcSession.getIssue(JiraRpcSession.java:208)
            at b4j.core.session.JiraRpcSession$SearchIterator.next(JiraRpcSession.java:368)
            at b4j.core.session.JiraRpcSession$SearchIterator.next(JiraRpcSession.java:345)
            at pl.wroc.pwr.buginfo.its.JiraITS.main(JiraITS.java:54)
    Caused by: java.lang.NullPointerException
            at b4j.core.session.JiraRpcSession.createIssue(JiraRpcSession.java:237)
            at b4j.core.session.JiraRpcSession.getIssue(JiraRpcSession.java:206)
            ... 3 more
  37. Ralph Schuster Says:

    Hi Saidou,

    thank you for the stacktrace. I opened a bug BFJ-84 which I will process this evening and release a new version.

  38. saidou Says:

    Thanks Ralph.

  39. saidou Says:

    Hi Ralph,

    I tryed the B4J v2.0.2 and it working find, but when i run a JQL query I only get 50 results back.
    How can I increase the results returned?

  40. Ralph Schuster Says:

    Hello Saidou,

    you stumbled across a Jira limit for queries. See here.

    In order to overcome this shortly, I recommend to write a new class extending from JiraRpcSession. Overwrite the following function

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    
    	@Override
    	public Iterable<Issue> searchBugs(SearchData searchData, SearchResultCountCallback callback) {
    		checkLoggedIn();
    		int maxResults = searchData.hasParameter("maxResults") ? LangUtils.getInt(searchData.get("maxResults").iterator().next()) : 50;
    		int startAt = searchData.hasParameter("startAt") ? LangUtils.getInt(searchData.get("startAt").iterator().next()) : 0;
     
    		Promise<SearchResult> result = null;
    		if (searchData.hasParameter("filterId")) {
    			result = filterClient.search(searchData.get("filterId").iterator().next(), maxResults, startAt);
    		} else if (searchData.hasParameter("jql")) {
    			String jql = searchData.get("jql").iterator().next();
    			result = jiraClient.getSearchClient().searchJql(jql, maxResults, startAt);
    		} else if (searchData.hasParameter("key")) {
    			result = jiraClient.getSearchClient().searchJql("key in ("+join(searchData.get("key"))+")", maxResults, startAt);
    		} else {
    			getLog().error("no search data given");
    		}
    		if (result != null)
    			try {
    				return new SearchIterator(result);
    			} catch (Exception e) {
    				throw new RuntimeException("Cannot retrieve issues", e);
    			}
    		return null;
    	}

    Now set the parameter maxResults and/or startAt in the search data parameter call and it should fix this problem. Don’t forget to use your new session class instead of JiraRpcSession.

    I already added this enhancement to my development version but will not publish it before tested it intensively. I also like to include a way to retrieve all records without this parameters if Jira allows it.

  41. saidou Says:

    Hi Ralph,

    Thank u for your quick answer.

    This solution cannot work because some attribute use in the overwrited function are declared as private and not protected in the JiraRpcSession class.

    Regard,

    Saidou.

  42. Ralph Schuster Says:

    Hello Saidou,

    I am sorry. You are right. A workaround is to completely replace the class by your own version of it. Take the source code and replace the single method. I will add methods for those private attributes in the next version allowing inheritance. I will also include a possibility to set those limitation parameters.

    Regards,

    Ralph

  43. Scott Boag Says:

    My company upgraded our bugzilla to version 4.4.8. Before the following code used to work:


    b4j.core.SearchData searchData = new DefaultSearchData();
    searchData.add(“bug_status”, “NEW”);
    Iterable issues = session.searchBugs(searchData, null);
    Iterator issuesIter = issues.iterator();
    for (; issuesIter.hasNext();) {
    Issue issue = issuesIter.next();
    System.out.println(“”+issue.getId()+”\t”+issue.getAssignee()+”\t”+issue.getSummary());
    }

    But now the iterator is empty. Any ideas about what could be going on?

  44. Scott Boag Says:

    My bugzilla 4.4.8 bug is happening because the login fails:

    You tried to log in using the xxx@xxx.xxx.com account, but Bugzilla is unable to trust your request. Make sure your web browser accepts cookies and that you haven’t been redirected here from an external web site. Click here if you really want to log in.

    I’ve googled this, and it seems to be a well-known thing, but I can’t figure out what to do about it. If you’ve any ideas, let me know.

  45. Ralph Says:

    Hey Scott,

    I will check this issue with my Bugzilla test installation and get back to you. Please be patient.

    Regards

    Ralph

  46. Scott Boag Says:

    Hi Ralph, were you able to reproduce the problem with the Untrusted Authentication Request result?

    I added to your code…

    if (con.getResponseCode() == 200) {
    //debugResponse(con);
    boolean rc = retrieveCookies(con);

    // Get Bugzilla version and test for compatibility
    BufferedReader r = new BufferedReader(new InputStreamReader(con.getInputStream(), Charsets.UTF_8));
    Pattern p = Pattern.compile(“.*version\\s+([\\d\\.]+).*”, Pattern.CASE_INSENSITIVE);
    Pattern p2 = Pattern.compile(“.*Untrusted\\s+Authentication\\s+Request.*”, Pattern.CASE_INSENSITIVE);

    String line;
    String untrusted = null;
    while ((line = r.readLine()) != null) {
    // System.err.println(line);
    // Search for: version 3.0.5
    Matcher m = p.matcher(line);
    if (m.matches()) {
    setBugzillaVersion(m.group(1));
    break;
    }
    Matcher m2 = p2.matcher(line);
    if (m2.matches()) {
    untrusted = line.trim();
    }
    }
    if(untrusted != null){
    getLog().error(“Cannot open session: Result contained \””+untrusted+”\””);
    return false;
    }

    setLoggedIn(rc);

    But, beyond that, I still don’t know what to do.

    Apparently, mylyn (and, down stream, netbeans) had this problem. See https://netbeans.org/bugzilla/show_bug.cgi?id=244069.

    If I could even come up with some sort of workaround, like manually logging in.

  47. Ralph Schuster Says:

    Hello Scott,

    I tested a login with my 4.4.10 installation. It worked perfectly. Can you check whether you are able to upgrade to 4.4.10 and that you have latest B4J version 2.0.2 installed?

    Regards

    Ralph

  48. Ralph Schuster Says:

    Hello Scott,

    B4J 2.0.3 fixes this issue (although it’s merely a workaround for a deviation of Bugzilla behaviour) 🙂

    Regards

    Ralph

Leave a Reply