Search in sources :

Example 6 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class FailoverForwardingService method init.

public void init(SynapseEnvironment se) throws SynapseException {
    // Setting up the JMS consumer/Producer here.
    try {
        setMessageConsumerAndProducer();
    } catch (StoreForwardException e) {
        throw new SynapseException("Error while initializing Message Consumer " + messageProcessor.getName() + "and Message Producer " + targetMessageStoreName, e);
    }
    // Defaults to -1.
    Map<String, Object> parametersMap = messageProcessor.getParameters();
    if (parametersMap.get(MessageProcessorConstants.MAX_DELIVER_ATTEMPTS) != null) {
        maxDeliverAttempts = Integer.parseInt((String) parametersMap.get(MessageProcessorConstants.MAX_DELIVER_ATTEMPTS));
    }
    if (parametersMap.get(MessageProcessorConstants.RETRY_INTERVAL) != null) {
        retryInterval = Integer.parseInt((String) parametersMap.get(MessageProcessorConstants.RETRY_INTERVAL));
    }
    faultSeq = (String) parametersMap.get(FailoverForwardingProcessorConstants.FAULT_SEQUENCE);
    deactivateSeq = (String) parametersMap.get(FailoverForwardingProcessorConstants.DEACTIVATE_SEQUENCE);
    // Default value should be true.
    if (parametersMap.get(FailoverForwardingProcessorConstants.THROTTLE) != null) {
        isThrottling = Boolean.parseBoolean((String) parametersMap.get(FailoverForwardingProcessorConstants.THROTTLE));
    }
    if (parametersMap.get(FailoverForwardingProcessorConstants.CRON_EXPRESSION) != null) {
        cronExpression = String.valueOf(parametersMap.get(FailoverForwardingProcessorConstants.CRON_EXPRESSION));
    }
    // Default Value should be -1.
    if (cronExpression != null && parametersMap.get(FailoverForwardingProcessorConstants.THROTTLE_INTERVAL) != null) {
        throttlingInterval = Long.parseLong((String) parametersMap.get(FailoverForwardingProcessorConstants.THROTTLE_INTERVAL));
    }
    // Default to FALSE.
    if (parametersMap.get(FailoverForwardingProcessorConstants.MAX_DELIVERY_DROP) != null && parametersMap.get(FailoverForwardingProcessorConstants.MAX_DELIVERY_DROP).toString().equals("Enabled") && maxDeliverAttempts > 0) {
        isMaxDeliveryAttemptDropEnabled = true;
    }
    // Setting the interval value.
    interval = Long.parseLong((String) parametersMap.get(MessageProcessorConstants.INTERVAL));
    /*
		 * Make sure to set the isInitialized flag to TRUE in order to avoid
		 * re-initialization.
		 */
    initialized = true;
}
Also used : SynapseException(org.apache.synapse.SynapseException) StoreForwardException(org.apache.synapse.message.StoreForwardException)

Example 7 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class FailoverScheduledMessageForwardingProcessor method init.

@Override
public void init(SynapseEnvironment se) {
    parameters.put(FailoverForwardingProcessorConstants.THROTTLE, String.valueOf((isThrottling(interval))));
    if (isThrottling(cronExpression)) {
        parameters.put(FailoverForwardingProcessorConstants.THROTTLE_INTERVAL, String.valueOf(interval));
        parameters.put(FailoverForwardingProcessorConstants.CRON_EXPRESSION, cronExpression);
    }
    super.init(se);
    try {
        view = new FailoverMessageForwardingProcessorView(this);
    } catch (Exception e) {
        throw new SynapseException(e);
    }
    // register MBean
    org.apache.synapse.commons.jmx.MBeanRegistrar.getInstance().registerMBean(view, "Message Failover Forwarding Processor view", getName());
}
Also used : SynapseException(org.apache.synapse.SynapseException) SynapseException(org.apache.synapse.SynapseException)

Example 8 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class ForwardingService method execute.

/**
 * Starts the execution of this task which grabs a message from the message
 * queue and dispatch it to a given endpoint.
 */
