Skip to content

Commit

Permalink
modify test integration call
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushaga14 committed Sep 19, 2024
1 parent 83a9fe9 commit 68ded7c
Showing 1 changed file with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
import com.mongodb.client.model.Updates;
import com.opensymphony.xwork2.Action;

import okhttp3.Call;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;

public class JiraIntegrationAction extends UserAction {

Expand Down Expand Up @@ -71,17 +73,29 @@ public String testIntegration() {

String url = baseUrl + META_ENDPOINT;
String authHeader = Base64.getEncoder().encodeToString((userEmail + ":" + apiToken).getBytes());

Map<String, List<String>> headers = new HashMap<>();
headers.put("Authorization", Collections.singletonList("Basic " + authHeader));
OriginalHttpRequest request = new OriginalHttpRequest(url, "", "GET", null, headers, "");
try {
OriginalHttpResponse response = ApiExecutor.sendRequest(request, true, null, false, new ArrayList<>());
String responsePayload = response.getBody();
loggerMaker.errorAndAddToDb("triggered meta api for test integration step, requestbody " + request.getBody() + " ,responsebody " + response.getBody() + " ,responsestatus " + response.getStatusCode() + " ,url " + url, LoggerMaker.LogDb.DASHBOARD);
if (response.getStatusCode() != 200 || responsePayload == null) {
loggerMaker.errorAndAddToDb("error while testing jira integration, url not accessible", LoggerMaker.LogDb.DASHBOARD);

Request.Builder builder = new Request.Builder();
builder.addHeader("Authorization", "Basic " + authHeader);
builder = builder.url(url);
Request okHttpRequest = builder.build();
Call call = client.newCall(okHttpRequest);
Response response = null;
String responsePayload = null;
try {
response = call.execute();
responsePayload = response.body().string();
loggerMaker.errorAndAddToDb("error while testing jira integration, received null response", LoggerMaker.LogDb.DASHBOARD);
if (responsePayload == null) {
return Action.ERROR.toUpperCase();
}
} catch (Exception e) {
loggerMaker.errorAndAddToDb("error while testing jira integration, error making call" + e.getMessage(), LoggerMaker.LogDb.DASHBOARD);
return Action.ERROR.toUpperCase();
} finally {
if (response != null) {
response.close();
}
}
BasicDBObject payloadObj;
try {
Expand Down Expand Up @@ -112,11 +126,11 @@ public String testIntegration() {
return Action.ERROR.toUpperCase();
}
} catch(Exception e) {
return null;
return Action.ERROR.toUpperCase();
}
} catch (Exception e) {
loggerMaker.errorAndAddToDb("error while testing jira integration, " + e, LoggerMaker.LogDb.DASHBOARD);
return null;
return Action.ERROR.toUpperCase();
}

return Action.SUCCESS.toUpperCase();
Expand Down Expand Up @@ -244,10 +258,10 @@ public String createIssue() {
jiraTicketUrl = jiraIntegration.getBaseUrl() + "/browse/" + jiraTicketKey;
} catch(Exception e) {
loggerMaker.errorAndAddToDb(e, "error making jira issue url " + e.getMessage(), LoggerMaker.LogDb.DASHBOARD);
return null;
return Action.ERROR.toUpperCase();
}
} catch(Exception e) {
return null;
return Action.ERROR.toUpperCase();
}

UpdateOptions updateOptions = new UpdateOptions();
Expand Down

0 comments on commit 68ded7c

Please sign in to comment.