if (pollReply!=null)
{
// can we bypass response generation?
if (_refsThreshold>0 && size==1 && transport instanceof JSONTransport)
{
MessageImpl message = (MessageImpl)messages.peek();
// is there a response already prepared
ByteBuffer buffer = message.getBuffer();
if (buffer!=null)
{
request.setAttribute("org.mortbay.jetty.ResponseBuffer",buffer);
((MessageImpl)message).decRef();
flushed=true;
}
else if (message.getRefs()>=_refsThreshold)
{
byte[] contentBytes = ("[{\""+Bayeux.SUCCESSFUL_FIELD+"\":true,\""+
Bayeux.CHANNEL_FIELD+"\":\""+Bayeux.META_CONNECT+"\"},"+
message.getJSON()+"]").getBytes(StringUtil.__UTF8);
int contentLength = contentBytes.length;
String headerString = "HTTP/1.1 200 OK\r\n"+
"Content-Type: text/json; charset=utf-8\r\n" +
"Content-Length: " + contentLength + "\r\n" +
"\r\n";
byte[] headerBytes = headerString.getBytes(StringUtil.__UTF8);
buffer = ByteBuffer.allocateDirect(headerBytes.length+contentLength);
buffer.put(headerBytes);
buffer.put(contentBytes);
buffer.flip();
message.setBuffer(buffer);
request.setAttribute("org.mortbay.jetty.ResponseBuffer",buffer);
((MessageImpl)message).decRef();
flushed=true;
}
else