-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsampleJwtGenerator.java
More file actions
63 lines (52 loc) · 2.18 KB
/
sampleJwtGenerator.java
File metadata and controls
63 lines (52 loc) · 2.18 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//package com.thed.zapi.cloud.sample;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import com.thed.zephyr.cloud.rest.ZFJCloudRestClient;
import com.thed.zephyr.cloud.rest.client.JwtGenerator;
/**
* @author swapna.vemula 12-Dec-2016
*
*/
public class sampleJwtGenerator {
/**
* @param args
* @author Created by swapna.vemula on 12-Dec-2016.
* @throws URISyntaxException
* @throws JobProgressException
* @throws JSONException
* @throws IOException
* @throws IllegalStateException
*/
public static void main(String[] args) throws URISyntaxException, IllegalStateException, IOException {
// Replace Zephyr BaseUrl with the <ZAPI_CLOUD_URL> shared with ZAPI Cloud Installation
String zephyrBaseUrl = "https://prod-api.zephyr4jiracloud.com/connect";
// zephyr accessKey , we can get from Addons >> zapi section
String accessKey = "MjQ0NjU0ZmEtNTUzNi0zZGRiLWE4ODktMjYyMDYyZjJhNTk4IGFkbWluIFVTRVJfREVGQVVMVF9OQU1F";
// zephyr secretKey , we can get from Addons >> zapi section
String secretKey = "bYuxqjx8YTbjb_Oped_GV-vP3lHdg97l2Bo3Z9ZJoNM";
// Jira UserName
String userName = "admin";
ZFJCloudRestClient client = ZFJCloudRestClient.restBuilder(zephyrBaseUrl, accessKey, secretKey, userName).build();
JwtGenerator jwtGenerator = client.getJwtGenerator();
System.out.println(args[0]);
// API to which the JWT token has to be generated
String createCycleUri = zephyrBaseUrl + args[0];
URI uri = new URI(createCycleUri);
int expirationInSec = 20000;
String jwt = jwtGenerator.generateJWT("GET", uri, expirationInSec);
// Print the URL and JWT token to be used for making the REST call
System.out.println("FINAL API : " +uri.toString());
System.out.println("JWT Token : " +jwt);
}
}