Search in sources :

Example 6 with MessageProcessor

use of org.apache.synapse.message.processor.MessageProcessor in project wso2-synapse by wso2.

the class MessageProcessorSerializerTest method testSerializeMessageProcessor.

/**
 * test serializeMessageProcessor with no Message store name.
 */
@Test(expected = SynapseException.class)
public void testSerializeMessageProcessor() {
    MessageProcessor messageProcessor = new SamplingProcessor();
    MessageProcessorSerializer.serializeMessageProcessor(null, messageProcessor);
}
Also used : MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) SamplingProcessor(org.apache.synapse.message.processor.impl.sampler.SamplingProcessor) Test(org.junit.Test)

Example 7 with MessageProcessor

use of org.apache.synapse.message.processor.MessageProcessor in project wso2-synapse by wso2.

the class MessageProcessorFactoryTest method testCreateMessageProcessor.

/**
 * Test CreateMessageProcessor with given XML configuration and asserting it is created.
 *
 * @throws XMLStreamException - XMLStreamException
 */
@Test
public void testCreateMessageProcessor() throws XMLStreamException {
    String inputXML = "<messageProcessor\n" + "        class=\"org.apache.synapse.message.processor.impl.forwarder." + "ScheduledMessageForwardingProcessor\"\n" + "        messageStore=\"MyStore\" name=\"ScheduledProcessor\" targetEndpoint=\"StockQuoteServiceEp\" " + "xmlns=\"http://ws.apache.org/ns/synapse\">\n" + "        <parameter name=\"interval\">10000</parameter>\n" + "        <parameter name=\"throttle\">false</parameter>\n" + "        <parameter name=\"target.endpoint\">StockQuoteServiceEp</parameter>\n" + "        <description>  test </description>" + "    </messageProcessor>";
    OMElement element = AXIOMUtil.stringToOM(inputXML);
    MessageProcessor messageProcessor = MessageProcessorFactory.createMessageProcessor(element);
    Assert.assertNotNull("MessageProcessor is not created", messageProcessor);
}
Also used : MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) OMElement(org.apache.axiom.om.OMElement) Test(org.junit.Test)

Example 8 with MessageProcessor

use of org.apache.synapse.message.processor.MessageProcessor in project wso2-synapse by wso2.

the class MultiXMLConfigurationSerializer method serializeSynapseXML.

/**
 * Serialize only the elements defined in the top level synapse.xml file back to the
 * synapse.xml file. This method ignores the elements defined in files other than the
 * synapse.xml. Can be used in situations where only the synapse.xml file should be
 * updated at runtime.
 *
 * @param synapseConfig Current Synapse configuration
 * @throws Exception on file I/O error
 */
