Search in sources :

Example 6 with StoreForwardException

use of org.apache.synapse.message.StoreForwardException in project wso2-synapse by wso2.

the class JmsStore method initme.

private boolean initme() throws StoreForwardException, JMSException {
    Set<Map.Entry<String, Object>> mapSet = parameters.entrySet();
    for (Map.Entry<String, Object> e : mapSet) {
        if (e.getValue() instanceof String) {
            connectionProperties.put(e.getKey(), e.getValue());
        }
    }
    userName = (String) parameters.get(USERNAME);
    password = resolveSecureVaultExpressions((String) parameters.get(PASSWORD));
    String conCaching = (String) parameters.get(CACHE);
    if ("true".equals(conCaching)) {
        if (logger.isDebugEnabled()) {
            logger.debug(nameString() + " enabling connection Caching");
        }
        cacheLevel = 1;
    }
    String destination = (String) parameters.get(DESTINATION);
    if (destination != null) {
        this.destination = destination;
    } else {
        String name = getName();
        String defaultDest;
        if (name != null && !name.isEmpty()) {
            defaultDest = name + "_Queue";
        } else {
            defaultDest = "JmsStore_" + System.currentTimeMillis() + "_Queue";
        }
        logger.warn(nameString() + ". Destination not provided. " + "Setting default destination to [" + defaultDest + "].");
        this.destination = defaultDest;
    }
    destinationType = "queue";
    String version = (String) parameters.get(JMS_VERSION);
    if (version != null) {
        if (!JMS_SPEC_11.equals(version)) {
            isVersion11 = false;
        }
    }
    if (parameters != null && !parameters.isEmpty() && parameters.get(GUARANTEED_DELIVERY_ENABLE) != null) {
        isGuaranteedDeliveryEnable = Boolean.valueOf(parameters.get(GUARANTEED_DELIVERY_ENABLE).toString());
    }
    String consumerReceiveTimeOut = (String) parameters.get(CONSUMER_TIMEOUT);
    int consumerReceiveTimeOutI = 6000;
    if (consumerReceiveTimeOut != null) {
        try {
            consumerReceiveTimeOutI = Integer.parseInt(consumerReceiveTimeOut);
        } catch (NumberFormatException e) {
        // logger.error(nameString() + ". Error parsing consumer receive time out value. " +
        // "Set to 60s.");
        }
    }
    // else {
    // logger.warn(nameString() + ". Consumer Receiving time out not passed in. " +
    // "Set to 60s.");
    // }
    String connectionFac = null;
    try {
        context = new InitialContext(connectionProperties);
        connectionFac = (String) parameters.get(CONN_FACTORY);
        if (connectionFac == null) {
            connectionFac = "QueueConnectionFactory";
        }
        connectionFactory = lookup(context, javax.jms.ConnectionFactory.class, connectionFac);
        if (connectionFactory == null) {
            throw new StoreForwardException(nameString() + " could not initialize JMS Connection Factory. " + "Connection factory not found : " + connectionFac);
        }
        createDestIfAbsent(null);
        if (queue == null) {
            logger.warn(nameString() + ". JMS Destination [" + destination + "] does not exist.");
        }
    } catch (NamingException e) {
        logger.error(nameString() + ". Could not initialize JMS Message Store. Error:" + e.getLocalizedMessage() + ". Initial Context Factory:[" + parameters.get(NAMING_FACTORY_INITIAL) + "]; Provider URL:[" + parameters.get(PROVIDER_URL) + "]; Connection Factory:[" + connectionFac + "].", e);
    } catch (Throwable t) {
        logger.error(nameString() + ". Could not initialize JMS Message Store. Error:" + t.getMessage() + ". Initial Context Factory:[" + parameters.get(NAMING_FACTORY_INITIAL) + "]; Provider URL:[" + parameters.get(PROVIDER_URL) + "]; Connection Factory:[" + connectionFac + "].", t);
    }
    newWriteConnection();
    return true;
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) InitialContext(javax.naming.InitialContext) QueueConnectionFactory(javax.jms.QueueConnectionFactory) StoreForwardException(org.apache.synapse.message.StoreForwardException) NamingException(javax.naming.NamingException) Map(java.util.Map)

Aggregations

StoreForwardException (org.apache.synapse.message.StoreForwardException)6 SynapseException (org.apache.synapse.SynapseException)3 Connection (javax.jms.Connection)2 JMSException (javax.jms.JMSException)2 QueueConnection (javax.jms.QueueConnection)2 QueueConnectionFactory (javax.jms.QueueConnectionFactory)2 InitialContext (javax.naming.InitialContext)2 NamingException (javax.naming.NamingException)2 Map (java.util.Map)1 Destination (javax.jms.Destination)1 QueueSession (javax.jms.QueueSession)1 Session (javax.jms.Session)1 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)1