Home » Java » Connect to JIRA using JAVA-Exceptionshub

Connect to JIRA using JAVA-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am trying to connect to JIRA using jira-java-client(provided by atlassian).

CODE DETAILS:
Here is my build.gradle file(app level)

apply plugin: 'com.android.application'
android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.appautomation"
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    testImplementation group: 'junit', name: 'junit', version: '4.12'
    testImplementation group: 'io.appium', name: 'java-client', version: '6.1.0'
    testImplementation group: 'org.testng', name: 'testng', version: '6.14.3'

    // https://mvnrepository.com/artifact/com.atlassian.jira/jira-rest-java-client-core
    implementation group: 'com.atlassian.jira', name: 'jira-rest-java-client-core', version: '5.1.1-e0dd194'
    // https://mvnrepository.com/artifact/com.atlassian.jira/jira-rest-java-client-api
    implementation group: 'com.atlassian.jira', name: 'jira-rest-java-client-api', version: '5.1.1-e0dd194'

    // https://mvnrepository.com/artifact/io.atlassian.fugue/fugue
    compileOnly group: 'io.atlassian.fugue', name: 'fugue', version: '4.7.2'

    // https://mvnrepository.com/artifact/org.slf4j/slf4j-api
    //implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.0-alpha1'
}

And this is my Java code for connection and fetching an issue

import com.atlassian.jira.rest.client.api.JiraRestClient;
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;
import java.net.URI;
import java.net.URISyntaxException;
import io.atlassian.util.concurrent.Promise;
import utils.LogUtils;

public class JiraIntegration {
    private final String USERNAME = EMAIL;
    private final String PASSWORD = API_TOKEN;

    public void jiraConnectionSetup() throws URISyntaxException {
        try {
            final URI jiraServerURI = new URI("https://jirajifflenow.atlassian.net/");
            final JiraRestClient jiraRestClient = new AsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(jiraServerURI, USERNAME, PASSWORD);
            Promise issuePromise = jiraRestClient.getIssueClient().getIssue("MOBILE-2773");
            LogUtils.setInfo("Here is you Issue" + issuePromise);
        } catch (Exception e) {
            LogUtils.setError("Error happened" + e);
            e.printStackTrace();
        }
    }
}

ERROR DETAILS:

Initially, only with jira-rest-java-client-core dependency, I was getting below error:

Caused by: java.lang.ClassNotFoundException: io.atlassian.fugue.Suppliers
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 8 more

for which I added fugue dependency(as suggested in community) but then I am getting below error:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.atlassian.httpclient.apache.httpcomponents.ApacheAsyncHttpClient.getRegistry(ApacheAsyncHttpClient.java:233)
    at com.atlassian.httpclient.apache.httpcomponents.ApacheAsyncHttpClient.<init>(ApacheAsyncHttpClient.java:158)
    at com.atlassian.httpclient.apache.httpcomponents.ApacheAsyncHttpClient.<init>(ApacheAsyncHttpClient.java:102)
    at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClientFactory.doCreate(DefaultHttpClientFactory.java:61)
    at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClientFactory.create(DefaultHttpClientFactory.java:36)
    at com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory.createClient(AsynchronousHttpClientFactory.java:65)
    at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.create(AsynchronousJiraRestClientFactory.java:36)
    at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.createWithBasicHttpAuthentication(AsynchronousJiraRestClientFactory.java:42)
    at JiraIntegration.jiraConnectionSetup(JiraIntegration.java:18)
    at SuiteBuilder.main(SuiteBuilder.java:25)
Caused by: java.lang.RuntimeException: Stub!
    at org.apache.http.conn.ssl.AbstractVerifier.<init>(AbstractVerifier.java:57)
    at org.apache.http.conn.ssl.AllowAllHostnameVerifier.<init>(AllowAllHostnameVerifier.java:54)
    at org.apache.http.nio.conn.ssl.SSLIOSessionStrategy.<clinit>(SSLIOSessionStrategy.java:67)
    ... 10 more

I even added slf4j-api dependency but still same error.

Am I missing something here?
Let me knwo if any more details needed.

How to&Answers: