Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
SanojPunchihewa committed Nov 22, 2024
1 parent 9b66249 commit 082f1bf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ public Mediator createSpecificMediator(OMElement elem, Properties properties) {
// set its common attributes such as tracing etc
processAuditStatus(logMediator,elem);

boolean containMessageTemplate = false;
OMElement messageElement = elem.getFirstChildWithName(ELEMENT_MESSAGE_Q);
if (messageElement != null && messageElement.getText() != null) {
logMediator.setMessageTemplate(messageElement.getText());
logMediator.setLogLevel(LogMediator.MESSAGE_TEMPLATE);
containMessageTemplate = true;
}

// Set the high level set of properties to be logged (i.e. log level)
Expand All @@ -90,6 +91,10 @@ public Mediator createSpecificMediator(OMElement elem, Properties properties) {
handleException("Invalid log level. Level has to be one of the following : "
+ "simple, headers, full, custom");
}
} else {
if (containMessageTemplate) {
logMediator.setLogLevel(LogMediator.MESSAGE_TEMPLATE);
}
}

// Set the log statement category (i.e. INFO, DEBUG, etc..)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public OMElement serializeSpecificMediator(Mediator m) {
OMElement log = fac.createOMElement("log", synNS);
saveTracingState(log,mediator);

if (StringUtils.isBlank(mediator.getMessageTemplate()) && mediator.getLogLevel() != LogMediator.SIMPLE) {
if (mediator.getLogLevel() != LogMediator.MESSAGE_TEMPLATE) {
log.addAttribute(fac.createOMAttribute(
"level", nullNS,
mediator.getLogLevel() == LogMediator.HEADERS ? "headers" :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class LogMediator extends AbstractMediator {
/** The holder for the custom properties */
private final List<MediatorProperty> properties = new ArrayList<MediatorProperty>();

private String messageTemplate;
private String messageTemplate = "";

/**
* Logs the current message according to the supplied semantics
Expand Down Expand Up @@ -142,28 +142,33 @@ public boolean mediate(MessageContext synCtx) {
private String getLogMessage(MessageContext synCtx) {
switch (logLevel) {
case CUSTOM:
case MESSAGE_TEMPLATE:
return getCustomLogMessage(synCtx);
case SIMPLE:
return getSimpleLogMessage(synCtx);
case HEADERS:
return getHeadersLogMessage(synCtx);
case FULL:
return getFullLogMessage(synCtx);
case MESSAGE_TEMPLATE:
return processMessageTemplate(synCtx, messageTemplate);
default:
return "Invalid log level specified";
}
}

private String getCustomLogMessage(MessageContext synCtx) {
StringBuffer sb = new StringBuffer();
processMessageTemplate(sb, synCtx, messageTemplate);
setCustomProperties(sb, synCtx);
return trimLeadingSeparator(sb);
}

private String getSimpleLogMessage(MessageContext synCtx) {
StringBuffer sb = new StringBuffer();
processMessageTemplate(sb, synCtx, messageTemplate);
// append separator if the message template is not empty
if (sb.length() > 0) {
sb.append(separator);
}
if (synCtx.getTo() != null)
sb.append("To: ").append(synCtx.getTo().getAddress());
else
Expand All @@ -188,6 +193,7 @@ private String getSimpleLogMessage(MessageContext synCtx) {

private String getHeadersLogMessage(MessageContext synCtx) {
StringBuffer sb = new StringBuffer();
processMessageTemplate(sb, synCtx, messageTemplate);
if (synCtx.getEnvelope() != null) {
SOAPHeader header = synCtx.getEnvelope().getHeader();
if (getCorrelationId(synCtx) != null)
Expand Down Expand Up @@ -303,7 +309,7 @@ public String getMessageTemplate() {

public void setMessageTemplate(String messageTemplate) {

this.messageTemplate = messageTemplate;
this.messageTemplate = messageTemplate.replace("\\n", "\n").replace("\\t", "\t");
}

private String trimLeadingSeparator(StringBuffer sb) {
Expand All @@ -315,35 +321,24 @@ private String trimLeadingSeparator(StringBuffer sb) {
}
}

private String processMessageTemplate(MessageContext synCtx, String template) {
StringBuffer result = new StringBuffer();
private void processMessageTemplate(StringBuffer stringBuffer, MessageContext synCtx, String template) {
try {
result.append(InlineExpressionUtil.processInLineSynapseExpressionTemplate(synCtx, template));
stringBuffer.append(InlineExpressionUtil.processInLineSynapseExpressionTemplate(synCtx, template));
} catch (JaxenException e) {
handleException("Failed to process the message template : " + template, e, synCtx);
}
setCustomProperties(result, synCtx);
return result.toString();
}

@Override
public boolean isContentAware() {
if (logLevel == MESSAGE_TEMPLATE) {
if (logLevel == MESSAGE_TEMPLATE || logLevel == CUSTOM) {
for (MediatorProperty property : properties) {
if (property.getExpression() != null && property.getExpression().isContentAware()) {
return true;
}
}
return InlineExpressionUtil.isInlineSynapseExpressionsContentAware(messageTemplate);
}
if (logLevel == CUSTOM) {
for (MediatorProperty property : properties) {
if (property.getExpression() != null && property.getExpression().isContentAware()) {
return true;
}
}
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private String getXmlOfMediatorScenarioTwo(String level, String seperator) {
}

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

}
Expand Down

0 comments on commit 082f1bf

Please sign in to comment.