Skip to content

Commit

Permalink
Update log mediator serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
SanojPunchihewa committed Dec 3, 2024
1 parent 20fdee8 commit 5395da5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,25 @@ public OMElement serializeSpecificMediator(Mediator m) {
OMElement log = fac.createOMElement("log", synNS);
saveTracingState(log,mediator);

if (mediator.getLogLevel() != LogMediator.MESSAGE_TEMPLATE) {
log.addAttribute(fac.createOMAttribute(
"level", nullNS,
mediator.getLogLevel() == LogMediator.HEADERS ? "headers" :
mediator.getLogLevel() == LogMediator.FULL ? "full" :
mediator.getLogLevel() == LogMediator.CUSTOM ? "custom" : "simple"
));
String logLevel = "";
switch (mediator.getLogLevel()) {
case LogMediator.CUSTOM:
logLevel = "custom";
break;
case LogMediator.HEADERS:
logLevel = "headers";
break;
case LogMediator.FULL:
logLevel = "full";
break;
case LogMediator.MESSAGE_TEMPLATE:
OMElement messageElement = fac.createOMElement("message", synNS);
messageElement.setText(mediator.getMessageTemplate());
log.addChild(messageElement);
break;
}
if (StringUtils.isNotBlank(logLevel)) {
log.addAttribute(fac.createOMAttribute("level", nullNS, logLevel));
}

if (mediator.getCategory() != LogMediator.CATEGORY_INFO) {
Expand All @@ -75,12 +87,6 @@ public OMElement serializeSpecificMediator(Mediator m) {
"separator", nullNS, mediator.getSeparator()));
}

if (StringUtils.isNotBlank(mediator.getMessageTemplate())) {
OMElement onCompleteElem = fac.createOMElement("message", synNS);
onCompleteElem.setText(mediator.getMessageTemplate());
log.addChild(onCompleteElem);
}

super.serializeProperties(log, mediator.getProperties());

serializeComments(log, mediator.getCommentsList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void testLogMediatorSerializationWithTemplate() throws Exception {

assertTrue(serialization(getXmlOfLogMediatorWithTemplate(), logMediatorFactory, logMediatorSerializer));
assertTrue(serialization(getXmlOfLogMediatorWithTemplateAndProps(), logMediatorFactory, logMediatorSerializer));
assertTrue(serialization(getXmlOfLogMediatorWithEmptyTemplateAndProps(), logMediatorFactory, logMediatorSerializer));
}

public void testLogMediatorSerializationSenarioOne() throws Exception {
Expand Down Expand Up @@ -147,6 +148,12 @@ private String getXmlOfLogMediatorWithTemplateAndProps() {
"<property name=\"Text\" value=\"Sending quote request\"/></log>";
}

private String getXmlOfLogMediatorWithEmptyTemplateAndProps() {
return "<log xmlns=\"http://ws.apache.org/ns/synapse\">" +
"<message></message>" +
"<property name=\"Text\" value=\"Sending quote request\"/></log>";
}

private String getXmlOfMediatorScenarioOneA(String level) {
return "<log level=\"" +
level + "\"><property name=\"Text\" value=\"Sending quote request\"/></log>";
Expand All @@ -161,7 +168,7 @@ private String getXmlOfMediatorScenarioTwo(String level, String seperator) {
}

private String getXmlOfMediatorScenarioThree(String category) {
return "<log xmlns=\"http://ws.apache.org/ns/synapse\" level=\"simple\" category=\"" +
return "<log xmlns=\"http://ws.apache.org/ns/synapse\" category=\"" +
category + "\"><property name=\"Text\" value=\"Sending quote request\"/></log>";

}
Expand Down

0 comments on commit 5395da5

Please sign in to comment.