Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for [HUBDEV-2367] add request id to log entries #177

Open
wants to merge 2 commits into
base: mediator_stabilize-M2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions com.wso2telco.dep.common.capp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<com.wso2telco.dep.common.template_._mediation.common.doubleGTZeroValidation.Template>capp/EnterpriseServiceBus</com.wso2telco.dep.common.template_._mediation.common.doubleGTZeroValidation.Template>
<com.wso2telco.dep.common.template_._com.wso2telco.dep.common.integerValidation.Template>capp/EnterpriseServiceBus</com.wso2telco.dep.common.template_._com.wso2telco.dep.common.integerValidation.Template>
<com.wso2telco.dep.common.template_._com.wso2telco.dep.common.loggingExtension.Template>capp/EnterpriseServiceBus</com.wso2telco.dep.common.template_._com.wso2telco.dep.common.loggingExtension.Template>
<com.wso2telco.dep.common.template_._com.wso2telco.dep.common.anonymizeUserData.Template>capp/EnterpriseServiceBus</com.wso2telco.dep.common.template_._com.wso2telco.dep.common.anonymizeUserData.Template>
<com.wso2telco.dep.common.template_._com.wso2telco.dep.common.integerOffsetAndLimitValidation.Template>capp/EnterpriseServiceBus</com.wso2telco.dep.common.template_._com.wso2telco.dep.common.integerOffsetAndLimitValidation.Template>
<com.wso2telco.dep.common.sequence_._com.wso2telco.dep.common.notification.url.retriever.Sequence>capp/EnterpriseServiceBus</com.wso2telco.dep.common.sequence_._com.wso2telco.dep.common.notification.url.retriever.Sequence>
<com.wso2telco.dep.common.template_._com.wso2telco.dep.common.mandatoryParameterValueValidation.Template>capp/EnterpriseServiceBus</com.wso2telco.dep.common.template_._com.wso2telco.dep.common.mandatoryParameterValueValidation.Template>
Expand Down Expand Up @@ -251,6 +252,12 @@
<version>2.1.4-SNAPSHOT</version>
<type>xml</type>
</dependency>
<dependency>
<groupId>com.wso2telco.dep.common.template</groupId>
<artifactId>com.wso2telco.dep.common.anonymizeUserData.Template</artifactId>
<version>2.1.4-SNAPSHOT</version>
<type>xml</type>
</dependency>
<dependency>
<groupId>com.wso2telco.dep.common.sequence</groupId>
<artifactId>com.wso2telco.dep.common.main.response.Sequence</artifactId>
Expand Down
15 changes: 14 additions & 1 deletion com.wso2telco.dep.common.mediation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
<groupId>org.apache.axis2.wso2</groupId>
<artifactId>axis2</artifactId>
</dependency>
<dependency>
<groupId>com.wso2telco.dep</groupId>
<artifactId>user-masking</artifactId>
<version>2.4.4</version>
</dependency>
</dependencies>
<repositories>
<repository>
Expand Down Expand Up @@ -202,6 +207,14 @@
</projectnatures>
</configuration>
</plugin>
</plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wso2telco.dep.common.mediation;

