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

Update log mediator serializer #2249

Merged
merged 1 commit into from
Dec 3, 2024
Merged
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
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
Loading