Hi, I develop a plugin for issue page. In the plugin I am making a rest api call to jira server rest api to get boardId which issue’s sprints belongs to. It worked on my local jira but when I deploy plugin to my companie’s jira, issue page shows a blank screen and in the browser console I see this error:
So I had to disable plugin.
RPC: request rejected (bad origin): https://jtracker.company.com
import com.google.gson.Gson;
import com.trendyol.testManagementPlugin.model.SprintSummary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;
public class JiraRestApiClient {
private final Gson gson;
private final String token;
private static final Logger LOG = LoggerFactory.getLogger("atlassian.plugin");
public JiraRestApiClient(String token) {
this.gson = new Gson();
this.token = token;
}
public Integer getBoardIdBySprintId(long sprintId) {
HttpURLConnection connection = null;
try {
String baseUrl = "https://jtracker.trendyol.com/rest/agile/latest";
URL url = new URL(baseUrl + "/sprint/" + sprintId);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("accept", "application/json");
connection.setRequestProperty("Authorization","Bearer "+ token);
try (InputStream inputStream = connection.getInputStream()) {
String responseText = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))
.lines()
.collect(Collectors.joining("\n"));
if (connection.getResponseCode() == 200) {
return extractBoardIdFromResponse(responseText);
} else {
LOG.error("Status Code: {}. Reason: {}", connection.getResponseCode(), responseText);
return null;
}
}
} catch (IOException e) {
LOG.error(e.getMessage());
return null;
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
private Integer extractBoardIdFromResponse(String responseText) {
SprintSummary sprintSummary = gson.fromJson(responseText, SprintSummary.class);
return Integer.parseInt(sprintSummary.getOriginBoardId());
}
}