use of org.apache.synapse.message.StoreForwardException 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;
}
use of org.apache.synapse.message.StoreForwardException in project wso2-synapse by wso2.
the class JmsStore method getDestination.
/**
* Get Destination denoted by destination variable by looking up context or
* creating it using the session.
*
* @param session Session to create destination from
* @return Destination object
* @throws JMSException on a JMS exception when creating Destination using session
* @throws StoreForwardException on other issue
*/
private Destination getDestination(Session session) throws JMSException, StoreForwardException {
Destination dest = queue;
if (dest != null) {
return dest;
}
// try creating a destination by looking up context
InitialContext newContext;
String destinationLookupFailureReason = "";
try {
dest = lookup(context, javax.jms.Destination.class, destination);
} catch (NamingException e) {
if (logger.isDebugEnabled()) {
logger.debug(nameString() + ". Could not lookup destination [" + destination + "]. Message: " + e.getLocalizedMessage());
}
// try to re-init the context
newContext = newContext();
try {
dest = lookup(newContext, Destination.class, destination);
} catch (Throwable t) {
destinationLookupFailureReason = nameString() + ". Destination [" + destination + "] not defined in JNDI context. Message:" + t.getLocalizedMessage();
}
}
// try creating destination by session as lookup failed (dest == null)
if (dest == null) {
if (session == null) {
throw new StoreForwardException(nameString() + "cannot create Destination" + destination + ". JMS Session " + "cannot be null");
}
try {
dest = session.createQueue(destination);
if (logger.isDebugEnabled()) {
logger.debug(nameString() + " created destination [" + destination + "] from session object.");
}
} catch (JMSException e) {
String error = nameString() + " could not create destination [" + destination + "]. from session or by JNDI context lookup. ";
error.concat("create by session error: " + e);
if (!destinationLookupFailureReason.isEmpty()) {
error.concat(" create by lookup error: " + destinationLookupFailureReason);
}
throw new StoreForwardException(error, e);
}
}
synchronized (queueLock) {
queue = dest;
}
return dest;
}
use of org.apache.synapse.message.StoreForwardException in project wso2-synapse by wso2.
the class JmsStore method getConsumer.
public MessageConsumer getConsumer() throws SynapseException {
JmsConsumer consumer = new JmsConsumer(this);
consumer.setId(nextConsumerId());
try {
Connection connection = newConnection();
Session session = newSession(connection, Session.CLIENT_ACKNOWLEDGE, false);
javax.jms.MessageConsumer jmsConsumer = newConsumer(session);
consumer.setConnection(connection).setSession(session).setConsumer(jmsConsumer);
if (logger.isDebugEnabled()) {
logger.debug(nameString() + " created message consumer " + consumer.getId());
}
} catch (JMSException | StoreForwardException e) {
throw new SynapseException("Could not create a Message Consumer for " + nameString(), e);
}
return consumer;
}
use of org.apache.synapse.message.StoreForwardException in project wso2-synapse by wso2.
the class JmsStore method newConnection.
/**
* Creates a new JMS Connection.
*
* @return A connection to the JMS Queue used as the store of this message store.
* @throws JMSException on a JMS issue
* @throws StoreForwardException on a non JMS issue
*/
public Connection newConnection() throws JMSException, StoreForwardException {
Connection connection;
if (connectionFactory == null) {
throw new StoreForwardException("Cannot create a connection to JMS provider as connectionFactory == null");
}
if (isVersion11) {
if (userName != null && password != null) {
connection = connectionFactory.createConnection(userName, password);
} else {
connection = connectionFactory.createConnection();
}
} else {
QueueConnectionFactory connectionFactory;
connectionFactory = (QueueConnectionFactory) this.connectionFactory;
if (userName != null && password != null) {
connection = connectionFactory.createQueueConnection(userName, password);
} else {
connection = connectionFactory.createQueueConnection();
}
}
connection.start();
if (logger.isDebugEnabled()) {
logger.debug(nameString() + ". Created JMS Connection.");
}
return connection;
}
use of org.apache.synapse.message.StoreForwardException in project wso2-synapse by wso2.
the class ForwardingService method init.
public void init(SynapseEnvironment se) throws SynapseException {
// Setting up the JMS consumer here.
try {
setMessageConsumer();
} catch (StoreForwardException e) {
throw new SynapseException("Error while initializing consumer " + messageProcessor.getName(), 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));
}
String maxConnectionAttemptsToStore = (String) parametersMap.get(MessageProcessorConstants.MAX_STORE_CONNECT_ATTEMPTS);
String storeConnectionAttemptDelay = (String) parametersMap.get(MessageProcessorConstants.STORE_CONNECTION_RETRY_INTERVAL);
if (null != maxConnectionAttemptsToStore) {
this.maxConnectionAttemptsToStore = Integer.parseInt(maxConnectionAttemptsToStore);
}
if (null != storeConnectionAttemptDelay) {
this.storeConnectionAttemptDelay = Integer.parseInt(storeConnectionAttemptDelay);
}
replySeq = (String) parametersMap.get(ForwardingProcessorConstants.REPLY_SEQUENCE);
faultSeq = (String) parametersMap.get(ForwardingProcessorConstants.FAULT_SEQUENCE);
deactivateSeq = (String) parametersMap.get(ForwardingProcessorConstants.DEACTIVATE_SEQUENCE);
targetEndpoint = (String) parametersMap.get(ForwardingProcessorConstants.TARGET_ENDPOINT);
String failMessageStoreName = (String) parametersMap.get(ForwardingProcessorConstants.FAIL_MESSAGES_STORE);
if (null != failMessageStoreName && !failMessageStoreName.isEmpty()) {
failMessageStore = se.createMessageContext().getConfiguration().getMessageStore(failMessageStoreName);
}
// Default value should be true.
if (parametersMap.get(ForwardingProcessorConstants.THROTTLE) != null) {
isThrottling = Boolean.parseBoolean((String) parametersMap.get(ForwardingProcessorConstants.THROTTLE));
}
if (parametersMap.get(ForwardingProcessorConstants.CRON_EXPRESSION) != null) {
cronExpression = String.valueOf(parametersMap.get(ForwardingProcessorConstants.CRON_EXPRESSION));
}
// Default Value should be -1.
if (cronExpression != null && parametersMap.get(ForwardingProcessorConstants.THROTTLE_INTERVAL) != null) {
throttlingInterval = Long.parseLong((String) parametersMap.get(ForwardingProcessorConstants.THROTTLE_INTERVAL));
}
nonRetryStatusCodes = (String[]) parametersMap.get(ForwardingProcessorConstants.NON_RETRY_STATUS_CODES);
// Default to FALSE.
if (parametersMap.get(ForwardingProcessorConstants.MAX_DELIVERY_DROP) != null && parametersMap.get(ForwardingProcessorConstants.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;
}
Aggregations