Search in sources :

Example 16 with SynapseException

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();
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) ObjectMessage(javax.jms.ObjectMessage) StorableMessage(org.apache.synapse.message.store.impl.commons.StorableMessage) Message(javax.jms.Message) StorableMessage(org.apache.synapse.message.store.impl.commons.StorableMessage) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) MessageContext(org.apache.synapse.MessageContext)

Example 17 with SynapseException

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;
}
Also used : SynapseException(org.apache.synapse.SynapseException) JMSException(javax.jms.JMSException) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession)

Example 18 with SynapseException

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;
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) SynapseException(org.apache.synapse.SynapseException) Matcher(java.util.regex.Matcher) JaxenException(org.jaxen.JaxenException) Value(org.apache.synapse.mediators.Value)

Example 19 with SynapseException

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;
}
Also used : SynapseException(org.apache.synapse.SynapseException) Connection(javax.jms.Connection) QueueConnection(javax.jms.QueueConnection) StoreForwardException(org.apache.synapse.message.StoreForwardException) JMSException(javax.jms.JMSException) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession)

Example 20 with SynapseException

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;
}
Also used : SynapseException(org.apache.synapse.SynapseException) Statement(org.apache.synapse.message.store.impl.jdbc.util.Statement) PreparedStatement(java.sql.PreparedStatement) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SQLException(java.sql.SQLException) NoSuchElementException(java.util.NoSuchElementException) SynapseException(org.apache.synapse.SynapseException) IOException(java.io.IOException)

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