/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package org.apache.jmeter.protocol.jms;

import java.util.Enumeration;

import javax.jms.JMSException;
import javax.jms.Message;

/**
 * Utility methods for JMS protocol.
 * WARNING - the API for this class is likely to change!
 */
public final class Utils {

    public static final String messageProperties(Message msg){
        return messageProperties(new StringBuilder(), msg).toString();
    }

    public static final StringBuilder messageProperties(StringBuilder sb, Message msg){
        requestHeaders(sb, msg);
        sb.append("Properties:\n");
        Enumeration<?> rme;
        try {
            rme = msg.getPropertyNames();
            while(rme.hasMoreElements()){
                String name=(String) rme.nextElement();
                sb.append(name).append('\t');
                String value=msg.getStringProperty(name);
                sb.append(value).append('\n');
            }
        } catch (JMSException e) {
            sb.append("\nError: "+e.toString());
        }
        return sb;
    }
    
    public static final StringBuilder requestHeaders(StringBuilder sb, Message msg){
        try {
            sb.append("JMSCorrelationId ").append(msg.getJMSCorrelationID()).append('\n');
            sb.append("JMSMessageId     ").append(msg.getJMSMessageID()).append('\n');
            sb.append("JMSTimestamp     ").append(msg.getJMSTimestamp()).append('\n');
            sb.append("JMSType          ").append(msg.getJMSType()).append('\n');
            sb.append("JMSExpiration    ").append(msg.getJMSExpiration()).append('\n');
            sb.append("JMSPriority      ").append(msg.getJMSPriority()).append('\n');
            sb.append("JMSDestination   ").append(msg.getJMSDestination()).append('\n');
        } catch (JMSException e) {
            sb.append("\nError: "+e.toString());
        }
        return sb;
    }
}

@@ -931,162 +931,2050 @@
 ge;%0A
-%0A/**%0A * Utility methods for JMS protocol.%0A * WARNING - the API for this class is likely to change!%0A */%0Apublic final class Utils %7B%0A%0A    public static final
+import javax.jms.MessageConsumer;%0Aimport javax.jms.QueueConnection;%0Aimport javax.jms.QueueSession;%0Aimport javax.jms.TopicConnection;%0Aimport javax.jms.TopicPublisher;%0Aimport javax.jms.TopicSession;%0A%0Aimport org.apache.log.Logger;%0A%0A/**%0A * Utility methods for JMS protocol.%0A * WARNING - the API for this class is likely to change!%0A */%0Apublic final class Utils %7B%0A%0A    public static void close(MessageConsumer closeable, Logger log)%7B%0A        if (closeable != null)%7B%0A            try %7B%0A                closeable.close();%0A            %7D catch (JMSException e) %7B%0A                log.error(%22Error during close: %22, e);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static void close(TopicSession closeable, Logger log) %7B%0A        if (closeable != null)%7B%0A            try %7B%0A                closeable.close();%0A            %7D catch (JMSException e) %7B%0A                log.error(%22Error during close: %22, e);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static void close(TopicConnection closeable, Logger log) %7B%0A        if (closeable != null)%7B%0A            try %7B%0A                closeable.close();%0A            %7D catch (JMSException e) %7B%0A                log.error(%22Error during close: %22, e);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static void close(TopicPublisher closeable, Logger log) %7B%0A        if (closeable != null)%7B%0A            try %7B%0A                closeable.close();%0A            %7D catch (JMSException e) %7B%0A                log.error(%22Error during close: %22, e);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static void close(QueueSession closeable, Logger log) %7B%0A        if (closeable != null)%7B%0A            try %7B%0A                closeable.close();%0A            %7D catch (JMSException e) %7B%0A                log.error(%22Error during close: %22, e);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static void close(QueueConnection closeable, Logger log) %7B%0A        if (closeable != null)%7B%0A            try %7B%0A                closeable.close();%0A            %7D catch (JMSException e) %7B%0A                log.error(%22Error during close: %22, e);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static
  Str
@@ -3097,38 +3097,32 @@
   public static 
-final 
 StringBuilder me
@@ -3727,22 +3727,16 @@
  static 
-final 
 StringBu
@@ -4531,10 +4531,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

Add utility close() methods