If it is a local Jira (installed on your system), you can call any client API to retrieve the data by simply specifying the url and auth encoded (with username and password).
String getUrl = applicationProperties.getjURL() + "/rest/api/1.0/XXX"; String jiraUser = applicationProperties.getJiraUser().trim(); String jiraPwd = applicationProperties.getJiraPassword().trim(); String auth = new String(Base64.encode(jiraUser + ":" + jiraPwd)); HttpGet get = new HttpGet(getUrl); StringEntity postingString = new StringEntity(gson.toJson(descrptionBean)); post.setEntity(postingString); post.setHeader("Authorization", "Basic " + auth); post.setHeader("Content-type", "application/json"); HttpClient httpClient = new org.apache.http.impl.client.DefaultHttpClient(); HttpResponse response = httpClient.execute(get);
... but if it is SSL / https secure, you need to set the system property with truststore, keystore, keyStorePassword, etc. (in the case of using Java as a technology). You can use the JiraRestClientFactory API to create a jira client, as shown below.
public JiraRestClient getRestClient() { System.setProperty("javax.net.ssl.trustStore", Constants.KEYSTORE); System.setProperty("javax.net.ssl.keyStore", Constants.KEYSTORE); System.setProperty("javax.net.ssl.keyStorePassword", "changeit"); String trustStore = System.getProperty("javax.net.ssl.trustStore"); System.setProperty("-Dlog4j.configuration", "log4j.properties"); if (trustStore == null) { Constants.REPORT.info("javax.net.ssl.trustStore is not defined, Please generate \"KeyStore.jks\" of JIRA Instance"); } final JiraRestClientFactory jiraRestClientFactory = new AsynchronousJiraRestClientFactory(); final HttpClientOptions options = new HttpClientOptions(); options.setConnectionTimeout(15, TimeUnit.MINUTES); options.setSocketTimeout(15, TimeUnit.MINUTES); options.setConnectionPoolTimeToLive(15, TimeUnit.MINUTES); options.setRequestPreparer(new Effect<Request>() { @Override public void apply(final Request request) { new BasicHttpAuthenticationHandler(applicationProperties.getJiraUser().trim(), applicationProperties.getJiraPassword().trim()).configure(request); } }); try { URI serverUri = new URI(applicationProperties.getjURL().trim()); defaultHttpClient = new DefaultHttpClient<>(new NoOpEventPublisher(), new RestClientApplicationProperties(serverUri), ThreadLocalContextManagers.noop(), options); return jiraRestClientFactory.create(serverUri, defaultHttpClient); } catch (Exception e) { String msg = "Terminating the application while connecting to RestClient : " + e.getMessage(); Constants.REPORT.info("javax.net.ssl.trustStore is not defined, Please generate \"KeyStore.jks\" of JIRA Instance"); Constants.REPORT.info(msg); Constants.ERROR.info(msg); Constants.ERROR.info(Level.SEVERE, e); System.exit(-1); } return null; }
source share