Search in sources :

Example 1 with MessageStoreMediator

use of org.apache.synapse.mediators.store.MessageStoreMediator in project wso2-synapse by wso2.

the class MessageStoreMediatorSerializer method serializeSpecificMediator.

@Override
protected OMElement serializeSpecificMediator(Mediator m) {
    if (!(m instanceof MessageStoreMediator)) {
        handleException("Unsupported mediator passed in for serialization : " + m.getType());
    }
    MessageStoreMediator messageStoreMediator = (MessageStoreMediator) m;
    SynapsePath messageStoreExp = messageStoreMediator.getMessageStoreExp();
    String messageStoreName = messageStoreMediator.getMessageStoreName();
    OMElement storeElem = fac.createOMElement("store", synNS);
    String name = messageStoreMediator.getName();
    if (name != null) {
        OMAttribute nameAtt = fac.createOMAttribute("name", nullNS, name);
        storeElem.addAttribute(nameAtt);
    }
    // But we do a null check here since in run time there can be manual modifications
    if (messageStoreExp != null) {
        SynapsePathSerializer.serializePathWithBraces(messageStoreExp, storeElem, "messageStore");
    } else if (messageStoreName != null) {
        OMAttribute msName = fac.createOMAttribute(ATT_MESSAGE_STORE, nullNS, messageStoreName);
        storeElem.addAttribute(msName);
    } else {
        handleException("Can't serialize MessageStore Mediator message store is null ");
    }
    String sequence = messageStoreMediator.getOnStoreSequence();
    // sequence is an optional parameter
    if (sequence != null) {
        OMAttribute sequenceAtt = fac.createOMAttribute(ATT_SEQUENCE, nullNS, sequence);
        storeElem.addAttribute(sequenceAtt);
    }
    return storeElem;
}
Also used : MessageStoreMediator(org.apache.synapse.mediators.store.MessageStoreMediator) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 2 with MessageStoreMediator

use of org.apache.synapse.mediators.store.MessageStoreMediator in project wso2-synapse by wso2.

the class MessageStoreMediatorFactory method createSpecificMediator.

@Override
protected Mediator createSpecificMediator(OMElement elem, Properties properties) {
    MessageStoreMediator messageStoreMediator = new MessageStoreMediator();
    processAuditStatus(messageStoreMediator, elem);
    OMAttribute nameAtt = elem.getAttribute(ATT_NAME);
    if (nameAtt != null) {
        messageStoreMediator.setName(nameAtt.getAttributeValue());
    }
    OMAttribute messageStoreNameAtt = elem.getAttribute(ATT_MESSAGE_STORE);
    if (messageStoreNameAtt != null) {
        if (checkForExpression(messageStoreNameAtt)) {
            String path = messageStoreNameAtt.getAttributeValue().substring(1, messageStoreNameAtt.getAttributeValue().length() - 1);
            try {
                messageStoreMediator.setMessageStoreExp(SynapsePathFactory.getSynapsePath(elem, path));
            } catch (JaxenException e) {
                String msg = "Invalid XPath expression for attribute 'messageStore' : " + messageStoreNameAtt.getAttributeValue();
                throw new SynapseException(msg, e);
            }
        } else {
            messageStoreMediator.setMessageStoreName(messageStoreNameAtt.getAttributeValue());
        }
    } else {
        throw new SynapseException("Message Store mediator must have a Message store defined");
    }
    OMAttribute sequenceAtt = elem.getAttribute(ATT_SEQUENCE);
    if (sequenceAtt != null) {
        messageStoreMediator.setOnStoreSequence(sequenceAtt.getAttributeValue());
    }
    return messageStoreMediator;
}
Also used : MessageStoreMediator(org.apache.synapse.mediators.store.MessageStoreMediator) SynapseException(org.apache.synapse.SynapseException) JaxenException(org.jaxen.JaxenException) OMAttribute(org.apache.axiom.om.OMAttribute)

Aggregations

OMAttribute (org.apache.axiom.om.OMAttribute)2 MessageStoreMediator (org.apache.synapse.mediators.store.MessageStoreMediator)2 OMElement (org.apache.axiom.om.OMElement)1 SynapseException (org.apache.synapse.SynapseException)1 JaxenException (org.jaxen.JaxenException)1