Skip to content

Commit

Permalink
Merge pull request #12330 from AnuGayan/master
Browse files Browse the repository at this point in the history
Fix issue when API Manager is running as a service in Windows env
  • Loading branch information
AnuGayan authored Mar 21, 2024
2 parents b3fcbfb + 45a43e6 commit 60cbaad
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2350,6 +2350,11 @@ public static class Monetization {
public static final String ADDITIONAL_ATTRIBUTES = "AdditionalAttributes";
public static final String ATTRIBUTE = "Attribute";

public static final String ANALYTICS_HOST = "AnalyticsHost";
public static final String ANALYTICS_PORT = "AnalyticsPort";
public static final String ANALYTICS_USERNAME = "AnalyticsUsername";
public static final String ANALYTICS_PASSWORD = "AnalyticsPassword";
public static final String ANALYTICS_INDEX_NAME = "AnalyticsIndexName";
public static final String IS_ATTRIBITE_REQUIRED = "Required";
public static final String IS_ATTRIBUTE_HIDDEN = "Hidden";
public static final String ATTRIBUTE_DESCRIPTION = "Description";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -424,7 +425,7 @@ private void readChildElements(OMElement serverConfig,
if (redisIsSslEnabled != null) {
redisConfig.setSslEnabled(Boolean.parseBoolean(redisIsSslEnabled.getText()));
}
if (propertiesElement !=null){
if (propertiesElement != null) {
Iterator<OMElement> properties = propertiesElement.getChildElements();
if (properties != null) {
while (properties.hasNext()) {
Expand Down Expand Up @@ -1722,49 +1723,88 @@ private void setMonetizationConfigurations(OMElement element) {
OMElement usagePublisherElement =
element.getFirstChildWithName(new QName(APIConstants.Monetization.USAGE_PUBLISHER_CONFIG));
if (usagePublisherElement != null) {
OMElement choreoInsightAPIEndpointElement = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.INSIGHT_API_ENDPOINT_CONFIG));
if (choreoInsightAPIEndpointElement != null) {
monetizationConfigurationDto.setInsightAPIEndpoint(choreoInsightAPIEndpointElement.getText());
}
if (analyticsProperties.get("type") != null && !analyticsProperties.get("type").trim().equals("")) {
OMElement analyticsHost = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.ANALYTICS_HOST));

OMElement analyticsAccessTokenElement = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.ANALYTICS_ACCESS_TOKEN_CONFIG));
if (analyticsAccessTokenElement != null) {
String analyticsAccessToken = MiscellaneousUtil.resolve(analyticsAccessTokenElement, secretResolver);
monetizationConfigurationDto.setAnalyticsAccessToken(analyticsAccessToken);
}
if (analyticsHost != null) {
monetizationConfigurationDto.setAnalyticsHost(analyticsHost.getText());
}

OMElement choreoTokenEndpointElement = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.CHOREO_TOKEN_URL_CONFIG));
if (choreoTokenEndpointElement != null) {
monetizationConfigurationDto.setChoreoTokenEndpoint(choreoTokenEndpointElement.getText());
}
OMElement analyticsPort = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.ANALYTICS_PORT));

OMElement consumerKeyElement = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.CHOREO_INSIGHT_APP_CONSUMER_KEY_CONFIG));
if (consumerKeyElement != null) {
String consumerKeyToken = MiscellaneousUtil.resolve(consumerKeyElement, secretResolver);
monetizationConfigurationDto.setInsightAppConsumerKey(consumerKeyToken);
}
if (analyticsPort != null) {
monetizationConfigurationDto.setAnalyticsPort(Integer.parseInt(analyticsPort.getText()));
}

OMElement consumerSecretElement = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.CHOREO_INSIGHT_APP_CONSUMER_SECRET_CONFIG));
if (consumerSecretElement != null) {
String consumerSecretToken = MiscellaneousUtil.resolve(consumerSecretElement, secretResolver);
monetizationConfigurationDto.setInsightAppConsumerSecret(consumerSecretToken);
}
OMElement analyticsUsername = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.ANALYTICS_USERNAME));

OMElement granularityElement = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.USAGE_PUBLISHER_GRANULARITY_CONFIG));
if (granularityElement != null) {
monetizationConfigurationDto.setGranularity(granularityElement.getText());
}
if (analyticsUsername != null) {
monetizationConfigurationDto.setAnalyticsUserName(analyticsUsername.getText());
}

OMElement analyticsPassword = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.ANALYTICS_PASSWORD));

if (analyticsPassword != null) {
monetizationConfigurationDto.setAnalyticsPassword(
analyticsPassword.getText().getBytes(StandardCharsets.UTF_8));
}

