Search in sources :

Example 1 with LogMediator

use of org.apache.synapse.mediators.builtin.LogMediator in project wso2-synapse by wso2.

the class TransactionMediatorSerializationTest method testCreatingMediatorWithInvalidInstance.

/**
 * Test for transaction mediator serialization with an invalid mediator instance
 *
 * @throws Exception
 */
public void testCreatingMediatorWithInvalidInstance() throws Exception {
    try {
        LogMediator logMediator = new LogMediator();
        transactionMediatorSerializer.serializeSpecificMediator(logMediator);
        fail("Test for transaction mediator serialization with an invalid mediator instance fails.");
    } catch (SynapseException e) {
        assertEquals("Unsupported mediator passed in for serialization : LogMediator", e.getMessage());
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) LogMediator(org.apache.synapse.mediators.builtin.LogMediator)

Example 2 with LogMediator

use of org.apache.synapse.mediators.builtin.LogMediator in project wso2-synapse by wso2.

the class LogMediatorFactory method createSpecificMediator.

public Mediator createSpecificMediator(OMElement elem, Properties properties) {
    LogMediator logMediator = new LogMediator();
    // after successfully creating the mediator
    // set its common attributes such as tracing etc
    processAuditStatus(logMediator, elem);
    // Set the high level set of properties to be logged (i.e. log level)
    OMAttribute level = elem.getAttribute(ATT_LEVEL);
    if (level != null) {
        String levelstr = level.getAttributeValue();
        if (SIMPLE.equals(levelstr)) {
            logMediator.setLogLevel(LogMediator.SIMPLE);
        } else if (HEADERS.equals(levelstr)) {
            logMediator.setLogLevel(LogMediator.HEADERS);
        } else if (FULL.equals(levelstr)) {
            logMediator.setLogLevel(LogMediator.FULL);
        } else if (CUSTOM.equals(levelstr)) {
            logMediator.setLogLevel(LogMediator.CUSTOM);
        }
    }
    // Set the log statement category (i.e. INFO, DEBUG, etc..)
    OMAttribute category = elem.getAttribute(ATT_CATEGORY);
    if (category != null) {
        String catstr = category.getAttributeValue().trim().toUpperCase();
        if (CAT_INFO.equals(catstr)) {
            logMediator.setCategory(LogMediator.CATEGORY_INFO);
        } else if (CAT_TRACE.equals(catstr)) {
            logMediator.setCategory(LogMediator.CATEGORY_TRACE);
        } else if (CAT_DEBUG.equals(catstr)) {
            logMediator.setCategory(LogMediator.CATEGORY_DEBUG);
        } else if (CAT_WARN.equals(catstr)) {
            logMediator.setCategory(LogMediator.CATEGORY_WARN);
        } else if (CAT_ERROR.equals(catstr)) {
            logMediator.setCategory(LogMediator.CATEGORY_ERROR);
        } else if (CAT_FATAL.equals(catstr)) {
            logMediator.setCategory(LogMediator.CATEGORY_FATAL);
        } else {
            handleException("Invalid log category. Category has to be one of " + "the following : INFO, TRACE, DEBUG, WARN, ERROR, FATAL");
        }
    }
    // check if a custom separator has been supplied, if so use it
    OMAttribute separator = elem.getAttribute(ATT_SEPERATOR);
    if (separator != null) {
        logMediator.setSeparator(separator.getAttributeValue());
    }
    logMediator.addAllProperties(MediatorPropertyFactory.getMediatorProperties(elem));
    return logMediator;
}
Also used : LogMediator(org.apache.synapse.mediators.builtin.LogMediator) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 3 with LogMediator

use of org.apache.synapse.mediators.builtin.LogMediator in project wso2-synapse by wso2.

the class SynapseConfigUtils method setDefaultFaultSequence.

/**
 * Return the fault sequence if one is not defined. This implementation defaults to
 * a simple sequence :
 * <log level="full">
 *   <property name="MESSAGE" value="Executing default "fault" sequence"/>
 *   <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
 *   <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
 * </log>
 * <drop/>
 *
 * @param config the configuration to be updated
 */
public static void setDefaultFaultSequence(SynapseConfiguration config) {
    SequenceMediator fault = new SequenceMediator();
    fault.setName(org.apache.synapse.SynapseConstants.FAULT_SEQUENCE_KEY);
    LogMediator log = new LogMediator();
    log.setLogLevel(LogMediator.FULL);
    MediatorProperty mp = new MediatorProperty();
    mp.setName("MESSAGE");
    mp.setValue("Executing default \"fault\" sequence");
    log.addProperty(mp);
    mp = new MediatorProperty();
    mp.setName("ERROR_CODE");
    try {
        mp.setExpression(new SynapseXPath("get-property('ERROR_CODE')"));
    } catch (JaxenException ignore) {
    }
    log.addProperty(mp);
    mp = new MediatorProperty();
    mp.setName("ERROR_MESSAGE");
    try {
        mp.setExpression(new SynapseXPath("get-property('ERROR_MESSAGE')"));
    } catch (JaxenException ignore) {
    }
    log.addProperty(mp);
    fault.addChild(log);
    fault.addChild(new DropMediator());
    // set aspect configuration
    AspectConfiguration configuration = new AspectConfiguration(fault.getName());
    fault.configure(configuration);
    config.addSequence(org.apache.synapse.SynapseConstants.FAULT_SEQUENCE_KEY, fault);
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) MediatorProperty(org.apache.synapse.mediators.MediatorProperty) JaxenException(org.jaxen.JaxenException) LogMediator(org.apache.synapse.mediators.builtin.LogMediator) DropMediator(org.apache.synapse.mediators.builtin.DropMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) AspectConfiguration(org.apache.synapse.aspects.AspectConfiguration)

Example 4 with LogMediator

use of org.apache.synapse.mediators.builtin.LogMediator in project wso2-synapse by wso2.

the class SynapseConfigurationBuilder method getDefaultConfiguration.

/**
 * Return the default Synapse Configuration
 * @return the default configuration to be used
 */
public static SynapseConfiguration getDefaultConfiguration() {
    // programatically create an empty configuration which just log and drop the messages
    SynapseConfiguration config = SynapseConfigUtils.newConfiguration();
    SequenceMediator mainMediator = new SequenceMediator();
    InMediator inMediator = new InMediator();
    inMediator.addChild(new LogMediator());
    mainMediator.addChild(inMediator);
    OutMediator outMediator = new OutMediator();
    outMediator.addChild(new SendMediator());
    mainMediator.addChild(outMediator);
    mainMediator.setName(SynapseConstants.MAIN_SEQUENCE_KEY);
    config.addSequence(SynapseConstants.MAIN_SEQUENCE_KEY, mainMediator);
    SequenceMediator faultMediator = new SequenceMediator();
    LogMediator fault = new LogMediator();
    fault.setLogLevel(LogMediator.FULL);
    faultMediator.addChild(fault);
    faultMediator.setName(SynapseConstants.FAULT_SEQUENCE_KEY);
    config.addSequence(SynapseConstants.FAULT_SEQUENCE_KEY, faultMediator);
    config.setDescription("The default configuration of the ESB, that is created " + "programatically at the startup");
    return config;
}
Also used : OutMediator(org.apache.synapse.mediators.filters.OutMediator) LogMediator(org.apache.synapse.mediators.builtin.LogMediator) InMediator(org.apache.synapse.mediators.filters.InMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SendMediator(org.apache.synapse.mediators.builtin.SendMediator)

Example 5 with LogMediator

use of org.apache.synapse.mediators.builtin.LogMediator in project wso2-synapse by wso2.

the class LogMediatorSerializer method serializeSpecificMediator.

public OMElement serializeSpecificMediator(Mediator m) {
    if (!(m instanceof LogMediator)) {
        handleException("Unsupported mediator passed in for serialization : " + m.getType());
    }
    LogMediator mediator = (LogMediator) m;
    OMElement log = fac.createOMElement("log", synNS);
    saveTracingState(log, mediator);
    if (mediator.getLogLevel() != LogMediator.SIMPLE) {
        log.addAttribute(fac.createOMAttribute("level", nullNS, mediator.getLogLevel() == LogMediator.HEADERS ? "headers" : mediator.getLogLevel() == LogMediator.FULL ? "full" : mediator.getLogLevel() == LogMediator.CUSTOM ? "custom" : "simple"));
    }
    if (mediator.getCategory() != LogMediator.CATEGORY_INFO) {
        log.addAttribute(fac.createOMAttribute("category", nullNS, mediator.getCategory() == LogMediator.CATEGORY_TRACE ? LogMediatorFactory.CAT_TRACE : mediator.getCategory() == LogMediator.CATEGORY_DEBUG ? LogMediatorFactory.CAT_DEBUG : mediator.getCategory() == LogMediator.CATEGORY_WARN ? LogMediatorFactory.CAT_WARN : mediator.getCategory() == LogMediator.CATEGORY_ERROR ? LogMediatorFactory.CAT_ERROR : mediator.getCategory() == LogMediator.CATEGORY_FATAL ? LogMediatorFactory.CAT_FATAL : LogMediatorFactory.CAT_INFO));
    }
    if (!LogMediator.DEFAULT_SEP.equals(mediator.getSeparator())) {
        log.addAttribute(fac.createOMAttribute("separator", nullNS, mediator.getSeparator()));
    }
    super.serializeProperties(log, mediator.getProperties());
    return log;
}
Also used : LogMediator(org.apache.synapse.mediators.builtin.LogMediator) OMElement(org.apache.axiom.om.OMElement)

Aggregations

LogMediator (org.apache.synapse.mediators.builtin.LogMediator)6 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)3 AspectConfiguration (org.apache.synapse.aspects.AspectConfiguration)2 DropMediator (org.apache.synapse.mediators.builtin.DropMediator)2 OMAttribute (org.apache.axiom.om.OMAttribute)1 OMElement (org.apache.axiom.om.OMElement)1 SynapseException (org.apache.synapse.SynapseException)1 MediatorProperty (org.apache.synapse.mediators.MediatorProperty)1 SendMediator (org.apache.synapse.mediators.builtin.SendMediator)1 InMediator (org.apache.synapse.mediators.filters.InMediator)1 OutMediator (org.apache.synapse.mediators.filters.OutMediator)1 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)1 JaxenException (org.jaxen.JaxenException)1