From 5cf22c0f74bab12a26ea6abe0b697b3bb376c39b Mon Sep 17 00:00:00 2001 From: Dulanjali Dilmi Date: Fri, 26 Jan 2024 17:58:23 +0530 Subject: [PATCH] Fix intermittent build failure in ESBJAVA3336HostHeaderValuePortCheckTestCase Related issue: https://github.com/wso2/micro-integrator/issues/3088 --- .../common/utils/ESBIntegrationTest.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/integration/tests-common/integration-test-utils/src/main/java/org/wso2/esb/integration/common/utils/ESBIntegrationTest.java b/integration/tests-common/integration-test-utils/src/main/java/org/wso2/esb/integration/common/utils/ESBIntegrationTest.java index 46dcc77289..f86ba61f61 100644 --- a/integration/tests-common/integration-test-utils/src/main/java/org/wso2/esb/integration/common/utils/ESBIntegrationTest.java +++ b/integration/tests-common/integration-test-utils/src/main/java/org/wso2/esb/integration/common/utils/ESBIntegrationTest.java @@ -1179,6 +1179,7 @@ protected void reloadSessionCookie() throws Exception { * @param logLevel - The log-level of synapse-transport-http-wire logger */ public void configureHTTPWireLogs(String logLevel) { + String loggerName = "synapse-transport-http-wire"; if (!isManagementApiAvailable) { Awaitility.await().pollInterval(50, TimeUnit.MILLISECONDS).atMost(DEFAULT_TIMEOUT, TimeUnit.SECONDS). until(isManagementApiAvailable()); @@ -1192,15 +1193,40 @@ public void configureHTTPWireLogs(String logLevel) { + "logging"; JSONObject payload = new JSONObject(); - payload.put("loggerName", "synapse-transport-http-wire"); + payload.put("loggerName", loggerName); payload.put("loggingLevel", logLevel); client.doPatch(endpoint, headers, payload.toString(), "application/json"); + Awaitility.await().pollInterval(50, TimeUnit.MILLISECONDS). + atMost(DEFAULT_TIMEOUT, TimeUnit.SECONDS).until(isLogsConfigured(endpoint, loggerName, logLevel)); } catch (IOException e) { throw new SynapseException("Error updating the log-level of synapse-transport-http-wire logger", e); } } + private Callable isLogsConfigured(String endpoint, String loggerName, String logLevel) { + return () -> isLogConfigured(endpoint + "?loggerName=" + loggerName, logLevel); + } + + private boolean isLogConfigured(String endpoint, String logLevel) { + try { + SimpleHttpClient client = new SimpleHttpClient(); + Map headers = new HashMap<>(); + headers.put("Accept", "application/json"); + + HttpResponse response = client.doGet(endpoint, headers); + String responsePayload = client.getResponsePayload(response); + if (response.getStatusLine().getStatusCode() != 200) { + return false; + } + JSONObject jsonResponse = new JSONObject(responsePayload); + return jsonResponse.get("level").toString().equals(logLevel); + } catch (IOException e) { + log.error("Error while checking the log-level", e); + return false; + } + } + private void copyArtifactToDeploymentDirectory(String sourceArtifactPath, String artifactName, String deploymentDirectory) throws IOException { Files.copy(new File(sourceArtifactPath + File.separator + artifactName + ".xml").toPath(),