OMElement analyticsIndexName = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.ANALYTICS_INDEX_NAME));

if (analyticsIndexName != null) {
monetizationConfigurationDto.setAnalyticsIndexName(analyticsIndexName.getText());
}
} else {
OMElement choreoInsightAPIEndpointElement = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.INSIGHT_API_ENDPOINT_CONFIG));
if (choreoInsightAPIEndpointElement != null) {
monetizationConfigurationDto.setInsightAPIEndpoint(choreoInsightAPIEndpointElement.getText());
}

OMElement analyticsAccessTokenElement = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.ANALYTICS_ACCESS_TOKEN_CONFIG));
if (analyticsAccessTokenElement != null) {
String analyticsAccessToken = MiscellaneousUtil.resolve(analyticsAccessTokenElement,
secretResolver);
monetizationConfigurationDto.setAnalyticsAccessToken(analyticsAccessToken);
}

OMElement choreoTokenEndpointElement = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.CHOREO_TOKEN_URL_CONFIG));
if (choreoTokenEndpointElement != null) {
monetizationConfigurationDto.setChoreoTokenEndpoint(choreoTokenEndpointElement.getText());
}

OMElement publishTimeDurationElement = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.FROM_TIME_CONFIGURATION_PROPERTY));
if (publishTimeDurationElement != null) {
monetizationConfigurationDto.setPublishTimeDurationInDays(publishTimeDurationElement.getText());
OMElement consumerKeyElement = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.CHOREO_INSIGHT_APP_CONSUMER_KEY_CONFIG));
if (consumerKeyElement != null) {
String consumerKeyToken = MiscellaneousUtil.resolve(consumerKeyElement, secretResolver);
monetizationConfigurationDto.setInsightAppConsumerKey(consumerKeyToken);
}

OMElement consumerSecretElement = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.CHOREO_INSIGHT_APP_CONSUMER_SECRET_CONFIG));
if (consumerSecretElement != null) {
String consumerSecretToken = MiscellaneousUtil.resolve(consumerSecretElement, secretResolver);
monetizationConfigurationDto.setInsightAppConsumerSecret(consumerSecretToken);
}

OMElement granularityElement = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.USAGE_PUBLISHER_GRANULARITY_CONFIG));
if (granularityElement != null) {
monetizationConfigurationDto.setGranularity(granularityElement.getText());
}

OMElement publishTimeDurationElement = usagePublisherElement.getFirstChildWithName(
new QName(APIConstants.Monetization.FROM_TIME_CONFIGURATION_PROPERTY));
if (publishTimeDurationElement != null) {
monetizationConfigurationDto.setPublishTimeDurationInDays(publishTimeDurationElement.getText());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ public class MonetizationConfigurationDto {
private String insightAppConsumerSecret;
private String granularity;
private String publishTimeDurationInDays;

private String analyticsHost;

private int analyticsPort;

private String analyticsUserName;

private byte[] analyticsPassword;

public String getAnalyticsIndexName() {
return analyticsIndexName;
}

public void setAnalyticsIndexName(String analyticsIndexName) {
this.analyticsIndexName = analyticsIndexName;
}

private String analyticsIndexName;
private JSONArray monetizationAttributes = new JSONArray();

public String getMonetizationImpl() {
Expand Down Expand Up @@ -121,4 +139,36 @@ public void setPublishTimeDurationInDays(String publishTimeDurationInDays) {

this.publishTimeDurationInDays = publishTimeDurationInDays;
}

public String getAnalyticsHost() {
return analyticsHost;
}

public void setAnalyticsHost(String analyticsHost) {
this.analyticsHost = analyticsHost;
}

public int getAnalyticsPort() {
return analyticsPort;
}

public void setAnalyticsPort(int analyticsPort) {
this.analyticsPort = analyticsPort;
}

public String getAnalyticsUserName() {
return analyticsUserName;
}

public void setAnalyticsUserName(String analyticsUserName) {
this.analyticsUserName = analyticsUserName;
}

public byte[] getAnalyticsPassword() {
return analyticsPassword;
}

public void setAnalyticsPassword(byte[] analyticsPassword) {
this.analyticsPassword = analyticsPassword;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10160,8 +10160,6 @@ public static void initializeVelocityContext(VelocityEngine velocityEngine){
velocityEngine.setProperty(RuntimeConstants.OLD_CHECK_EMPTY_OBJECTS, false);
velocityEngine.setProperty(DeprecatedRuntimeConstants.OLD_SPACE_GOBBLING,"bc");
velocityEngine.setProperty("runtime.conversion.handler", "none");
velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, "classpath");
velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
}

/**
Expand Down

This file was deleted.

0 comments on commit 60cbaad

Please sign in to comment.