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

Perf improve mediator2.1.5 #178

Open
wants to merge 6 commits into
base: perf_improve_mediator2.1.5
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
18 changes: 0 additions & 18 deletions .project

This file was deleted.

23 changes: 0 additions & 23 deletions com.wso2telco.dep.common.mediation/.project

This file was deleted.

8 changes: 8 additions & 0 deletions com.wso2telco.dep.common.mediation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@
</projectnatures>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package com.wso2telco.dep.common.mediation;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
import org.apache.synapse.MessageContext;
import org.apache.synapse.commons.json.JsonUtil;
import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.apache.synapse.mediators.AbstractMediator;
import org.json.JSONObject;

import com.wso2telco.dep.common.mediation.constant.Constant;

public class UtilMediator extends AbstractMediator {

public boolean mediate(MessageContext synCtx) {

try {

org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx)
.getAxis2MessageContext();
JSONObject jsonPayload = new JSONObject(JsonUtil.jsonPayloadToString(axis2MessageContext));

switch (propertyValue) {

case Constant.propertyValues.CORRELATORCHANGE:

JSONObject objClientCorrelator = getSubPayloadObject(propertyPath, jsonPayload,
Constant.JsonObject.CLIENTCORRELATOR);
objClientCorrelator.remove(Constant.JsonObject.CLIENTCORRELATOR);
objClientCorrelator.put(Constant.JsonObject.CLIENTCORRELATOR, synCtx.getProperty(msgContextProperty));

JsonUtil.getNewJsonPayload(axis2MessageContext, jsonPayload.toString(), true, true);
break;

case Constant.propertyValues.RESOURCEURLCHANGE:

String smsRetrieveResourceUrlPrefix = (String) synCtx
.getProperty(Constant.messageContext.SEND_SMS_RESOURCE_URL_PREFIX);
String requestId = (String) synCtx.getProperty(Constant.messageContext.REQUEST_ID);
String request = "/request/";
String smsRetrieveResourceUrl = (smsRetrieveResourceUrlPrefix + request + requestId);
String responseDeliveryInfoResourceUrl = (String) synCtx
.getProperty(Constant.messageContext.RESPONSE_DELIVERY_INFO_RESOURCE_URL);
String operatorRequestId = null;

JSONObject jsonObject1 = (JSONObject) jsonPayload.get(Constant.JsonObject.OUTBOUNDSMSMESSAGEREQUEST);
JSONObject jsonObject2 = (JSONObject) jsonObject1.get(Constant.JsonObject.DELIVERYINFOLIST);

String responseResourceUrl = (String) jsonObject1.get(Constant.JsonObject.RESOURCEURL);
operatorRequestId = responseResourceUrl.substring(responseResourceUrl.lastIndexOf('/') + 1);

jsonObject1.remove(Constant.JsonObject.RESOURCEURL);
jsonObject1.put(Constant.JsonObject.RESOURCEURL, smsRetrieveResourceUrl);

jsonObject2.remove(Constant.JsonObject.RESOURCEURL);
jsonObject2.put(Constant.JsonObject.RESOURCEURL, responseDeliveryInfoResourceUrl);

synCtx.setProperty(Constant.messageContext.SEND_SMS_OPERATOR_REQUEST_ID, operatorRequestId);
JsonUtil.getNewJsonPayload(axis2MessageContext, jsonPayload.toString(), true, true);
break;

case Constant.propertyValues.APIVERSIONCHANGE:

String apiVersion = (String) synCtx.getProperty(Constant.messageContext.API_VERSION);
String generatedApiVersion = apiVersion.replace(':', '_');

synCtx.setProperty(Constant.messageContext.GENERATED_API_ID, generatedApiVersion);
break;

case Constant.propertyValues.MSISDNCHANGE:

String paramValue = (String) synCtx.getProperty(Constant.messageContext.PARAMVALUE);
String regexp = (String) synCtx.getProperty(Constant.messageContext.MSISDNREGEX);
boolean isValidMsisdn = isValidMsisdn(paramValue,regexp);

synCtx.setProperty(Constant.messageContext.ISVALIDMSISDN, isValidMsisdn);
break;

case Constant.propertyValues.PARTIALREQUESTIDCHANGE:

String requestID = (String) synCtx.getProperty(Constant.messageContext.REQUEST_ID);
String splittedParts [] = StringUtils.split(requestID,":");
String modifiedId = "";
if(splittedParts.length > 3) {

modifiedId = splittedParts[0] + ':' + splittedParts[1] + ':' + splittedParts[3];
}

synCtx.setProperty(Constant.messageContext.PARTIALREQUESTID, modifiedId);
break;

case Constant.propertyValues.NOTIFYURLCHANGE:
JSONObject objNotifyUrl = getSubPayloadObject(propertyPath, jsonPayload, Constant.JsonObject.NOTIFYURL);

// TODO need to build logic to get notify url

objNotifyUrl.remove(Constant.JsonObject.NOTIFYURL);
objNotifyUrl.put(Constant.JsonObject.NOTIFYURL, synCtx.getProperty(msgContextProperty));
JsonUtil.getNewJsonPayload(axis2MessageContext, jsonPayload.toString(), true, true);
break;
default:
JsonUtil.getNewJsonPayload(axis2MessageContext, jsonPayload.toString(), true, true);
}

} catch (Exception ex) {
ex.printStackTrace();
}
return true;
}