public void serializeSynapseXML(SynapseConfiguration synapseConfig) throws Exception {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMElement definitions = fac.createOMElement("definitions", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
    if (synapseConfig.getRegistry() != null && !Boolean.valueOf(synapseConfig.getProperty(MultiXMLConfigurationBuilder.SEPARATE_REGISTRY_DEFINITION))) {
        RegistrySerializer.serializeRegistry(definitions, synapseConfig.getRegistry());
    }
    if (synapseConfig.getTaskManager() != null && !Boolean.valueOf(synapseConfig.getProperty(MultiXMLConfigurationBuilder.SEPARATE_TASK_MANAGER_DEFINITION))) {
        TaskManagerSerializer.serializetaskManager(definitions, synapseConfig.getTaskManager());
    }
    Collection<ProxyService> proxyServices = synapseConfig.getProxyServices();
    Collection<SynapseEventSource> eventSources = synapseConfig.getEventSources();
    Collection<Startup> tasks = synapseConfig.getStartups();
    Collection localEntries = synapseConfig.getLocalRegistry().values();
    Collection<PriorityExecutor> executors = synapseConfig.getPriorityExecutors().values();
    Collection<MessageStore> messageStores = synapseConfig.getMessageStores().values();
    Collection<MessageProcessor> messageProcessors = synapseConfig.getMessageProcessors().values();
    Collection<API> apiCollection = synapseConfig.getAPIs();
    Collection<SynapseImport> synapseImportsCollection = synapseConfig.getSynapseImports().values();
    Collection<InboundEndpoint> inboundEndpoints = synapseConfig.getInboundEndpoints();
    Collection<String> comments = synapseConfig.getCommentedTextList();
    for (ProxyService service : proxyServices) {
        if (service.getFileName() == null) {
            ProxyServiceSerializer.serializeProxy(definitions, service);
        }
    }
    for (SynapseEventSource source : eventSources) {
        if (source.getFileName() == null) {
            EventSourceSerializer.serializeEventSource(definitions, source);
        }
    }
    for (Startup task : tasks) {
        if (task instanceof AbstractStartup && task.getFileName() == null) {
            StartupFinder.getInstance().serializeStartup(definitions, task);
        }
    }
    for (Object o : localEntries) {
        if (o instanceof TemplateMediator) {
            TemplateMediator template = (TemplateMediator) o;
            if (template.getFileName() == null) {
                MediatorSerializerFinder.getInstance().getSerializer(template).serializeMediator(definitions, template);
            }
        } else if (o instanceof SequenceMediator) {
            SequenceMediator seq = (SequenceMediator) o;
            if (seq.getFileName() == null) {
                MediatorSerializerFinder.getInstance().getSerializer(seq).serializeMediator(definitions, seq);
            }
        } else if (o instanceof Template) {
            Template templEndpoint = (Template) o;
            if (templEndpoint.getFileName() == null) {
                new TemplateSerializer().serializeEndpointTemplate(templEndpoint, definitions);
            }
        } else if (o instanceof AbstractEndpoint) {
            AbstractEndpoint endpoint = (AbstractEndpoint) o;
            if (endpoint.getFileName() == null) {
                OMElement endpointElem = EndpointSerializer.getElementFromEndpoint(endpoint);
                definitions.addChild(endpointElem);
            }
        } else if (o instanceof Entry) {
            Entry entry = (Entry) o;
            if (entry.getFileName() == null) {
                if ((SynapseConstants.SERVER_HOST.equals(entry.getKey()) || SynapseConstants.SERVER_IP.equals(entry.getKey())) || entry.getType() == Entry.REMOTE_ENTRY) {
                    continue;
                }
                EntrySerializer.serializeEntry(entry, definitions);
            }
        }
    }
    for (PriorityExecutor executor : executors) {
        PriorityExecutorSerializer.serialize(definitions, executor, SynapseConstants.SYNAPSE_NAMESPACE);
    }
    for (MessageStore messageStore : messageStores) {
        if (messageStore.getFileName() == null) {
            MessageStoreSerializer.serializeMessageStore(definitions, messageStore);
        }
    }
    for (MessageProcessor messageProcessor : messageProcessors) {
        if (messageProcessor.getFileName() == null) {
            MessageProcessorSerializer.serializeMessageProcessor(definitions, messageProcessor);
        }
    }
    for (API api : apiCollection) {
        if (api.getFileName() == null) {
            APISerializer.serializeAPI(definitions, api);
        }
    }
    for (SynapseImport synapseImport : synapseImportsCollection) {
        if (synapseImport.getFileName() == null) {
            SynapseImportSerializer.serializeImport(definitions, synapseImport);
        }
    }
    for (InboundEndpoint inboundEndpoint : inboundEndpoints) {
        if (inboundEndpoint.getFileName() == null) {
            InboundEndpointSerializer.serializeInboundEndpoint(definitions, inboundEndpoint);
        }
    }
    serializeComments(comments, definitions);
    serializeSynapseXML(definitions);
}
Also used : MessageStore(org.apache.synapse.message.store.MessageStore) SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) OMElement(org.apache.axiom.om.OMElement) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) Template(org.apache.synapse.endpoints.Template) SynapseImport(org.apache.synapse.libraries.imports.SynapseImport) Entry(org.apache.synapse.config.Entry) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TemplateSerializer(org.apache.synapse.config.xml.endpoints.TemplateSerializer) AbstractStartup(org.apache.synapse.startup.AbstractStartup) AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) OMFactory(org.apache.axiom.om.OMFactory) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) ProxyService(org.apache.synapse.core.axis2.ProxyService) Collection(java.util.Collection) API(org.apache.synapse.rest.API) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) Startup(org.apache.synapse.Startup) AbstractStartup(org.apache.synapse.startup.AbstractStartup)

Example 9 with MessageProcessor

use of org.apache.synapse.message.processor.MessageProcessor in project wso2-synapse by wso2.

the class SynapseXMLConfigurationFactory method defineMessageProcessor.

