protected override void OnElementChanged(ElementChangedEventArgs <HybridWebView> e) { base.OnElementChanged(e); // string url = "https://demo-ipg.comtrust.ae/Payment/PaymentPartner.aspx?lang=en&layout=C0BSTCBLEI"; if (Control == null) { webView = new global::Android.Webkit.WebView(Forms.Context); webView.SetWebViewClient(new FormsWebViewClient(this, FormsWebViewItem)); webView.Settings.JavaScriptEnabled = true;// byte[] post = EncodingUtils.GetBytes("TransactionID=" + Element.transactionID, "BASE64"); webView.PostUrl(Element.Uri, post); webView.Settings.JavaScriptEnabled = true; webView.FocusChange += WebView_FocusChange; webView.ScrollChange += WebView_ScrollChange; webView.LayoutChange += WebView_LayoutChange; SetNativeControl(webView); } if (e.OldElement != null) { Control.RemoveJavascriptInterface("jsBridge"); var hybridWebView = e.OldElement as HybridWebView; hybridWebView.Cleanup(); } if (e.NewElement != null) { Control.AddJavascriptInterface(new JSBridge(this), "jsBridge"); Control.LoadUrl(string.Format("https://", Element.Uri)); InjectJS(JavaScriptFunction); } }
public static Header Authenticate(Credentials credentials, string charset, bool proxy ) { Args.NotNull(credentials, "Credentials"); Args.NotNull(charset, "charset"); StringBuilder tmp = new StringBuilder(); tmp.Append(credentials.GetUserPrincipal().GetName()); tmp.Append(":"); tmp.Append((credentials.GetPassword() == null) ? "null" : credentials.GetPassword ()); byte[] base64password = Base64.EncodeBase64(EncodingUtils.GetBytes(tmp.ToString() , charset), false); CharArrayBuffer buffer = new CharArrayBuffer(32); if (proxy) { buffer.Append(AUTH.ProxyAuthResp); } else { buffer.Append(AUTH.WwwAuthResp); } buffer.Append(": Basic "); buffer.Append(base64password, 0, base64password.Length); return(new BufferedHeader(buffer)); }
/// <summary> /// Produces basic authorization header for the given set of /// <see cref="Apache.Http.Auth.Credentials">Apache.Http.Auth.Credentials</see> /// . /// </summary> /// <param name="credentials">The set of credentials to be used for authentication</param> /// <param name="request">The request being authenticated</param> /// <exception cref="Apache.Http.Auth.InvalidCredentialsException"> /// if authentication /// credentials are not valid or not applicable for this authentication scheme /// </exception> /// <exception cref="Apache.Http.Auth.AuthenticationException"> /// if authorization string cannot /// be generated due to an authentication failure /// </exception> /// <returns>a basic authorization string</returns> public override Header Authenticate(Credentials credentials, IHttpRequest request , HttpContext context) { Args.NotNull(credentials, "Credentials"); Args.NotNull(request, "HTTP request"); StringBuilder tmp = new StringBuilder(); tmp.Append(credentials.GetUserPrincipal().GetName()); tmp.Append(":"); tmp.Append((credentials.GetPassword() == null) ? "null" : credentials.GetPassword ()); byte[] base64password = base64codec.Encode(EncodingUtils.GetBytes(tmp.ToString(), GetCredentialsCharset(request))); CharArrayBuffer buffer = new CharArrayBuffer(32); if (IsProxy()) { buffer.Append(AUTH.ProxyAuthResp); } else { buffer.Append(AUTH.WwwAuthResp); } buffer.Append(": Basic "); buffer.Append(base64password, 0, base64password.Length); return(new BufferedHeader(buffer)); }
public void OnEvent(ReceiveData data, long sequence, bool endOfBatch) { var messageEvent = data; if (messageEvent != null) { if (messageEvent.Message is IControler || messageEvent.RawMsg == null) { return; //neu msg chua dc hoan thien thi ko thuc hien giai ma } IMessage bizData = null; try { string rawStr = EncodingUtils.GetString(messageEvent.RawMsg); bizData = JsonUtils.DeserializeMessage(rawStr); if (Endpoint.IsWriteLogInfo) { LogTo.Info(rawStr); //Ghi toan bo thong tin gia nhan duoc } if (Endpoint.IsWriteLog && bizData != null) { #region Xu ly luu thong tin log msg try { var msgNameBiz = bizData.GetType().ToString(); decimal sizeBiz = (decimal)messageEvent.RawMsg.Length / (1024 * 1024); if (!Endpoint.DicMessageCount.ContainsKey(msgNameBiz)) { Endpoint.DicMessageCount[msgNameBiz] = 0; Endpoint.DicMessageSize[msgNameBiz] = 0; } Endpoint.DicMessageCount[msgNameBiz] += 1; Endpoint.DicMessageSize[msgNameBiz] += sizeBiz; if (!Endpoint.DicMessageCountFull.ContainsKey(msgNameBiz)) { Endpoint.DicMessageCountFull[msgNameBiz] = 0; Endpoint.DicMessageSizeFull[msgNameBiz] = 0; } Endpoint.DicMessageCountFull[msgNameBiz] += 1; Endpoint.DicMessageSizeFull[msgNameBiz] += sizeBiz; // sau 5p se ghi log tong so message gui di var timeCheck = (DateTime.Now - Endpoint.LastCheckCountMsg).TotalSeconds; if (timeCheck > Endpoint.TimeWriteLogMsgReceived) { // sau 5 phut ghi log 1 lan // sau 5 moi ghi log decimal countAll = 0; decimal countSizeAll = 0; decimal count5MinAll = 0; decimal count5MinSizeAll = 0; StringBuilder strDetail = new StringBuilder(); var dicSort = Endpoint.DicMessageSizeFull.OrderBy(s => s.Key); foreach (var keyValue in dicSort) { string msgName = keyValue.Key; decimal sizeForMsg = keyValue.Value; decimal countForMsg = Endpoint.DicMessageCountFull[msgName]; decimal count5Min = 0; if (Endpoint.DicMessageCount.ContainsKey(msgName)) { count5Min = Endpoint.DicMessageCount[msgName]; } decimal byte5Min = 0; if (Endpoint.DicMessageSize.ContainsKey(msgName)) { byte5Min = Endpoint.DicMessageSize[msgName]; } decimal avg5Min = count5Min / Endpoint.TimeWriteLogMsgReceived; countAll += countForMsg; countSizeAll += sizeForMsg; count5MinAll += count5Min; count5MinSizeAll += byte5Min; strDetail.AppendLine(GetLog(msgName, countForMsg, sizeForMsg, count5Min, byte5Min, avg5Min)); } decimal avgAll5Min = count5MinAll / Endpoint.TimeWriteLogMsgReceived; var textLogFull = string.Format( "Total message = {0} with size = {1} MB; In 5min count = {2} and size = {3} MB; avg 5 min = {4} msg/s", countAll, countSizeAll.ToString("#,##0.0000"), count5MinAll, count5MinSizeAll.ToString("#,##0.0000"), avgAll5Min.ToString("#,##0.00")); StringBuilder strBuild = new StringBuilder(); strBuild.AppendLine(string.Format("Thoi diem dang nhap {0}", Endpoint.StartTimeLogin)); strBuild.AppendLine(textLogFull); strBuild.AppendLine("Thong tin chi tiet : "); strBuild.AppendLine(strDetail.ToString()); LogTo.Info(strBuild.ToString()); Endpoint.DicMessageCount = new Dictionary <string, decimal>(); Endpoint.DicMessageSize = new Dictionary <string, decimal>(); Endpoint.LastCheckCountMsg = DateTime.Now; } } catch (Exception ex1) { LogTo.Error(ex1.ToString()); } #endregion } } catch (Exception ex) { LogTo.Error(ex.ToString()); _processor.Send(new JournalMessage() { Tag = messageEvent.DeliveryTag, IsAck = true, }, messageEvent.QueueType); data.SetMessage(messageEvent); return; } if (_isWorker) { switch (messageEvent.QueueType) { case (byte)QueueType.MainQueue: //main queue se co trach nhiem xu ly msg, nen no can danh seq cho cac msg ma no xu ly //tang seq truoc if (_isBStarMode && !bizData.IsNotPersist) { //cap nhat seq vao msg goc de gui di sang replicator var str = JsonUtils.SerializeMessage(bizData); messageEvent.RawMsg = EncodingUtils.GetBytes(str); } break; } } if (!messageEvent.IsObsolate && bizData is PartialMessage) { try { //neu day la msg partial thi thuc hien tong hop lai var pendingMsg = bizData as PartialMessage; //raise event change _processor.ProcessControlerMsg(new NewMessageCommingEvent { Count = pendingMsg.Count, Index = pendingMsg.Index, MsgId = pendingMsg.MainRequestKey }, messageEvent.QueueType); PartialMessageStorage storage; if (_listPending.ContainsKey(pendingMsg.MainRequestKey)) { storage = _listPending[pendingMsg.MainRequestKey]; } else { storage = new PartialMessageStorage(pendingMsg.Count); _listPending[pendingMsg.MainRequestKey] = storage; } bool isFull = storage.Append(pendingMsg.RawMessage, pendingMsg.Index, pendingMsg.Count); if (isFull) { var fullRawStr = storage.GetFullMessge(); IMessage rawFullObj = JsonUtils.DeserializeMessage(fullRawStr); if (Endpoint.IsWriteLog && rawFullObj != null) { #region Xu ly luu thong tin log msg try { var msgNameBiz = rawFullObj.GetType().ToString(); decimal sizeBiz = (decimal)System.Text.ASCIIEncoding.UTF8.GetByteCount(fullRawStr) / (1024 * 1024); if (!Endpoint.DicMessageCount.ContainsKey(msgNameBiz)) { Endpoint.DicMessageCount[msgNameBiz] = 0; Endpoint.DicMessageSize[msgNameBiz] = 0; } Endpoint.DicMessageCount[msgNameBiz] += 1; Endpoint.DicMessageSize[msgNameBiz] += sizeBiz; if (!Endpoint.DicMessageCountFull.ContainsKey(msgNameBiz)) { Endpoint.DicMessageCountFull[msgNameBiz] = 0; Endpoint.DicMessageSizeFull[msgNameBiz] = 0; } Endpoint.DicMessageCountFull[msgNameBiz] += 1; Endpoint.DicMessageSizeFull[msgNameBiz] += sizeBiz; // sau 5p se ghi log tong so message gui di var timeCheck = (DateTime.Now - Endpoint.LastCheckCountMsg).TotalSeconds; if (timeCheck > Endpoint.TimeWriteLogMsgReceived) { // sau 5 phut ghi log 1 lan // sau 5 moi ghi log decimal countAll = 0; decimal countSizeAll = 0; decimal count5MinAll = 0; decimal count5MinSizeAll = 0; StringBuilder strDetail = new StringBuilder(); var dicSort = Endpoint.DicMessageSizeFull.OrderBy(s => s.Key); foreach (var keyValue in dicSort) { string msgName = keyValue.Key; decimal sizeForMsg = keyValue.Value; decimal countForMsg = Endpoint.DicMessageCountFull[msgName]; decimal count5Min = 0; if (Endpoint.DicMessageCount.ContainsKey(msgName)) { count5Min = Endpoint.DicMessageCount[msgName]; } decimal byte5Min = 0; if (Endpoint.DicMessageSize.ContainsKey(msgName)) { byte5Min = Endpoint.DicMessageSize[msgName]; } decimal avg5Min = count5Min / Endpoint.TimeWriteLogMsgReceived; countAll += countForMsg; countSizeAll += sizeForMsg; count5MinAll += count5Min; count5MinSizeAll += byte5Min; strDetail.AppendLine(GetLog(msgName, countForMsg, sizeForMsg, count5Min, byte5Min, avg5Min)); } decimal avgAll5Min = count5MinAll / Endpoint.TimeWriteLogMsgReceived; var textLogFull = string.Format( "Total message = {0} with size = {1} MB; In 5min count = {2} and size = {3} MB; avg 5 min = {4} msg/s", countAll, countSizeAll.ToString("#,##0.0000"), count5MinAll, count5MinSizeAll.ToString("#,##0.0000"), avgAll5Min.ToString("#,##0.00")); StringBuilder strBuild = new StringBuilder(); strBuild.AppendLine(string.Format("Thoi diem dang nhap {0}", Endpoint.StartTimeLogin)); strBuild.AppendLine(textLogFull); strBuild.AppendLine("Thong tin chi tiet : "); strBuild.AppendLine(strDetail.ToString()); LogTo.Info(strBuild.ToString()); Endpoint.DicMessageCount = new Dictionary <string, decimal>(); Endpoint.DicMessageSize = new Dictionary <string, decimal>(); Endpoint.LastCheckCountMsg = DateTime.Now; } } catch (Exception ex1) { LogTo.Error(ex1.ToString()); } #endregion } messageEvent.Message = rawFullObj; storage.Dispose(); _listPending.Remove(pendingMsg.MainRequestKey); } } catch (Exception ex) { //neu phat sinh ra loi thi ghi ra console va thuc hien close network de load lai du lieu. LogTo.Error(ex.ToString()); //neu khong hop le thi canh bao _processor.ProcessControlerMsg(new InvalidMessageSeqEvent(), messageEvent.QueueType); } } else if (!messageEvent.IsObsolate) { messageEvent.Message = bizData; } } data.SetMessage(messageEvent); }
/// <summary>Creates digest-response header as defined in RFC2617.</summary> /// <remarks>Creates digest-response header as defined in RFC2617.</remarks> /// <param name="credentials">User credentials</param> /// <returns>The digest-response as String.</returns> /// <exception cref="Apache.Http.Auth.AuthenticationException"></exception> private Header CreateDigestHeader(Credentials credentials, IHttpRequest request) { string uri = GetParameter("uri"); string realm = GetParameter("realm"); string nonce = GetParameter("nonce"); string opaque = GetParameter("opaque"); string method = GetParameter("methodname"); string algorithm = GetParameter("algorithm"); // If an algorithm is not specified, default to MD5. if (algorithm == null) { algorithm = "MD5"; } ICollection <string> qopset = new HashSet <string>(8); int qop = QopUnknown; string qoplist = GetParameter("qop"); if (qoplist != null) { StringTokenizer tok = new StringTokenizer(qoplist, ","); while (tok.HasMoreTokens()) { string variant = tok.NextToken().Trim(); qopset.AddItem(variant.ToLower(CultureInfo.InvariantCulture)); } if (request is HttpEntityEnclosingRequest && qopset.Contains("auth-int")) { qop = QopAuthInt; } else { if (qopset.Contains("auth")) { qop = QopAuth; } } } else { qop = QopMissing; } if (qop == QopUnknown) { throw new AuthenticationException("None of the qop methods is supported: " + qoplist ); } string charset = GetParameter("charset"); if (charset == null) { charset = "ISO-8859-1"; } string digAlg = algorithm; if (Sharpen.Runtime.EqualsIgnoreCase(digAlg, "MD5-sess")) { digAlg = "MD5"; } MessageDigest digester; try { digester = CreateMessageDigest(digAlg); } catch (UnsupportedDigestAlgorithmException) { throw new AuthenticationException("Unsuppported digest algorithm: " + digAlg); } string uname = credentials.GetUserPrincipal().GetName(); string pwd = credentials.GetPassword(); if (nonce.Equals(this.lastNonce)) { nounceCount++; } else { nounceCount = 1; cnonce = null; lastNonce = nonce; } StringBuilder sb = new StringBuilder(256); Formatter formatter = new Formatter(sb, CultureInfo.InvariantCulture); formatter.Format("%08x", nounceCount); formatter.Close(); string nc = sb.ToString(); if (cnonce == null) { cnonce = CreateCnonce(); } a1 = null; a2 = null; // 3.2.2.2: Calculating digest if (Sharpen.Runtime.EqualsIgnoreCase(algorithm, "MD5-sess")) { // H( unq(username-value) ":" unq(realm-value) ":" passwd ) // ":" unq(nonce-value) // ":" unq(cnonce-value) // calculated one per session sb.Length = 0; sb.Append(uname).Append(':').Append(realm).Append(':').Append(pwd); string checksum = Encode(digester.Digest(EncodingUtils.GetBytes(sb.ToString(), charset ))); sb.Length = 0; sb.Append(checksum).Append(':').Append(nonce).Append(':').Append(cnonce); a1 = sb.ToString(); } else { // unq(username-value) ":" unq(realm-value) ":" passwd sb.Length = 0; sb.Append(uname).Append(':').Append(realm).Append(':').Append(pwd); a1 = sb.ToString(); } string hasha1 = Encode(digester.Digest(EncodingUtils.GetBytes(a1, charset))); if (qop == QopAuth) { // Method ":" digest-uri-value a2 = method + ':' + uri; } else { if (qop == QopAuthInt) { // Method ":" digest-uri-value ":" H(entity-body) HttpEntity entity = null; if (request is HttpEntityEnclosingRequest) { entity = ((HttpEntityEnclosingRequest)request).GetEntity(); } if (entity != null && !entity.IsRepeatable()) { // If the entity is not repeatable, try falling back onto QOP_AUTH if (qopset.Contains("auth")) { qop = QopAuth; a2 = method + ':' + uri; } else { throw new AuthenticationException("Qop auth-int cannot be used with " + "a non-repeatable entity" ); } } else { HttpEntityDigester entityDigester = new HttpEntityDigester(digester); try { if (entity != null) { entity.WriteTo(entityDigester); } entityDigester.Close(); } catch (IOException ex) { throw new AuthenticationException("I/O error reading entity content", ex); } a2 = method + ':' + uri + ':' + Encode(entityDigester.GetDigest()); } } else { a2 = method + ':' + uri; } } string hasha2 = Encode(digester.Digest(EncodingUtils.GetBytes(a2, charset))); // 3.2.2.1 string digestValue; if (qop == QopMissing) { sb.Length = 0; sb.Append(hasha1).Append(':').Append(nonce).Append(':').Append(hasha2); digestValue = sb.ToString(); } else { sb.Length = 0; sb.Append(hasha1).Append(':').Append(nonce).Append(':').Append(nc).Append(':').Append (cnonce).Append(':').Append(qop == QopAuthInt ? "auth-int" : "auth").Append(':') .Append(hasha2); digestValue = sb.ToString(); } string digest = Encode(digester.Digest(EncodingUtils.GetAsciiBytes(digestValue))); CharArrayBuffer buffer = new CharArrayBuffer(128); if (IsProxy()) { buffer.Append(AUTH.ProxyAuthResp); } else { buffer.Append(AUTH.WwwAuthResp); } buffer.Append(": Digest "); IList <BasicNameValuePair> @params = new AList <BasicNameValuePair>(20); @params.AddItem(new BasicNameValuePair("username", uname)); @params.AddItem(new BasicNameValuePair("realm", realm)); @params.AddItem(new BasicNameValuePair("nonce", nonce)); @params.AddItem(new BasicNameValuePair("uri", uri)); @params.AddItem(new BasicNameValuePair("response", digest)); if (qop != QopMissing) { @params.AddItem(new BasicNameValuePair("qop", qop == QopAuthInt ? "auth-int" : "auth" )); @params.AddItem(new BasicNameValuePair("nc", nc)); @params.AddItem(new BasicNameValuePair("cnonce", cnonce)); } // algorithm cannot be null here @params.AddItem(new BasicNameValuePair("algorithm", algorithm)); if (opaque != null) { @params.AddItem(new BasicNameValuePair("opaque", opaque)); } for (int i = 0; i < @params.Count; i++) { BasicNameValuePair param = @params[i]; if (i > 0) { buffer.Append(", "); } string name = param.GetName(); bool noQuotes = ("nc".Equals(name) || "qop".Equals(name) || "algorithm".Equals(name )); BasicHeaderValueFormatter.Instance.FormatNameValuePair(buffer, param, !noQuotes); } return(new BufferedHeader(buffer)); }
public void OnEvent(PublishData data, long sequence, bool endOfBatch) { var messageEvent = data; if (messageEvent == null || messageEvent.ListOutput == null) { return; } foreach (var publishMsg in messageEvent.ListOutput) { if (publishMsg.Message is IControler) { //neu la connect message if (publishMsg.Message is ConnectMessage) { var connectMsg = publishMsg.Message as ConnectMessage; if (connectMsg.StartupMessage != null) { //thuc hien Marshal messase check AutoUpdate var str = JsonUtils.SerializeMessage(connectMsg.StartupMessage); connectMsg.BytesMsg = EncodingUtils.GetBytes(str); publishMsg.Message = connectMsg; } } } else if (publishMsg.Message is IMessage) { if (publishMsg.Message is GetStartupMemoryRequest && _loader != null) { var req = publishMsg.Message as GetStartupMemoryRequest; _loader.ProcessData(ref req); } else { var message = publishMsg.Message as IMessage; publishMsg.IsSendToQueue = message.IsSendToQueue; var jsonStr = JsonUtils.SerializeMessage(message); if (message is Response && jsonStr.Length > _maxSize) { //chi thuc hien chia nho khi msg la response va kich thuoc lon hon kich thuc cho phep List <string> arr = Split(jsonStr, _maxSize); int count = arr.Count; publishMsg.BytesMsg = new List <byte[]>(); for (int i = 0; i < count; i++) { var msg = new PartialMessage() { Count = count, Index = i, MainRequestKey = (message as Response).RequestKey, RawMessage = arr[i], SendingTopic = message.SendingTopic, MainMsgType = message.GetType().ToString(), RequestKey = "", }; var str = JsonUtils.Serialize(msg); byte[] byteMsg = EncodingUtils.GetBytes(str); if (byteMsg == null) { throw new Exception("not parse PartialMessage"); } publishMsg.BytesMsg.Add(byteMsg); } } else { publishMsg.BytesMsg = new List <byte[]>() { EncodingUtils.GetBytes(jsonStr) } }; } } } data.SetMessage(messageEvent); }