/// <inheritdoc /> public void receive_request(ServerRequestInfo ri) { // FIXME: O código abaixo é necessário porque: // (1) para que informações possam ser colocadas nos slots do PICurrent, // esse tipo de código deve ficar na receive_request_service_contexts. // No entanto, essas informações acabam não ficando disponíveis para a // send_exception. // (2) a send_exception NÃO É CHAMADA caso a exceção seja lançada na // receive_request_service_contexts. A exceção precisa ser lançada aqui. // (3) não é possível colocar o código da send_exception nas // receive_request*, pois é impossível chamar ri.add_reply_service_context // nesses pontos devido a erro do IIOP.Net. try { string reset = ri.get_slot(ChainSlotId) as string; if ((reset != null) && (reset.Equals("reset"))) { throw new NO_PERMISSION(InvalidCredentialCode.ConstVal, CompletionStatus.Completed_No); } } catch (InvalidSlot e) { Logger.Fatal( "Falha ao acessar o slot da credencial para avaliar se um reset deve ser enviado.", e); throw; } Logger.Info(String.Format( "A operação '{0}' será executada.", ri.operation)); }
/// <summary>don't intercept calls for interception control service</summary> private bool MustNonInterceptCall(ServerRequestInfo ri) { return(ri.operation.Equals("IsReceiveSvcContextCalled") || ri.operation.Equals("IsReceiveRequestCalled") || ri.operation.Equals("GetOutPathResult") || ri.operation.Equals("ClearInterceptorHistory")); }
/// <summary> /// 处理Socket发送数据事件 /// </summary> /// <param name="session"></param> /// <param name="requestInfo"></param> private void OnReceived(Session session, ServerRequestInfo requestInfo) { String jsonStr = requestInfo.Data; List <ClientDataEntity> clientDataEntities = JsonConvert.DeserializeObject <List <ClientDataEntity> >(jsonStr); foreach (var clientDataEntity in clientDataEntities) { switch (clientDataEntity.FunctionCode) { case FuncCode.Read: { ReadAsync(session, clientDataEntity).Wait(); break; } case FuncCode.Write: { WriteAsync(session, clientDataEntity).Wait(); break; } case FuncCode.SubScription: { SetSubScriptionAsync(session, clientDataEntities).Wait(); break; } default: break; } } }
private Connection GetDispatcherForRequest(ServerRequestInfo request, AnyCredential credential) { Connection dispatcher = null; string busId = credential.Bus; string loginId = credential.Login; if (Context.OnCallDispatch != null) { dispatcher = Context.OnCallDispatch(Context, busId, loginId, GetObjectUriForObjectKey( request.object_id), request.operation); } if (dispatcher == null) { dispatcher = Context.GetDefaultConnection(); } if ((dispatcher != null) && (!busId.Equals(dispatcher.BusId))) { // se a conexão retornada não pertence ao barramento esperado Logger.Error( String.Format( "A conexão retornada pela callback OnCallDispatch não pertence ao barramento da requisição sendo atendida.")); throw new NO_PERMISSION(UnknownBusCode.ConstVal, CompletionStatus.Completed_No); } return(dispatcher); }
public void send_exception(ServerRequestInfo ri) { if (MustNonInterceptCall(ri)) { return; } m_outPathResult = OutPathResult.Exception; }
public void send_other(ServerRequestInfo ri) { if (MustNonInterceptCall(ri)) { return; } m_outPathResult = OutPathResult.Other; }
public void receive_request(ServerRequestInfo ri) { if (MustNonInterceptCall(ri)) { return; } m_invokedOnInPathReceive = true; }
internal void SetCurrentConnection(Connection conn, ServerRequestInfo ri) { Object guid; SetCurrentConnection(conn, out guid); if (conn != null && guid != null) { ri.set_slot(_connectionIdSlotId, guid); } }
public void receive_request_service_contexts(ServerRequestInfo ri) { if (MustNonInterceptCall(ri)) { return; } m_invokedOnInPathReceiveSvcContext = true; ServiceContext context = ri.get_request_service_context(1000); m_contextReceived = (TestServiceContext)m_codec.decode(context.context_data); }
public void receive_request_service_contexts(ServerRequestInfo ri) { object contextAsObject; try { contextAsObject = ri.get_request_service_context(1000); } catch (BAD_PARAM) { contextAsObject = null; } if (contextAsObject != null) { ServiceContext context = (ServiceContext)contextAsObject; TestServiceContext contextReceived = (TestServiceContext)m_codec.decode(context.context_data); ri.set_slot(m_slotId, contextReceived.TestEntry); } }
public void send_reply(ServerRequestInfo ri) { object testEntryAsObject = ri.get_slot(m_slotId); if (testEntryAsObject != null) { int entryResult = (int)testEntryAsObject; TestServiceContext resultContextEntry = new TestServiceContext(entryResult); ServiceContext context = new ServiceContext(1000, m_codec.encode(resultContextEntry)); ri.add_reply_service_context(context, true); } }
/// <inheritdoc /> public void receive_request_service_contexts(ServerRequestInfo ri) { string interceptedOperation = ri.operation; Logger.Info(String.Format( "A operação '{0}' foi interceptada no servidor.", interceptedOperation)); bool legacyContext; ServiceContext serviceContext = GetContextFromRequestInfo(ri, true, out legacyContext); AnyCredential anyCredential = new AnyCredential(serviceContext, legacyContext); Logger.Debug( String.Format("A operação '{0}' possui credencial. É legada? {1}.", interceptedOperation, anyCredential.Legacy)); ConnectionImpl conn = null; try { conn = GetDispatcherForRequest(ri, anyCredential) as ConnectionImpl; if (conn == null) { Logger.Error( "Sem conexão ao barramento, impossível receber a chamada remota."); throw new NO_PERMISSION(UnknownBusCode.ConstVal, CompletionStatus.Completed_No); } if ((!conn.Legacy) && (anyCredential.Legacy)) { Logger.Error( String.Format( "Chamada negada devido a suporte legado inativo: login {0} operação {1} requestId {2}", anyCredential.Login, interceptedOperation, ri.request_id)); throw new NO_PERMISSION(NoCredentialCode.ConstVal, CompletionStatus.Completed_No); } Context.SetCurrentConnection(conn, ri); conn.ReceiveRequest(ri, anyCredential); } catch (InvalidSlot e) { Logger.Fatal("Falha ao inserir a credencial em seu slot.", e); throw; } finally { if (conn != null) { ri.set_slot(ReceivingConnectionSlotId, conn); } } }
/// <inheritdoc /> public void send_exception(ServerRequestInfo ri) { // esse tratamento precisa ser feito aqui (não é possível na receive_request) por causa de bugs do IIOP.net, descritos em OPENBUS-1677. String interceptedOperation = ri.operation; Logger.Info(String.Format( "O lançamento de uma exceção para a operação '{0}' foi interceptado no servidor.", interceptedOperation), (Exception)ri.sending_exception); NO_PERMISSION ex = ri.sending_exception as NO_PERMISSION; if (ex == null) { return; } if (ex.Minor == InvalidCredentialCode.ConstVal) { try { // pela implementação do IIOP.Net, o ServerRequestInfo da send_exception é // diferente do existente na receive_request. Assim, não podemos passar a // credencial por um slot e então precisamos fazer o unmarshal novamente. ConnectionImpl conn = ri.get_slot(ReceivingConnectionSlotId) as ConnectionImpl; if (conn == null) { Logger.Error( "Sem conexão ao barramento, impossível enviar exceção à chamada remota."); throw new NO_PERMISSION(UnverifiedLoginCode.ConstVal, CompletionStatus.Completed_No); } bool legacyContext; ServiceContext serviceContext = GetContextFromRequestInfo(ri, conn.Legacy, out legacyContext); // credencial é inválida AnyCredential anyCredential = new AnyCredential(serviceContext, legacyContext); Logger.Debug(String.Format( "A operação '{0}' para a qual será lançada a exceção possui credencial. Legada? {1}.", interceptedOperation, anyCredential.Legacy)); conn.SendException(ri, anyCredential); } catch (InvalidSlot e) { Logger.Fatal( "Falha ao acessar o slot da conexão de recebimento para enviar uma exceção.", e); throw; } } }
public void receive_request(ServerRequestInfo ri) { if (MustNonInterceptCall(ri)) { return; } m_invokedOnInPathReceive = true; if (m_throwExceptionInPathReceive != null) { Exception toThrow = m_throwExceptionInPathReceive; m_throwExceptionInPathReceive = null; // clear, to allow next call throw toThrow; } }
public void send_other(ServerRequestInfo ri) { if (MustNonInterceptCall(ri)) { return; } m_outPathResult = OutPathResult.Other; if (m_throwExceptionOutPath != null) { Exception toThrow = m_throwExceptionOutPath; m_throwExceptionOutPath = null; // clear, for next call throw toThrow; } }
public void receive_request(ServerRequestInfo ri) { // modify request scope after copy to the thread scope -> must not be propagated to the thread scope. if (ri.operation == "TestReceiveReqNotChangeThreadScope") { ri.set_slot(m_slotId, 2 * (int)ri.get_slot(m_slotId)); } else if (ri.operation == "TestReceiveReqChangeThreadScope") { ORB orb = OrbServices.GetSingleton(); omg.org.PortableInterceptor.Current current = (omg.org.PortableInterceptor.Current)orb.resolve_initial_references("PICurrent"); current.set_slot(m_slotId, 3 * (int)current.get_slot(m_slotId)); } }
public void send_reply(ServerRequestInfo ri) { if (MustNonInterceptCall(ri)) { return; } m_outPathResult = OutPathResult.Reply; if (m_contextReceived != null) { TestServiceContext resultContextEntry = new TestServiceContext(((TestServiceContext)m_contextReceived).TestEntry); ServiceContext context = new ServiceContext(1000, m_codec.encode(resultContextEntry)); ri.add_reply_service_context(context, true); } }
/// <summary> /// <see cref="omg.org.PortableInterceptor.ServerRequestInterceptor.receive_request_service_contexts"></see> /// </summary> public void receive_request_service_contexts(ServerRequestInfo ri) { object svcCtx = null; try { svcCtx = ri.get_request_service_context(BI_DIR_IIOP.ConstVal); } catch (omg.org.CORBA.BAD_PARAM) { // context not found } if (svcCtx != null) { BiDirIIOPServiceContext receivedCtx = (BiDirIIOPServiceContext)m_codec.decode_value(((ServiceContext)svcCtx).context_data, m_svcContextTypeCode); ServerRequestInfoImpl internalInfo = (ServerRequestInfoImpl)ri; // need access to connection information GiopBidirectionalConnectionManager biDirConManager = (GiopBidirectionalConnectionManager)internalInfo.ConnectionDesc.ConnectionManager; biDirConManager.RegisterBidirectionalConnection(internalInfo.ConnectionDesc, receivedCtx.listen_points); } }
public void send_exception(ServerRequestInfo ri) { }
private void GetChildDirItems(ObjectItem parentItem) { try { string strAddress = string.Empty; if (string.IsNullOrEmpty(strAddress)) { ShowException(string.Format("Server address is empty")); return; } if (parentItem == null) { return; } var parentDir = parentItem.Data as DirInfo; if (parentDir == null) { return; } ServerRequestInfo requestInfo = new ServerRequestInfo(); requestInfo.ServerHost = strAddress; requestInfo.ServerPort = 8009; requestInfo.Command = (int)ServerRequestCommand.GetChildDirectoryList; requestInfo.ListData.Add(parentDir.Path); OperationReturn optReturn = XMLHelper.SeriallizeObject(requestInfo); if (!optReturn.Result) { ShowException(string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return; } WebRequest webRequest = new WebRequest(); webRequest.Session = CurrentApp.Session; webRequest.Code = (int)S1110Codes.GetServerInfo; webRequest.Data = optReturn.Data.ToString(); Service11102Client client = new Service11102Client( WebHelper.CreateBasicHttpBinding(CurrentApp.Session), WebHelper.CreateEndpointAddress( CurrentApp.Session.AppServerInfo, "Service11102")); WebReturn webReturn = null; if (MainPage != null) { MainPage.SetBusy(true, CurrentApp.GetMessageLanguageInfo("004", "Getting server directory information")); } mWorker = new BackgroundWorker(); mWorker.DoWork += (s, de) => { try { webReturn = client.DoOperation(webRequest); client.Close(); } catch (Exception ex) { ShowException(ex.Message); } }; mWorker.RunWorkerCompleted += (s, re) => { mWorker.Dispose(); if (MainPage != null) { MainPage.SetBusy(false, string.Empty); } if (!webReturn.Result) { ShowException(string.Format("WSFail.\t{0}\t{1}", webReturn.Code, webReturn.Message)); return; } if (webReturn.ListData == null) { ShowException(string.Format("ListData is null")); return; } parentItem.Children.Clear(); for (int i = 0; i < webReturn.ListData.Count; i++) { string info = webReturn.ListData[i]; string[] arrInfo = info.Split(new[] { ConstValue.SPLITER_CHAR }, StringSplitOptions.None); if (arrInfo.Length < 2) { continue; } DirInfo dirInfo = new DirInfo(); dirInfo.Name = arrInfo[0]; dirInfo.Path = arrInfo[1]; ObjectItem item = new ObjectItem(); item.Type = S1110Consts.OBJECTITEMTYPE_DIRINFO; item.Name = dirInfo.Name; item.Icon = string.Format("../Themes/Default/UMPS1110/Images/{0}", "folder.png"); item.Description = dirInfo.Path; item.Data = dirInfo; parentItem.AddChild(item); } if (mConfigObject != null) { switch (mConfigObject.ObjectType) { case S1110Consts.RESOURCE_VOICESERVER: case S1110Consts.RESOURCE_NTIDRVPATH: //GetChildFileItems(parentItem); break; } } parentItem.IsExpanded = true; }; mWorker.RunWorkerAsync(); } catch (Exception ex) { ShowException(ex.Message); } }
/// <summary> /// <see cref="omg.org.PortableInterceptor.ServerRequestInterceptor.send_other"></see> /// </summary> public void send_other(ServerRequestInfo ri) { // nothing to do }
/// <summary> /// <see cref="omg.org.PortableInterceptor.ServerRequestInterceptor.send_reply"></see> /// </summary> public void send_reply(ServerRequestInfo ri) { // nothing to do }
/// <summary> /// <see cref="omg.org.PortableInterceptor.ServerRequestInterceptor.receive_request"></see> /// </summary> public void receive_request(ServerRequestInfo ri) { // nothing to do }
private OperationReturn GetServerInformation(ServerRequestInfo request, string sendMessage) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = 0; TcpClient tcpClient = null; SslStream sslStream = null; try { tcpClient = new TcpClient(AddressFamily.InterNetwork); tcpClient.Connect(request.ServerHost, request.ServerPort); sslStream = new SslStream(tcpClient.GetStream(), false, (sender, cert, chain, errs) => true, null); sslStream.AuthenticateAsClient("VoiceCyber.PF", null, SslProtocols.Default, false); sslStream.Write(Encoding.UTF8.GetBytes(sendMessage)); sslStream.Flush(); int intReaded; byte[] buffer = new byte[1024]; string strReturn = string.Empty; int intCount = 0; do { intReaded = sslStream.Read(buffer, 0, 1024); if (intReaded > 0) { string strMessage = Encoding.UTF8.GetString(buffer, 0, intReaded); strReturn += strMessage; if (strReturn.EndsWith(string.Format("{0}End{0}\r\n", ConstValue.SPLITER_CHAR))) { strReturn = strReturn.Substring(0, strReturn.Length - 7); if (strReturn.EndsWith("\r\n")) { strReturn = strReturn.Substring(0, strReturn.Length - 2); } break; } } intCount++; //超时 if (intCount > 100) { optReturn.Result = false; optReturn.Code = Defines.RET_TIMEOUT; optReturn.Message = string.Format("RecieveMessage timeout"); sslStream.Close(); tcpClient.Close(); return(optReturn); } Thread.Sleep(100); } while (intReaded > 0); sslStream.Close(); tcpClient.Close(); if (strReturn.StartsWith("Error")) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = string.Format("Server return error message. Please reference to log for detail"); sslStream.Close(); tcpClient.Close(); return(optReturn); } optReturn.Data = strReturn; } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; } finally { if (sslStream != null) { sslStream.Close(); } if (tcpClient != null) { tcpClient.Close(); } } return(optReturn); }
public void send_other(ServerRequestInfo ri) { }
private OperationReturn SetResourceChanged(ServerRequestInfo request) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = 0; try { List <string> listParams = request.ListData; if (listParams.Count < 1) { optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("Count parameter invalid"); return(optReturn); } string strCount = listParams[0]; int intCount; if (!int.TryParse(strCount, out intCount)) { optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("Parameter count invalid"); return(optReturn); } if (intCount + 1 > listParams.Count) { optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("Count parameter invalid"); return(optReturn); } List <NotifyObjectInfo> listNotifyObjects = new List <NotifyObjectInfo>(); for (int i = 0; i < intCount; i++) { string strServerInfo = listParams[i + 1]; optReturn = XMLHelper.DeserializeObject <NotifyObjectInfo>(strServerInfo); if (!optReturn.Result) { return(optReturn); } NotifyObjectInfo serverInfo = optReturn.Data as NotifyObjectInfo; if (serverInfo == null) { optReturn.Result = false; optReturn.Code = Defines.RET_OBJECT_NULL; optReturn.Message = string.Format("ServerInfo is null"); return(optReturn); } listNotifyObjects.Add(serverInfo); } List <string> listReturn = new List <string>(); //异步模式(过指定的时间超时) List <string> args = new List <string>(); for (int i = 0; i < listNotifyObjects.Count; i++) { args.Add(string.Format("{0}:8009", listNotifyObjects[i].Address)); } if (mService00Helper == null) { mService00Helper = new Service00Helper(); mService00Helper.Debug += mService00Helper_Debug; mService00Helper.Start(); } mService00Helper.HostAddress = request.ServerHost; mService00Helper.HostPort = request.ServerPort; optReturn = mService00Helper.DoOperation(RequestCommand.SET_RESOURCE_CHANGED, args); if (!optReturn.Result) { return(optReturn); } string strMessage = optReturn.Data.ToString(); if (!string.IsNullOrEmpty(strMessage)) { if (strMessage.StartsWith("Error")) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = string.Format("{0}", strMessage); return(optReturn); } optReturn.Message = strMessage; } optReturn.Data = listReturn; } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; } return(optReturn); }
private OperationReturn GetCTIServiceName(ServerRequestInfo request) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = 0; try { List <string> listParams = request.ListData; //ListParams //0 PBX主机地址 if (listParams.Count < 1) { optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("Parameter count invalid"); return(optReturn); } string strPBXAddress = listParams[0]; List <string> listReturn = new List <string>(); //异步模式(过指定的时间超时) List <string> args = new List <string>(); args.Add(strPBXAddress); if (mService00Helper == null) { mService00Helper = new Service00Helper(); mService00Helper.Debug += mService00Helper_Debug; mService00Helper.Start(); } mService00Helper.HostAddress = request.ServerHost; mService00Helper.HostPort = request.ServerPort; optReturn = mService00Helper.DoOperation(RequestCommand.GET_CTI_SERVICENAME, args); if (!optReturn.Result) { return(optReturn); } string strMessage = optReturn.Data.ToString(); if (!string.IsNullOrEmpty(strMessage)) { if (strMessage.StartsWith("Error")) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = string.Format("{0}", strMessage); return(optReturn); } string[] serviceNames = strMessage.Split(new[] { "\r\n" }, StringSplitOptions.None); if (serviceNames.Length > 0) { for (int i = 0; i < serviceNames.Length; i++) { string name = serviceNames[i]; if (string.IsNullOrEmpty(name)) { continue; } string[] arrInfos = name.Split(new[] { ConstValue.SPLITER_CHAR }, StringSplitOptions.None); string strName = string.Empty; if (arrInfos.Length > 0) { strName = arrInfos[0]; } string strInfo = string.Format("{0}", strName); listReturn.Add(strInfo); } } } optReturn.Data = listReturn; } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; } return(optReturn); }
private OperationReturn GetNetworkCardList(ServerRequestInfo request) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = 0; try { List <string> listParams = request.ListData; List <string> listReturn = new List <string>(); //测试: 此处获取的是UMP服务器机器的网卡信息,不是录音服务器的网卡信息 //NetworkInterface[] cards = NetworkInterface.GetAllNetworkInterfaces(); //for (int i = 0; i < cards.Length; i++) //{ // NetworkInterface card = cards[i]; // string info = string.Format("{0}{1}{2}{1}{3}", card.Id, ConstValue.SPLITER_CHAR, card.Name, // card.Description); // listReturn.Add(info); //} //optReturn.Data = listReturn; //异步模式(过指定的时间超时) List <string> args = new List <string>(); if (mService00Helper == null) { mService00Helper = new Service00Helper(); mService00Helper.Debug += mService00Helper_Debug; mService00Helper.Start(); } mService00Helper.HostAddress = request.ServerHost; mService00Helper.HostPort = request.ServerPort; optReturn = mService00Helper.DoOperation(RequestCommand.GET_NETWORK_CARD, args); if (!optReturn.Result) { return(optReturn); } //阻塞模式 //string strSendMessage = string.Format("{0}\r\n", EncryptString("G003")); //optReturn = GetServerInformation(request, strSendMessage); //if (!optReturn.Result) //{ // return optReturn; //} string strMessage = optReturn.Data.ToString(); if (!string.IsNullOrEmpty(strMessage)) { if (strMessage.StartsWith("Error")) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = string.Format("{0}", strMessage); return(optReturn); } string[] cards = strMessage.Split(new[] { "\r\n" }, StringSplitOptions.None); if (cards.Length > 0) { for (int i = 0; i < cards.Length; i++) { string card = cards[i]; if (string.IsNullOrEmpty(card)) { continue; } string[] arrInfos = card.Split(new[] { ConstValue.SPLITER_CHAR }, StringSplitOptions.None); string strDesc = string.Empty; string strID = string.Empty; if (arrInfos.Length > 0) { strDesc = arrInfos[0]; } if (arrInfos.Length > 1) { strID = arrInfos[1]; } string strInfo = string.Format("{0}{1}{2}", strDesc, ConstValue.SPLITER_CHAR, strID); listReturn.Add(strInfo); } } } optReturn.Data = listReturn; } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; } return(optReturn); }
/// <summary> /// <see cref="omg.org.PortableInterceptor.ServerRequestInterceptor.send_exception"></see> /// </summary> public void send_exception(ServerRequestInfo ri) { // nothing to do }
/// <summary>don't intercept calls for interception control service</summary> private bool MustNonInterceptCall(ServerRequestInfo ri) { return ri.operation.Equals("IsReceiveSvcContextCalled") || ri.operation.Equals("IsReceiveRequestCalled") || ri.operation.Equals("GetOutPathResult") || ri.operation.Equals("ClearInterceptorHistory"); }
/// <inheritdoc /> public virtual void send_other(ServerRequestInfo ri) { //Nada a ser feito }