import com.wso2telco.dep.common.mediation.service.APIService;
import com.wso2telco.dep.common.mediation.util.MSISDNConstants;
import org.apache.synapse.MessageContext;
import org.apache.synapse.SynapseConstants;
import org.apache.synapse.mediators.AbstractMediator;
Expand All @@ -25,9 +26,15 @@ public boolean mediate(MessageContext messageContext) {

String msisdn = (String) messageContext.getProperty("paramValue");
String paramArray = (String) messageContext.getProperty("paramArray");
String maskedMsidsn = (String) messageContext.getProperty("MASKED_MSISDN");
String maskedMsisdnSuffix = (String) messageContext.getProperty("MASKED_MSISDN_SUFFIX");
String maskedMsidsnArray = (String) messageContext.getProperty("MASKED_MSISDN_LIST");
String apiName = (String) messageContext.getProperty("API_NAME");
String apiVersion = (String) messageContext.getProperty("VERSION");
String apiPublisher = (String) messageContext.getProperty("API_PUBLISHER");
String secretKey = (String)messageContext.getProperty(MSISDNConstants.USER_MASKING_SECRET_KEY);

String loggingMsisdn = msisdn;

String apiID;
APIService apiService = new APIService();
Expand All @@ -43,25 +50,25 @@ public boolean mediate(MessageContext messageContext) {
formattedPhoneNumber = matcher.group(Integer.parseInt(regexGroupNumber));
}

if(Boolean.parseBoolean((String)messageContext.getProperty("USER_ANONYMIZATION"))) {
loggingMsisdn = maskedMsidsn;
formattedPhoneNumber = maskedMsisdnSuffix;
}

try {
apiID = apiService.getAPIId(apiPublisher, apiName, apiVersion);
if (apiService.isBlackListedNumber(apiID, formattedPhoneNumber)) {
log.info(msisdn + " is BlackListed number for " + apiName + " API" + apiVersion + " version");
if (apiService.isBlackListedNumber(apiID, formattedPhoneNumber, secretKey)) {
log.info(loggingMsisdn + " is BlackListed number for " + apiName + " API" + apiVersion + " version");
messageContext.setProperty(SynapseConstants.ERROR_CODE, "POL0001:");
messageContext.setProperty(SynapseConstants.ERROR_MESSAGE, "Internal Server Error. Blacklisted " +
"Number");
messageContext.setProperty("BLACKLISTED_MSISDN", "true");

String errorVariable = msisdn;

if(paramArray != null){
errorVariable = paramArray;
}
setErrorInContext(
messageContext,
"SVC0004",
" blacklisted number. %1",
errorVariable,
msisdn,
"400", "POLICY_EXCEPTION");
} else {
messageContext.setProperty("BLACKLISTED_MSISDN", "false");
Expand All @@ -71,10 +78,13 @@ public boolean mediate(MessageContext messageContext) {
log.error("error in MSISDNBlacklistMediator mediate : "
+ e.getMessage());

String errorVariable = msisdn;
String errorVariable = loggingMsisdn;

if(paramArray != null){
errorVariable = paramArray;
if(Boolean.valueOf((String)messageContext.getProperty("USER_ANONYMIZATION")).booleanValue()) {
errorVariable = maskedMsidsnArray;
}
}
setErrorInContext(
messageContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ public boolean mediate(MessageContext messageContext) {

String msisdn = (String) messageContext.getProperty("paramValue");
String paramArray = (String) messageContext.getProperty("paramArray");
String maskedMsidsn = (String) messageContext.getProperty("MASKED_MSISDN");
String maskedMsisdnSuffix = (String) messageContext.getProperty("MASKED_MSISDN_SUFFIX");
String maskedMsidsnArray = (String) messageContext.getProperty("MASKED_MSISDN_LIST");
String apiName = (String) messageContext.getProperty("API_NAME");
String apiVersion = (String) messageContext.getProperty("VERSION");
String apiPublisher = (String) messageContext.getProperty("API_PUBLISHER");
String appID = messageContext.getProperty("api.ut.application.id").toString();
String regexPattern = (String) messageContext.getProperty("msisdnRegex");
String regexGroupNumber = (String) messageContext.getProperty("msisdnRegexGroup");

String loggingMsisdn = msisdn;

Pattern pattern = Pattern.compile(regexPattern);
Matcher matcher = pattern.matcher(msisdn);

Expand All @@ -29,6 +34,11 @@ public boolean mediate(MessageContext messageContext) {
formattedPhoneNumber = matcher.group(Integer.parseInt(regexGroupNumber));
}

if(Boolean.parseBoolean((String)messageContext.getProperty("USER_ANONYMIZATION"))) {
loggingMsisdn = maskedMsidsn;
formattedPhoneNumber = maskedMsisdnSuffix;
}

try {
APIService apiService = new APIService();
String apiID = apiService.getAPIId(apiPublisher, apiName, apiVersion);
Expand All @@ -46,16 +56,11 @@ public boolean mediate(MessageContext messageContext) {
" Number");
messageContext.setProperty("WHITELISTED_MSISDN", "false");

String errorVariable = msisdn;

if(paramArray != null){
errorVariable = paramArray;
}
setErrorInContext(
messageContext,
"SVC0004",
" Not a whitelisted number. %1",
errorVariable,
msisdn,
"400", "POLICY_EXCEPTION");
}

Expand All @@ -64,10 +69,13 @@ public boolean mediate(MessageContext messageContext) {
log.error("error in MSISDNWhitelistMediator mediate : "
+ e.getMessage());

String errorVariable = msisdn;
String errorVariable = loggingMsisdn;

if(paramArray != null){
errorVariable = paramArray;
if(Boolean.valueOf((String)messageContext.getProperty("USER_ANONYMIZATION")).booleanValue()) {
errorVariable = maskedMsidsnArray;
}
}
setErrorInContext(
messageContext,
Expand Down
Loading