/*******************************************************************************
 * Copyright (c) 2011, 2016 Eurotech and/or its affiliates and others
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Eurotech - initial API and implementation
 *
 *******************************************************************************/
package org.eclipse.kapua.broker.core.message;

import javax.jms.JMSException;

import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQTopic;
import org.apache.camel.Message;
import org.eclipse.kapua.broker.core.listener.CamelConstants;
import org.eclipse.kapua.broker.core.plugin.AclConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Camel utility methods
 * 
 * @since 1.0
 */
public class CamelUtil
{

    public static final Logger logger = LoggerFactory.getLogger(CamelUtil.class);

    /**
     * Extract the topic from the {@link Message} looking for Kapua header property that handles this value and inspecting Camel header properties)
     * 
     * @param message
     * @return
     * @throws JMSException
     */
    public static String getTopic(org.apache.camel.Message message) throws JMSException
    {
        String topicOrig = message.getHeader(MessageConstants.PROPERTY_ORIGINAL_TOPIC, String.class);
        if (topicOrig != null) {
            return topicOrig;
        }
        else {
            ActiveMQDestination destination = message.getHeader(CamelConstants.JMS_HEADER_DESTINATION, ActiveMQDestination.class);
            if (destination instanceof ActiveMQTopic) {
                ActiveMQTopic destinationTopic = (ActiveMQTopic) destination;
                return destinationTopic.getTopicName().substring(AclConstants.VT_TOPIC_PREFIX.length());
            }
            else {
                logger.warn("jmsMessage destination is not a Topic or Queue: {}", destination.toString());
                throw new JMSException("Unable to extract the destination. Wrong destination {}", destination.toString());
            }
        }
    }

}

@@ -975,18 +975,17 @@
 thods%0A *
- 
 %0A
+
  * @sinc
@@ -1016,17 +1016,17 @@
 amelUtil
-%0A
+ 
 %7B%0A%0A    p
@@ -1265,17 +1265,16 @@
 )%0A     *
- 
 %0A     * 
@@ -1426,20 +1426,16 @@
 xception
-%0A   
  %7B%0A     
@@ -1603,24 +1603,16 @@
        %7D
-%0A       
  else %7B%0A
@@ -1977,24 +1977,24 @@
 .length());%0A
+
             
@@ -1994,28 +1994,16 @@
        %7D
-%0A           
  else %7B%0A

Apply code formatter and cleanup profile