Client client=(Client)req.getAttribute(CLIENT_ATTR);  Transport transport=(Transport)req.getAttribute(Bayeux.TRANSPORT_ATTR);
Object clientObj=req.getAttribute(CLIENT_ATTR); Client client=(clientObj instanceof Client)?(Client)clientObj:null; Transport transport=client==null?null:(Transport)req.getAttribute(Bayeux.TRANSPORT_ATTR);
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException    {        String bid=null;        if (_multiTimeout>0)        {            Cookie[] cookies=req.getCookies();            for (int i=0;cookies!=null && i<cookies.length;i++)            {                if (cookies[i].getName().equals(BROWSER_ID))                    bid=cookies[i].getValue();            }            if (bid==null)            {                bid=Long.toString(_bayeux._random.nextLong(),16)+Long.toString(_bayeux._random.nextLong(),16);                Cookie cookie = new Cookie(BROWSER_ID,bid);                cookie.setPath("/");                resp.addCookie(cookie);            }        }                int message_count=0;        Client client=(Client)req.getAttribute(CLIENT_ATTR);                Transport transport=(Transport)req.getAttribute(Bayeux.TRANSPORT_ATTR);        if (client==null)        {            // This is the first time we have seen this request - so handle all            // the messages            // We may see this request again if a continuation retries the            // request.            // handle all messages (before any polling)            String[] messages=req.getParameterValues(MESSAGE_PARAM);                        Object objects=null;            int index=0;            for (int m=0; m<messages.length; m++)            {                System.err.println("="+m+"=>"+messages[m]);                if (objects==null)                {                    index=0;                    objects=JSON.parse(messages[m]);                }                if (objects==null)                    continue;                Object object=objects;                if (objects.getClass().isArray())                {                    if (index>=Array.getLength(objects))                    {                        objects=null;                        continue;                    }                    object=Array.get(objects,index++);                }                else                    objects=null;                message_count++;                Map message=(Map)object;                // Get a client if possible                if (client==null)                {                    client=_bayeux.getClient((String)message.get(Bayeux.CLIENT_ATTR));                    req.setAttribute(CLIENT_ATTR,client);                }                if (transport==null)                {                    transport=_bayeux.newTransport(client,message);                    req.setAttribute(Bayeux.TRANSPORT_ATTR,transport);                }                transport.setResponse(resp);                _bayeux.handle(client,transport,message);                            }        }        // handle polling for additinal messages        Continuation continuation=null;        try        {            while (client!=null && transport!=null && transport.isPolling())            {                   long timeout=_timeout;                continuation=ContinuationSupport.getContinuation(req,client);                try                {                    if (bid!=null && !continuation.isPending() && incBID(bid)>1)                        timeout=_multiTimeout;                    synchronized (client)                    {                        client.addContinuation(continuation);                        if (!client.hasMessages())                            continuation.suspend(timeout);                        client.removeContinuation(continuation);                        continuation.reset();                        if (client.hasMessages())                        {                            List messages=client.takeMessages();                            transport.send(messages);                        }                        else                            transport.setPolling(false);                        // Only a simple poll if the transport does not flush                        if (!transport.keepAlive())                            transport.setPolling(false);                    }                 }                finally                {                    // Are we really finished polling?                    if (bid!=null && (continuation==null || !continuation.isPending()))                    {                        decBID(bid);                    }                }            }        }        finally        {            // Are we really finished polling?            if (continuation==null || !continuation.isPending())            {                // complete transport                if (transport!=null)                {                    transport.complete();                    transport.setPolling(false);                }            }        }    }