Skip to content

Commit

Permalink
Fix PublishToAnalyticsFunctionImpl bug due to graalVM's single thread…
Browse files Browse the repository at this point in the history
… restriction
  • Loading branch information
shanggeeth committed Feb 5, 2024
1 parent c54d015 commit 45bcf7c
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import static org.apache.http.HttpHeaders.CONTENT_TYPE;
Expand All @@ -51,9 +52,13 @@ public class PublishToAnalyticsFunctionImpl extends AbstractAnalyticsFunction im
public void publishToAnalytics(Map<String, String> metadata, Map<String, Object> payloadData,
JsBaseAuthenticationContext context) {

String appName = metadata.get(PARAM_APP_NAME);
String inputStream = metadata.get(PARAM_INPUT_STREAM);
String targetPath = metadata.get(PARAM_EP_URL);
Map<String, String> metadataMap = new HashMap<>(metadata);
Map<String, Object> payloadDataMap = new HashMap<>(payloadData);
String contextIdentifier = context.getWrapped().getContextIdentifier();

String appName = metadataMap.get(PARAM_APP_NAME);
String inputStream = metadataMap.get(PARAM_INPUT_STREAM);
String targetPath = metadataMap.get(PARAM_EP_URL);
String epUrl = null;
try {
if (appName != null && inputStream != null) {
Expand All @@ -78,7 +83,7 @@ public void publishToAnalytics(Map<String, String> metadata, Map<String, Object>

JSONObject jsonObject = new JSONObject();
JSONObject event = new JSONObject();
for (Map.Entry<String, Object> dataElements : payloadData.entrySet()) {
for (Map.Entry<String, Object> dataElements : payloadDataMap.entrySet()) {
event.put(dataElements.getKey(), dataElements.getValue());
}
jsonObject.put("event", event);
Expand All @@ -105,11 +110,11 @@ public void completed(final HttpResponse response) {
if (responseCode == 200) {
if (LOG.isDebugEnabled()) {
LOG.debug("Successfully published data to the analytics for session data key: " +
context.getWrapped().getContextIdentifier());
contextIdentifier);
}
} else {
LOG.error("Error while publishing data to analytics engine for session data key: " +
context.getWrapped().getContextIdentifier() + ". Request completed successfully. " +
contextIdentifier + ". Request completed successfully. " +
"But response code was not 200");
}
}
Expand All @@ -118,14 +123,14 @@ public void completed(final HttpResponse response) {
public void failed(final Exception ex) {

LOG.error("Error while publishing data to analytics engine for session data key: " +
context.getWrapped().getContextIdentifier() + ". Request failed with: " + ex);
contextIdentifier + ". Request failed with: " + ex);
}

@Override
public void cancelled() {

LOG.error("Error while publishing data to analytics engine for session data key: " +
context.getWrapped().getContextIdentifier() + ". Request canceled.");
contextIdentifier + ". Request canceled.");
}
});
}
Expand Down

0 comments on commit 45bcf7c

Please sign in to comment.