private JSONObject getSubPayloadObject(String path, JSONObject jsonPayload, String subObjPath) {
JSONObject objClientCorrelator = jsonPayload;
try {
List<String> arrSubPath = Arrays.asList(path.split("\\."));
Iterator<String> iterator = arrSubPath.iterator();
iterator.next();
while (iterator.hasNext()) {
String subPath = iterator.next();
if (subPath.equals(subObjPath)) {
break;
} else {
objClientCorrelator = objClientCorrelator.getJSONObject(subPath);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return objClientCorrelator;
}

public boolean isValidMsisdn(String paramValue, String regexp) {

Pattern pattern;
Matcher matcher;

pattern = Pattern.compile(regexp);
matcher = pattern.matcher(paramValue);

boolean isValidMsisdn = matcher.matches();

return isValidMsisdn;
}

private String propertyPath;
private String propertyValue;
private String msgContextProperty;

public String getPropertyPath() {
return propertyPath;
}

public void setPropertyPath(String propertyPath) {
this.propertyPath = propertyPath;
}

public String getPropertyValue() {
return propertyValue;
}

public void setPropertyValue(String propertyValue) {
this.propertyValue = propertyValue;
}

public String getMsgContextProperty() {
return msgContextProperty;
}

public void setMsgContextProperty(String msgContextProperty) {
this.msgContextProperty = msgContextProperty;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.wso2telco.dep.common.mediation.constant;


public interface Constant {

public interface JsonObject{

public static final String OUTBOUNDSMSMESSAGEREQUEST = "outboundSMSMessageRequest";
public static final String DELIVERYINFOLIST = "deliveryInfoList";
public static final String RESOURCEURL = "resourceURL";
public static final String CLIENTCORRELATOR = "clientCorrelator";
public static final String NOTIFYURL = "notifyURL";
}

public interface messageContext{
public static final String SEND_SMS_RESOURCE_URL_PREFIX = "SEND_SMS_RESOURCE_URL_PREFIX";
public static final String RESPONSE_DELIVERY_INFO_RESOURCE_URL = "RESPONSE_DELIVERY_INFO_RESOURCE_URL";
public static final String SEND_SMS_OPERATOR_REQUEST_ID = "SEND_SMS_OPERATOR_REQUEST_ID";
public static final String REQUEST_ID = "REQUEST_ID";
public static final String API_VERSION = "API_VERSION";
public static final String GENERATED_API_ID = "GENERATED_API_ID";
public static final String PARAMVALUE = "paramValue";
public static final String MSISDNREGEX = "msisdnRegex";
public static final String PARTIALREQUESTID ="PARTIAL_REQUEST_ID";
public static final String ISVALIDMSISDN = "isValidMsisdn";
}

public interface propertyValues{
public static final String CORRELATORCHANGE = "correlatorChange";
public static final String RESOURCEURLCHANGE = "resourceURLChange";
public static final String NOTIFYURLCHANGE = "notifyURLChange";
public static final String APIVERSIONCHANGE = "generatedApiVersionChange";
public static final String MSISDNCHANGE = "isValidMsisdn";
public static final String PARTIALREQUESTIDCHANGE = "partialRequestId";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<property expression="get-property('REQUEST_ID')" name="uniqueClientCorrelator" scope="default" type="STRING"/>
</then>
<else>
<class name="org.wso2telco.dep.nashornmediator.NashornMediator">

<!-- <class name="org.wso2telco.dep.nashornmediator.NashornMediator">
<property name="script" value="
var requestId = mc.getProperty('REQUEST_ID');
var splittedParts = requestId.split(':');
Expand All @@ -16,7 +17,11 @@
mc.setProperty('PARTIAL_REQUEST_ID', String(modifiedId));
}
"/>
</class>
</class> -->

<class name="com.wso2telco.dep.common.mediation.UtilMediator">
<property name="propertyValue" value="partialRequestId" />
</class>
<property expression="fn:concat($func:clientCorrelator , ':' , get-property('PARTIAL_REQUEST_ID'))" name="uniqueClientCorrelator" scope="default" type="STRING"/>
</else>
</filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@
<property value="Publishing Request Data" name="STATUS"/>
<property name="DIRECTION" expression="fn:concat($func:direction,' request')"/>
</log>
<!-- Generate API_ID from context and version -->
<class name="org.wso2telco.dep.nashornmediator.NashornMediator">

<!-- Generate API_ID from context and version -->
<!-- <class name="org.wso2telco.dep.nashornmediator.NashornMediator">
<property name="script" value="
var contextVersion = mc.getProperty('API_VERSION');
var generated_api_version = contextVersion.replace(':', '_');
mc.setProperty('GENERATED_API_ID', generated_api_version);
"/>
</class> -->


<class name="com.wso2telco.dep.common.mediation.UtilMediator">
<property name="propertyValue" value="generatedApiVersionChange" />
</class>

<property expression="$func:msisdn" name="msisdn"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@
<property name="STATUS" value="publishing response data"/>
<property name="DIRECTION" expression="fn:concat($func:direction,' response')"/>
</log>

<!-- Generate API_ID from context and version -->
<class name="org.wso2telco.dep.nashornmediator.NashornMediator">
<!-- <class name="org.wso2telco.dep.nashornmediator.NashornMediator">
<property name="script" value="
var contextVersion = mc.getProperty('API_VERSION');
var generated_api_version = contextVersion.replace(':', '_');
mc.setProperty('GENERATED_API_ID', generated_api_version);
"/>
</class> -->

<class name="com.wso2telco.dep.common.mediation.UtilMediator">
<property name="propertyValue" value="generatedApiVersionChange" />
</class>

<property expression="$func:msisdn" name="msisdn"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
<property expression="$ctx:mediationConfig//msisdn_regex_num_grp" name="msisdnRegexGroup" scope="default" type="STRING"/>
<property expression="$func:paramValue" name="paramValue" scope="default" type="STRING"/>
<property expression="$trp:APPLICATION_ID" name="api.ut.application.id" scope="default" type="STRING"/>


<class name="org.wso2telco.dep.nashornmediator.NashornMediator">

<!-- <class name="org.wso2telco.dep.nashornmediator.NashornMediator">
<property name="script" value="
var isValidMsisdn = false;
var paramValue = mc.getProperty('paramValue');
Expand All @@ -23,7 +22,11 @@
var isValidMsisdn = regExp.test(paramValue);
mc.setProperty('isValidMsisdn', isValidMsisdn);
"/>
</class>
</class> -->

<class name="com.wso2telco.dep.common.mediation.UtilMediator">
<property name="propertyValue" value="isValidMsisdn" />
</class>

<filter regex="^false$" source="$ctx:isValidMsisdn">
<then>
Expand Down