public static MessageProcessor defineMessageProcessor(SynapseConfiguration config, OMElement elem, Properties properties) {
    MessageProcessor processor = null;
    try {
        processor = MessageProcessorFactory.createMessageProcessor(elem);
        config.addMessageProcessor(processor.getName(), processor);
    } catch (Exception e) {
        String msg = "Message Processor configuration cannot be built";
        handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_MESSAGE_PROCESSORS, msg, e);
    }
    return processor;
}
Also used : MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) SynapseException(org.apache.synapse.SynapseException)

Example 10 with MessageProcessor

use of org.apache.synapse.message.processor.MessageProcessor in project wso2-synapse by wso2.

the class MessageProcessorFactory method createMessageProcessor.

/**
 * Creates a Message processor instance from given xml configuration element
 * @param elem OMElement of that contain the Message processor configuration
 * @return  created message processor instance
 */
public static MessageProcessor createMessageProcessor(OMElement elem) {
    MessageProcessor processor = null;
    OMAttribute clssAtt = elem.getAttribute(CLASS_Q);
    if (clssAtt != null) {
        String clssName = clssAtt.getAttributeValue();
        // Make synapse configuration backward compatible
        if (MessageProcessorConstants.DEPRECATED_FORWARDING_PROCESSOR_CLASS.equals(clssName)) {
            clssName = ScheduledMessageForwardingProcessor.class.getName();
        } else if (MessageProcessorConstants.DEPRECATED_SAMPLING_PROCESSOR_CLASS.equals(clssName)) {
            clssName = SamplingProcessor.class.getName();
        }
        try {
            Class cls = Class.forName(clssName);
            processor = (MessageProcessor) cls.newInstance();
        } catch (Exception e) {
            handleException("Error while creating Message processor " + e.getMessage());
        }
    } else {
        /**
         *We throw Exception since there is not default processor
         */
        handleException("Can't create Message processor without a provider class");
    }
    OMAttribute nameAtt = elem.getAttribute(NAME_Q);
    if (nameAtt != null) {
        assert processor != null;
        processor.setName(nameAtt.getAttributeValue());
    } else {
        handleException("Can't create Message processor without a name ");
    }
    if (FORWARDING_PROCESSOR.equals(clssAtt.getAttributeValue())) {
        OMAttribute targetSequenceAtt = elem.getAttribute(TARGET_ENDPOINT_Q);
        if (targetSequenceAtt != null) {
            assert processor != null;
            processor.setTargetEndpoint(targetSequenceAtt.getAttributeValue());
        } else {
        // This validation is commented due to backward compatibility
        // handleException("Can't create Message processor without a target endpoint ");
        }
    }
    OMAttribute storeAtt = elem.getAttribute(MESSAGE_STORE_Q);
    if (storeAtt != null) {
        assert processor != null;
        processor.setMessageStoreName(storeAtt.getAttributeValue());
    } else {
        handleException("Can't create a message processor with out a message Store");
    }
    OMElement descriptionElem = elem.getFirstChildWithName(DESCRIPTION_Q);
    if (descriptionElem != null) {
        assert processor != null;
        processor.setDescription(descriptionElem.getText());
    }
    assert processor != null;
    processor.setParameters(getParameters(elem));
    return processor;
}
Also used : MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) ScheduledMessageForwardingProcessor(org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute) SynapseException(org.apache.synapse.SynapseException)

Aggregations

MessageProcessor (org.apache.synapse.message.processor.MessageProcessor)15 OMElement (org.apache.axiom.om.OMElement)8 AbstractMessageProcessor (org.apache.synapse.message.processor.impl.AbstractMessageProcessor)6 Test (org.junit.Test)5 DeploymentException (org.apache.axis2.deployment.DeploymentException)4 SynapseException (org.apache.synapse.SynapseException)4 PriorityExecutor (org.apache.synapse.commons.executors.PriorityExecutor)3 ProxyService (org.apache.synapse.core.axis2.ProxyService)3 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)3 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)3 MessageStore (org.apache.synapse.message.store.MessageStore)3 API (org.apache.synapse.rest.API)3 File (java.io.File)2 HashMap (java.util.HashMap)2 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)2 Endpoint (org.apache.synapse.endpoints.Endpoint)2 ScheduledMessageForwardingProcessor (org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor)2 SamplingProcessor (org.apache.synapse.message.processor.impl.sampler.SamplingProcessor)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1