public void execute() {
    final long startTime = new Date().getTime();
    if (isDeactivatedAtStartup) {
        // inactive
        try {
            TimeUnit.MILLISECONDS.sleep(MessageProcessorConstants.INITIAL_EXECUTION_DELAY);
        } catch (InterruptedException exception) {
            log.warn("Initial delay interrupted when Forwarding service started as inactive ", exception);
        }
        isDeactivatedAtStartup = false;
    }
    /*
		 * Initialize only if it is NOT already done. This will make sure that
		 * the initialization is done only once.
		 */
    if (!initialized) {
        try {
            this.init(synapseEnvironment);
        } catch (SynapseException e) {
            log.fatal("Deactivating the message processor [" + this.messageProcessor.getName() + "] due to initialization issue", e);
            deactivateMessageProcessor(null);
        }
    }
    do {
        resetService();
        MessageContext messageContext = null;
        try {
            if (!this.messageProcessor.isDeactivated()) {
                messageContext = fetch();
                if (messageContext != null) {
                    Set proSet = messageContext.getPropertyKeySet();
                    if (proSet != null) {
                        if (proSet.contains(ForwardingProcessorConstants.BLOCKING_SENDER_ERROR)) {
                            proSet.remove(ForwardingProcessorConstants.BLOCKING_SENDER_ERROR);
                        }
                    }
                    // Now it is NOT terminated anymore.
                    isTerminated = messageProcessor.isDeactivated();
                    dispatch(messageContext);
                } else {
                    // massages.
                    if (log.isDebugEnabled()) {
                        log.debug("No messages were received for message processor [" + messageProcessor.getName() + "]");
                    }
                    // this means we have consumed all the messages
                    if (isRunningUnderCronExpression()) {
                        break;
                    }
                }
            } else {
                /*
					 * we need this because when start the server while the
					 * processors in deactivated mode
					 * the deactivation may not come in to play because the
					 * service may not be running.
					 */
                isTerminated = true;
                if (log.isDebugEnabled()) {
                    log.debug("Exiting service since the message processor is deactivated");
                }
            }
        } catch (Throwable e) {
            /*
				 * All the possible recoverable exceptions are handles case by
				 * case and yet if it comes this
				 * we have to shutdown the processor
				 */
            log.fatal("Deactivating the message processor [" + this.messageProcessor.getName() + "]", e);
            deactivateMessageProcessor(messageContext);
        }
        if (log.isDebugEnabled()) {
            log.debug("Exiting the iteration of message processor [" + this.messageProcessor.getName() + "]");
        }
        /*
			 * This code wrote handle scenarios in which cron expressions are
			 * used for scheduling task
			 */
        if (isRunningUnderCronExpression()) {
            try {
                Thread.sleep(throttlingInterval);
            } catch (InterruptedException e) {
                // no need to worry. it does have any serious consequences
                log.debug("Current Thread was interrupted while it is sleeping.");
            }
        }
        /*
			 * If the interval is less than 1000 ms, then the scheduling is done
			 * using the while loop since ntask rejects any intervals whose
			 * value is less then 1000 ms. Cron expressions are handled above so
			 * we need to skip it here. Otherwise the cron expression is kept
			 * sleeping twice as the forwarding interval.
			 */
        if (interval > 0 && interval < MessageProcessorConstants.THRESHOULD_INTERVAL && !isRunningUnderCronExpression()) {
            try {
                Thread.sleep(interval);
            } catch (InterruptedException e) {
                log.debug("Current Thread was interrupted while it is sleeping.");
            }
        }
        /*
			 * Gives the control back to Quartz scheduler. This needs to be done
			 * only if the interval value is less than the Threshould interval
			 * value of 1000 ms, where the scheduling is done outside of Quartz
			 * via the while loop. Otherwise the schedular will get blocked.
			 * For cron expressions with interval < 1000ms this scenario is not
			 * applicable hence skipping it here. For cron expressions, all the
			 * messages in the queue at the moment are sent to the backend. If
			 * you give control back to the Quartz that behavior can not be
			 * achieved, only a portion of the messages will get dispatched
			 * while other messages will remain in the queue.
			 */
        if (isThrottling && new Date().getTime() - startTime > 1000 && !isRunningUnderCronExpression()) {
            break;
        }
    } while ((isThrottling || isRunningUnderCronExpression()) && !isTerminated);
    if (log.isDebugEnabled()) {
        log.debug("Exiting service thread of message processor [" + this.messageProcessor.getName() + "]");
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 9 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class ScheduledMessageForwardingProcessor method init.

@Override
public void init(SynapseEnvironment se) {
    parameters.put(ForwardingProcessorConstants.THROTTLE, String.valueOf((isThrottling(interval))));
    if (isThrottling(cronExpression)) {
        parameters.put(ForwardingProcessorConstants.THROTTLE_INTERVAL, String.valueOf(interval));
        parameters.put(ForwardingProcessorConstants.CRON_EXPRESSION, cronExpression);
    }
    if (nonRetryStatusCodes != null) {
        parameters.put(ForwardingProcessorConstants.NON_RETRY_STATUS_CODES, nonRetryStatusCodes);
    }
    // target.endpoint property is used to fetch the endpoint
    if (targetEndpoint != null) {
        parameters.put(ForwardingProcessorConstants.TARGET_ENDPOINT, targetEndpoint);
    }
    super.init(se);
    try {
        view = new MessageForwardingProcessorView(this);
    } catch (Exception e) {
        throw new SynapseException(e);
    }
    // register MBean
    org.apache.synapse.commons.jmx.MBeanRegistrar.getInstance().registerMBean(view, "Message Forwarding Processor view", getName());
}
Also used : SynapseException(org.apache.synapse.SynapseException) SynapseException(org.apache.synapse.SynapseException)

Example 10 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class SamplingProcessor method init.

@Override
public void init(SynapseEnvironment se) {
    super.init(se);
    try {
        view = new SamplingProcessorView(this);
    } catch (Exception e) {
        throw new SynapseException(e);
    }
    // register MBean
    org.apache.synapse.commons.jmx.MBeanRegistrar.getInstance().registerMBean(view, "Message Sampling Processor view", getName());
}
Also used : SynapseException(org.apache.synapse.SynapseException) SynapseException(org.apache.synapse.SynapseException)

Aggregations

SynapseException (org.apache.synapse.SynapseException)136 OMElement (org.apache.axiom.om.OMElement)31 OMAttribute (org.apache.axiom.om.OMAttribute)23 MessageContext (org.apache.synapse.MessageContext)20 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)16 QName (javax.xml.namespace.QName)15 Iterator (java.util.Iterator)14 JaxenException (org.jaxen.JaxenException)14 XMLStreamException (javax.xml.stream.XMLStreamException)13 AxisFault (org.apache.axis2.AxisFault)13 Map (java.util.Map)12 Endpoint (org.apache.synapse.endpoints.Endpoint)12 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 IOException (java.io.IOException)8 MalformedURLException (java.net.MalformedURLException)8 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)8 OMNode (org.apache.axiom.om.OMNode)7 Mediator (org.apache.synapse.Mediator)7 MediatorProperty (org.apache.synapse.mediators.MediatorProperty)7