use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.
the class DebugManagerTest method testDebugManagerProcessCommandSetBreakPointInboundSequence.
public void testDebugManagerProcessCommandSetBreakPointInboundSequence() throws Exception {
InboundEndpoint inboundEndpoint = new InboundEndpoint();
inboundEndpoint.setName("test_inbound_1");
TestMediator in1 = new TestMediator();
TestMediator in2 = new TestMediator();
TestMediator in3 = new TestMediator();
SequenceMediator dispatchSeq = new SequenceMediator();
dispatchSeq.addChild(in1);
dispatchSeq.addChild(in2);
dispatchSeq.addChild(in3);
TestMediator out1 = new TestMediator();
TestMediator out2 = new TestMediator();
TestMediator out3 = new TestMediator();
SequenceMediator errorSeq = new SequenceMediator();
errorSeq.addChild(out1);
errorSeq.addChild(out2);
errorSeq.addChild(out3);
synConfig.addSequence("dispatch", dispatchSeq);
inboundEndpoint.setInjectingSeq("dispatch");
synConfig.addSequence("error", errorSeq);
inboundEndpoint.setOnErrorSeq("error");
synConfig.addInboundEndpoint(inboundEndpoint.getName(), inboundEndpoint);
String debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\",\"mediation-component\":\"sequence\"," + "\"sequence\":{\"inbound\":{\"inbound-key\":\"test_inbound_1\",\"sequence-type\":\"inbound_seq\",\"mediator-position\":\"0\"}}}";
dm.processDebugCommand(debug_command);
assertTrue(((AbstractMediator) dispatchSeq.getChild(0)).isBreakPoint());
}
use of org.apache.synapse.inbound.InboundEndpoint 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);
}
use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.
the class SynapseXMLConfigurationSerializer method serializeConfiguration.
/**
* Order of entries is irrelevant, however its nice to have some order.
*
* @param synCfg configuration to be serialized
* @return serialized element of the configuration
*/
public OMElement serializeConfiguration(SynapseConfiguration synCfg) {
OMElement definitions = fac.createOMElement("definitions", synNS);
// first add the description
if (synCfg.getDescription() != null) {
OMElement descElem = fac.createOMElement("description", synNS);
descElem.setText(synCfg.getDescription());
definitions.addChild(descElem);
}
// then process a remote registry if present
if (synCfg.getRegistry() != null) {
RegistrySerializer.serializeRegistry(definitions, synCfg.getRegistry());
}
// then process a remote registry if present
if (synCfg.getTaskManager() != null) {
TaskManagerSerializer.serializetaskManager(definitions, synCfg.getTaskManager());
}
serializeImports(definitions, synCfg.getSynapseImports().values());
// add proxy services
Iterator itr = synCfg.getProxyServices().iterator();
while (itr.hasNext()) {
ProxyService service = (ProxyService) itr.next();
ProxyServiceSerializer.serializeProxy(definitions, service);
}
// Add Event sources
for (SynapseEventSource eventSource : synCfg.getEventSources()) {
EventSourceSerializer.serializeEventSource(definitions, eventSource);
}
Map<String, Entry> entries = new HashMap<String, Entry>();
Map<String, Endpoint> endpoints = new HashMap<String, Endpoint>();
Map<String, SequenceMediator> sequences = new HashMap<String, SequenceMediator>();
Map<String, TemplateMediator> templates = new HashMap<String, TemplateMediator>();
Map<String, Template> endpointTemplates = new HashMap<String, Template>();
itr = synCfg.getLocalRegistry().keySet().iterator();
while (itr.hasNext()) {
Object key = itr.next();
if (SynapseConstants.SERVER_IP.equals(key) || SynapseConstants.SERVER_HOST.equals(key)) {
continue;
}
Object o = synCfg.getLocalRegistry().get(key);
if (o instanceof TemplateMediator) {
templates.put(key.toString(), (TemplateMediator) o);
} else if (o instanceof SequenceMediator) {
sequences.put(key.toString(), (SequenceMediator) o);
} else if (o instanceof Endpoint) {
endpoints.put(key.toString(), (Endpoint) o);
} else if (o instanceof Template) {
endpointTemplates.put(key.toString(), (Template) o);
} else if (o instanceof Entry) {
entries.put(key.toString(), (Entry) o);
} else {
handleException("Unknown object : " + o.getClass() + " for serialization into Synapse configuration");
}
}
// process entries
serializeEntries(definitions, entries);
// process endpoints
serializeEndpoints(definitions, endpoints);
// process sequences
serializeSequences(definitions, sequences);
// process templates
serializeMediatorTemplates(definitions, templates);
// serialize the endpoint templates
serializeEndpointTemplates(definitions, endpointTemplates);
// handle startups
serializeStartups(definitions, synCfg.getStartups());
// Executors
serializeExecutors(definitions, synCfg.getPriorityExecutors());
// Message stores
serializeMessageStores(definitions, synCfg.getMessageStores());
// Message Processors
serializeMessageProcessors(definitions, synCfg.getMessageProcessors());
serializeAPIs(definitions, synCfg.getAPIs());
// XML comments
serializeComments(definitions, synCfg.getCommentedTextList());
if (synCfg.getInboundEndpoints() != null && synCfg.getInboundEndpoints().size() > 0) {
Collection<InboundEndpoint> inboundEndpoints = synCfg.getInboundEndpoints();
for (InboundEndpoint inboundEndpoint : inboundEndpoints) {
InboundEndpointSerializer.serializeInboundEndpoint(definitions, inboundEndpoint);
}
}
return definitions;
}
use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.
the class InboundEndpointDebugUtil method registerInboundSequenceMediationFlowBreakPoint.
/**
* Registers/Un-registers a breakpoint, point where mediation flow get suspended
*
* @param synCfg Synapse configuration
* @param sequenceType Synapse sequence type
* @param inboundKey name of the Inbound Endpoint
* @param position array of integers that uniquely specifies a point in mediation route
* @param registerMode specify whether register or un register
*/
public static void registerInboundSequenceMediationFlowBreakPoint(SynapseConfiguration synCfg, String sequenceType, String inboundKey, int[] position, boolean registerMode) {
SynapseSequenceType synapseSequenceType = SynapseSequenceType.valueOf(sequenceType.toUpperCase());
SequenceMediationFlowPoint breakPoint = new SequenceMediationFlowPoint();
breakPoint.setSynapseMediationComponent(SynapseMediationComponent.SEQUENCE);
breakPoint.setKey(inboundKey);
breakPoint.setMediatorPosition(position);
breakPoint.setSequenceBaseType(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_INBOUND);
breakPoint.setSynapseSequenceType(synapseSequenceType);
Mediator seqMediator = null;
InboundEndpoint inbound = null;
inbound = synCfg.getInboundEndpoint(inboundKey);
if (inbound != null) {
if (synapseSequenceType.equals(SynapseSequenceType.INBOUND_SEQ)) {
seqMediator = synCfg.getSequence(inbound.getInjectingSeq());
} else if (synapseSequenceType.equals(SynapseSequenceType.INBOUND_FAULTSEQ)) {
seqMediator = synCfg.getSequence(inbound.getOnErrorSeq());
}
} else {
if (log.isDebugEnabled()) {
log.debug("Non existing Inbound Endpoint for key " + breakPoint.getKey());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_INBOUND_NOT_FOUND).toString());
return;
}
if (seqMediator != null) {
Mediator current_mediator = null;
current_mediator = MediatorTreeTraverseUtil.getMediatorReference(synCfg, seqMediator, position);
if (current_mediator != null) {
breakPoint.setMediatorReference(current_mediator);
if (registerMode) {
if (!((AbstractMediator) current_mediator).isBreakPoint()) {
((AbstractMediator) current_mediator).setBreakPoint(true);
((AbstractMediator) current_mediator).registerMediationFlowPoint(breakPoint);
if (log.isDebugEnabled()) {
log.debug("Registered breakpoint at mediator position " + logMediatorPosition(breakPoint) + " for Inbound Endpoint key " + breakPoint.getKey() + " sequence " + breakPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(true, null).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed register breakpoint. Already breakpoint enabled at mediator position " + logMediatorPosition(breakPoint) + " for Inbound Endpoint key " + breakPoint.getKey() + " sequence " + breakPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_ALREADY_BREAKPOINT_ENABLED).toString());
}
} else {
if (((AbstractMediator) current_mediator).isBreakPoint()) {
((AbstractMediator) current_mediator).unregisterMediationFlowPoint();
((AbstractMediator) current_mediator).setBreakPoint(false);
if (log.isDebugEnabled()) {
log.debug("Unregistered breakpoint at mediator position " + logMediatorPosition(breakPoint) + " for Inbound Endpoint key " + breakPoint.getKey() + " sequence " + breakPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(true, null).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister breakpoint. Already breakpoint disabled at mediator position " + logMediatorPosition(breakPoint) + " for Inbound Endpoint key " + breakPoint.getKey() + " sequence " + breakPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_ALREADY_BREAKPOINT_DISABLED).toString());
}
}
} else {
if (registerMode) {
if (log.isDebugEnabled()) {
log.debug("Failed register breakpoint. Non existing mediator position at " + logMediatorPosition(breakPoint) + " for Inbound Endpoint key " + breakPoint.getKey() + " sequence " + breakPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_MEDIATOR_POSITION).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister breakpoint. Non existing mediator position at " + logMediatorPosition(breakPoint) + " for Inbound Endpoint key " + breakPoint.getKey() + " sequence " + breakPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_MEDIATOR_POSITION).toString());
}
}
} else {
if (registerMode) {
if (log.isDebugEnabled()) {
log.debug("Failed register breakpoint. Non existing sequence " + breakPoint.getSynapseSequenceType().toString() + " for Inbound Endpoint key " + breakPoint.getKey());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister breakpoint. Non existing sequence " + breakPoint.getSynapseSequenceType().toString() + " for Inbound Endpoint key " + breakPoint.getKey());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
}
}
}
use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.
the class MultiXMLConfigurationBuilder method createInboundEndpoint.
private static void createInboundEndpoint(SynapseConfiguration synapseConfig, String rootDirPath, Properties properties) {
File inboundEndpointDir = new File(rootDirPath, INBOUND_ENDPOINT_DIR);
if (inboundEndpointDir.exists()) {
if (log.isDebugEnabled()) {
log.debug("Loading APIs from :" + inboundEndpointDir.getPath());
}
Iterator inboundEndpointIterator = FileUtils.iterateFiles(inboundEndpointDir, extensions, false);
while (inboundEndpointIterator.hasNext()) {
File file = (File) inboundEndpointIterator.next();
try {
OMElement document = getOMElement(file);
InboundEndpoint inboundEndpoint = SynapseXMLConfigurationFactory.defineInboundEndpoint(synapseConfig, document, properties);
if (inboundEndpoint != null) {
inboundEndpoint.setFileName(file.getName());
synapseConfig.getArtifactDeploymentStore().addArtifact(file.getAbsolutePath(), inboundEndpoint.getName());
}
} catch (Exception e) {
String msg = "Inbound Endpoint configuration cannot be built from : " + file.getName();
handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_INBOUND_ENDPOINT, msg, e);
}
}
}
}
Aggregations