/**
 * 
 */
package com.trendrr.strest;

import java.util.concurrent.atomic.AtomicLong;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.netty.handler.codec.http.HttpMessage;
import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.codec.http.HttpVersion;


/**
 * @author Dustin Norlander
 * @created Jan 13, 2011
 * 
 */
public class StrestUtil {

	protected static Log log = LogFactory.getLog(StrestUtil.class);
	
	private static AtomicLong txn = new AtomicLong(0l);
	public static String generateTxnId() {
		return "str" + Long.toHexString(txn.incrementAndGet()) + "st";
	}
	public static final HttpVersion STREST_VERSION = new HttpVersion("STREST", 0, 1, true);
	
	public static final class HEADERS {
		public static final String TXN_ID = "Strest-Txn-Id";
		public static final String TXN_STATUS = "Strest-Txn-Status";
		public static final String TXN_ACCEPT = "Strest-Txn-Accept";	
		
		public static final class TXN_STATUS_VALUES {
			public static final String COMPLETE = "complete";
			public static final String CONTINUE = "continue";
		}
		public static final class TXN_ACCEPT_VALUES {
			public static final String SINGLE = "single";	
			public static final String MULTI = "multi";	
		}
	}
	
	/**
	 * easy check to make sure client can handle multiple returns.
	 * @param request
	 * @return
	 */
	public static boolean isTxnMulti(HttpRequest request) {
		String val = request.getHeader(HEADERS.TXN_ACCEPT);
		if (val == null || !val.equals(HEADERS.TXN_ACCEPT_VALUES.MULTI)) {
			return false;
		}
		return true;
	}
	
	public static String txnId(HttpMessage message) {
		return 	message.getHeader(StrestUtil.HEADERS.TXN_ID);
	}
	
	public static boolean isStrest(HttpRequest request) {
		return "STREST".equalsIgnoreCase(request.getProtocolVersion().getProtocolName());
	}
}

@@ -277,16 +277,72 @@
 equest;%0A
+import org.jboss.netty.handler.codec.http.HttpResponse;%0A
 import o
@@ -1916,10 +1916,579 @@
 ());%0A%09%7D%0A
+%09%0A%09public static String toString(HttpResponse response) %7B%0A%09%09StringBuilder str = new StringBuilder();%0A%09%09str.append(response.getProtocolVersion());%0A%09%09str.append(%22 %22);%0A%09%09str.append(response.getStatus().getCode());%0A%09%09str.append(%22 %22);%0A%09%09str.append(response.getStatus().getReasonPhrase());%0A%09%09%0A%09%09str.append(%22%5Cn%22);%0A%09%09for (String hdr : response.getHeaderNames()) %7B%0A%09%09%09str.append(hdr);%0A%09%09%09str.append(%22 : %22);%0A%09%09%09str.append(response.getHeader(hdr));%0A%09%09%09str.append(%22%5Cn%22);%0A%09%09%7D%0A%09%09%0A%09%09str.append(%22%5Cn%5Cr%5Cn%5Cr%22);%0A%09%09str.append(response.getContent().toString());%0A%0A%09%09return str.toString();%0A%09%7D%0A
 %7D%0A

Add response toString helper