use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class JmsConsumer method receive.
public MessageContext receive() {
boolean connectionSuccess = checkAndTryConnect();
if (!connectionSuccess) {
throw new SynapseException(idString + "Error while connecting to JMS provider. " + MessageProcessorConstants.STORE_CONNECTION_ERROR);
}
try {
Message message = consumer.receive(1);
if (message == null) {
return null;
}
if (!(message instanceof ObjectMessage)) {
logger.warn("JMS Consumer " + getId() + " did not receive a javax.jms.ObjectMessage");
// we just discard this message as we only store Object messages via JMS Message store
message.acknowledge();
return null;
}
ObjectMessage msg = (ObjectMessage) message;
String messageId = msg.getStringProperty(Constants.OriginalMessageID);
if (!(msg.getObject() instanceof StorableMessage)) {
logger.warn("JMS Consumer " + getId() + " did not receive a valid message.");
message.acknowledge();
return null;
}
// create a ,essage context back from the stored message
StorableMessage storableMessage = (StorableMessage) msg.getObject();
org.apache.axis2.context.MessageContext axis2Mc = store.newAxis2Mc();
MessageContext synapseMc = store.newSynapseMc(axis2Mc);
synapseMc = MessageConverter.toMessageContext(storableMessage, axis2Mc, synapseMc);
// cache the message
updateCache(message, synapseMc, messageId, false);
if (logger.isDebugEnabled()) {
logger.debug(getId() + " Received MessageId:" + messageId + " priority:" + message.getJMSPriority());
}
return synapseMc;
} catch (JMSException e) {
logger.error("Cannot fetch messages from Store " + store.getName());
updateCache(null, null, "", true);
cleanup();
/* try connecting and receiving again. Try to connect will happen configured number of times
and give up with a SynapseException */
return receive();
}
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class JmsStore method getProducer.
public MessageProducer getProducer() {
if (cacheLevel == 1 && cachedProducer != null) {
return cachedProducer;
}
if (this.producer == null) {
this.producer = new JmsProducer(this);
this.producer.setId(nextProducerId());
} else {
return producer;
}
Session session = null;
javax.jms.MessageProducer messageProducer;
try {
synchronized (producerLock) {
if (producerConnection == null) {
newWriteConnection();
}
}
if (((JmsProducer) this.producer).getSession() == null) {
try {
session = newSession(producerConnection(), Session.AUTO_ACKNOWLEDGE, true);
} catch (JMSException e) {
newWriteConnection();
session = newSession(producerConnection(), Session.AUTO_ACKNOWLEDGE, true);
}
messageProducer = newProducer(session);
((JmsProducer) this.producer).setConnection(producerConnection()).setSession(session).setProducer(messageProducer);
if (logger.isDebugEnabled()) {
logger.debug(nameString() + " created message producer " + this.producer.getId());
}
if (cacheLevel == 1) {
cachedProducer = producer;
}
}
} catch (Throwable t) {
String errorMsg = "Could not create a Message Producer for " + nameString();
logger.error(errorMsg, t);
synchronized (producerLock) {
try {
cleanup(producerConnection, session);
} catch (JMSException e) {
throw new SynapseException("Error while cleaning up connection for message store " + nameString(), e);
}
producerConnection = null;
}
}
return this.producer;
}
use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.
the class JmsStore method resolveSecureVaultExpressions.
/**
* Use secure vault to secure password in JMS Message Store.
*
* @param value Value of password from JMS Message Store
* @return the actual password from the Secure Vault Password Management.
*/
private String resolveSecureVaultExpressions(String value) {
// Password can be null, it is optional
if (value == null) {
return null;
}
Matcher lookupMatcher = vaultLookupPattern.matcher(value);
String resolvedValue = value;
if (lookupMatcher.find()) {
Value expression = null;
// getting the expression with out curly brackets
String expressionStr = lookupMatcher.group(1);
try {
expression = new Value(new SynapseXPath(expressionStr));
} catch (JaxenException e) {
throw new SynapseException("Error while building the expression : " + expressionStr, e);
}
resolvedValue = expression.evaluateValue(synapseEnvironment.createMessageContext());
if (StringUtils.isEmpty(resolvedValue)) {
log.warn("Found Empty value for expression : " + expression.getExpression());
resolvedValue = "";
}
}
return resolvedValue;
}
use of org.apache.synapse.SynapseException 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.SynapseException in project wso2-synapse by wso2.
the class JDBCMessageStore method remove.
/**
* Remove the message with given msg_id
*
* @param msgId - message ID
* @return - removed message context
*/
@Override
public MessageContext remove(String msgId) throws SynapseException {
MessageContext result;
boolean cleaningState = false;
try {
if (cleaningFlag.get()) {
try {
removeLock.lock();
cleaningState = true;
} catch (Exception ie) {
logger.error("Message Cleanup lock released unexpectedly", ie);
}
}
result = get(msgId);
List<Statement> statements = removeMessageStatement(msgId);
processNonResultingStatement(statements);
} catch (Exception e) {
throw new SynapseException("Removing message with id = " + msgId + " failed !", e);
} finally {
if (cleaningState) {
removeLock.unlock();
}
}
return result;
}
Aggregations