public void setAsyncResult(ByteBuffer buf, Exception ex) { if (log.isDebugEnabled()) { log.debug("setAsyncResult" + this + "(buf=" + buf + ", ex=" + ex); } if (Interlocked.Increment(ref isOpen) == 1) { try { if (ex == null && buf != null && buf.remaining() != 0) { BMessageHeader header = new BMessageHeader(); bool nego = BNegotiate.isNegotiateMessage(buf); if (nego) { BNegotiate negoResponse = new BNegotiate(); negoResponse.read(buf); header.messageId = messageId; BTransport utransport = wire.getClientUtilityRequests().getTransport(); utransport.applyNegotiate(negoResponse); } else { header.read(buf); } BMessage msg = buf != null ? new BMessage(header, buf, null) : null; if (log.isDebugEnabled()) { log.debug("asyncResult.set"); } asyncResult.setAsyncResult(msg, ex); } else { asyncResult.setAsyncResult(null, ex); } } catch (Exception e) { asyncResult.setAsyncResult(null, e); } } if (log.isDebugEnabled()) { log.debug(")setAsyncResult"); } }
public void internalSend(RequestToCancel request) { if (log.isDebugEnabled()) { log.debug("internalSend(" + request); } ByteBuffer requestDataBuffer = request.buf; bool isNegotiate = BNegotiate.isNegotiateMessage(requestDataBuffer); bool isJson = isNegotiate || BMessageHeader.detectProtocol(requestDataBuffer) == BMessageHeader.MAGIC_JSON; String destUrl = url; // Negotiate? if (isNegotiate) { // Send a GET request and pass the negotate string as parameter String negoStr = Encoding.UTF8.GetString(requestDataBuffer.array(), requestDataBuffer.position(), requestDataBuffer.remaining()); negoStr = System.Uri.EscapeDataString(negoStr); destUrl = makeUrl(getServletPathForNegotiationAndAuthentication(), new String[] { "negotiate", negoStr }); } // Reverse request (long-poll) ? else if (request.requestDirection == ERequestDirection.REVERSE) { destUrl = makeUrl(getServletPathForReverseRequest(), null); } HttpWebRequest conn = (HttpWebRequest)HttpWebRequest.Create(destUrl); request.setConnection(conn); conn.Method = isNegotiate ? "GET" : "POST"; conn.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; // Content-Type for POST request if (!isNegotiate) { conn.ContentType = isJson ? "application/json" : "application/byps"; } conn.Accept = "application/json, application/byps, text/plain, text/html"; // BYPS-36: Accept GZIP for both, json and byps conn.Headers.Add("Accept-Encoding", "gzip"); applySession(conn); IAsyncResult asyncResult = null; if (isNegotiate) { asyncResult = conn.BeginGetResponse(new AsyncCallback(this.getResponseCallback), request); } else { asyncResult = conn.BeginGetRequestStream(new AsyncCallback(this.getRequestStreamCallback), request); } request.startTimeoutWatcher(conn, asyncResult, request.timeoutMillisRequest); if (log.isDebugEnabled()) { log.debug(")internalSend"); } }