/// <summary> /// allows to install a receiver when ready to process messages. /// </summary> /// <param name="serverThreadsMaxPerConnection"> /// the maximum number of server threads used for processing requests on a multiplexed client connection. /// </param> /// <remarks>used for standalone server side and used for bidirectional communication.</remarks> internal void InstallReceiver(IGiopRequestMessageReceiver receiver, GiopConnectionDesc receiverConDesc, int serverThreadsMaxPerConnection) { lock (this) { if (m_reiceivedRequestDispatcher == null) { m_reiceivedRequestDispatcher = new GiopReceivedRequestMessageDispatcher(receiver, this, receiverConDesc, serverThreadsMaxPerConnection); } } }
private bool IsBidirConnectionAlreadyRegistered(string conKey, GiopConnectionDesc receivedOnDesc) { IList known = (IList)m_bidirConnections[conKey]; if (known != null) { foreach (GiopClientConnection con in known) { if (con.Desc.TransportHandler == receivedOnDesc.TransportHandler) { return(true); // received on same transport handler to the same target -> same connection. } } } return(false); }
/// <summary>creates a giop transport message handler, which accept request messages by delegating to receiver</summary> /// <param name="serverThreadsMaxPerConnection"> /// the maximum number of server threads used for processing requests on a multiplexed client connection. /// </param> internal GiopReceivedRequestMessageDispatcher(IGiopRequestMessageReceiver receiver, GiopTransportMessageHandler msgHandler, GiopConnectionDesc conDesc, int serverThreadsMaxPerConnection) { m_serverCon = new GiopServerConnection(conDesc, this); if (receiver != null) { m_receiver = receiver; } else { throw new BAD_PARAM(400, CompletionStatus.Completed_MayBe); } m_msgHandler = msgHandler; if (serverThreadsMaxPerConnection < 1) { throw new BAD_PARAM(401, CompletionStatus.Completed_MayBe); } m_maxRequestsAllowedInParallel = serverThreadsMaxPerConnection; }
/// <summary>registeres connections from received listen points. Those connections /// can be used for callbacks.</summary> /// <remarks>for use case (1)</remarks> internal void RegisterBidirectionalConnection(GiopConnectionDesc receivedOnDesc, Array receivedListenPoints) { // ask transport factory to create the connection key for the listenPoints for (int i = 0; i < receivedListenPoints.Length; i++) { string conKey = m_transportFactory.GetEndPointKeyForBidirEndpoint(receivedListenPoints.GetValue(i)); if (conKey != null) { lock (this) { if (!IsBidirConnectionAlreadyRegistered(conKey, receivedOnDesc)) { // new / different connection for listen-point GiopBidirInitiatedConnection connection = new GiopBidirInitiatedConnection(conKey, receivedOnDesc.TransportHandler, this); Trace.WriteLine(String.Format("register bidirectional connection to {0}", conKey)); IList cons = (IList)m_bidirConnections[conKey]; if (cons == null) { cons = new ArrayList(); m_bidirConnections[conKey] = cons; } cons.Add(connection); RegisterConnection(conKey, connection); // register the new connection SetConnectionAvailable(conKey, connection); } else { Trace.WriteLine(String.Format("received listen points for already registered bidirectional connection to {0}", conKey)); } } } } }
/// <summary> /// allows to install a receiver when ready to process messages. /// </summary> /// <param name="serverThreadsMaxPerConnection"> /// the maximum number of server threads used for processing requests on a multiplexed client connection. /// </param> /// <remarks>used for standalone server side and used for bidirectional communication.</remarks> internal void InstallReceiver(IGiopRequestMessageReceiver receiver, GiopConnectionDesc receiverConDesc, int serverThreadsMaxPerConnection) { lock(this) { if (m_reiceivedRequestDispatcher == null) { m_reiceivedRequestDispatcher = new GiopReceivedRequestMessageDispatcher(receiver, this, receiverConDesc, serverThreadsMaxPerConnection); } } }
public void TestGiopConnectionDescCodeSetNotSetAccess() { GiopConnectionDesc desc = new GiopConnectionDesc(null, null); Assert.IsTrue( !desc.IsCodeSetDefined(), "No codeset user defined at construction time"); try { int charSet = desc.CharSet; Assert.Fail("Expected expection, when accessing charset, although not set"); } catch (INTERNAL) { // expected. } try { int wcharSet = desc.WCharSet; Assert.Fail("Expected expection, when accessing charset, although not set"); } catch (INTERNAL) { // expected. } }
public void TestWCharSetDefinedServer() { byte[] sourceContent = new byte[] { 0, 0, 0, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 116, 101, 115, 116, 117, 114, 105, 0, 0, 0, 0, 12, 69, 99, 104, 111, 87, 83, 116, 114, 105, 110, 103, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 12, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 9, 0, 0, 0, 8, 0, 116, 0, 101, 0, 115, 0, 116}; MemoryStream sourceStream = new MemoryStream(sourceContent); // create a connection context: this is needed for request deserialisation GiopConnectionDesc conDesc = new GiopConnectionDesc(null, null); // go to stream begin sourceStream.Seek(0, SeekOrigin.Begin); GiopMessageBodySerialiser ser = new GiopMessageBodySerialiser( new ArgumentsSerializerFactory(m_serFactory)); CdrInputStreamImpl cdrSourceStream = new CdrInputStreamImpl(sourceStream); cdrSourceStream.ConfigStream(0, new GiopVersion(1, 2)); cdrSourceStream.SetMaxLength((uint)sourceContent.Length); IMessage result = null; TestStringInterfaceImpl service = new TestStringInterfaceImpl(); try { // object which should be called string uri = "testuri"; RemotingServices.Marshal(service, uri); // deserialise request message result = ser.DeserialiseRequest(cdrSourceStream, new GiopVersion(1,2), conDesc, InterceptorManager.EmptyInterceptorOptions); } finally { RemotingServices.Disconnect(service); } // now check if values are correct Assert.IsTrue(result != null, "deserialised message is null"); object[] args = (object[])result.Properties[SimpleGiopMsg.ARGS_KEY]; Assert.IsTrue(args != null, "args is null"); Assert.AreEqual(1, args.Length); Assert.AreEqual("test", args[0]); }
internal AsyncProcessingData(IMessage reqMsg, GiopConnectionDesc conDesc) { m_reqMsg = reqMsg; m_conDesc = conDesc; }
public void TestGiopConnectionDescCodeSetNotSet() { GiopConnectionDesc desc = new GiopConnectionDesc(null, null); Assert.IsTrue( !desc.IsCodeSetNegotiated(), "Codeset not negotiated at construction time"); Assert.IsTrue( !desc.IsCodeSetDefined(), "No codeset user defined at construction time"); }
public void TestReplySerialisation() { // request msg the reply is for MethodInfo methodToCall = typeof(TestService).GetMethod("Add"); object[] args = new object[] { ((Int32) 1), ((Int32) 2) }; string uri = "iiop://localhost:8087/testuri"; // Giop 1.2 will be used because no version spec in uri GiopVersion version = new GiopVersion(1, 2); TestMessage msg = new TestMessage(methodToCall, args, uri); msg.Properties[SimpleGiopMsg.REQUEST_ID_KEY] = (uint)5; msg.Properties[SimpleGiopMsg.GIOP_VERSION_KEY] = version; msg.Properties[SimpleGiopMsg.CALLED_METHOD_KEY] = methodToCall; msg.Properties[SimpleGiopMsg.IDL_METHOD_NAME_KEY] = methodToCall.Name; // done by serialization normally // create a connection context GiopConnectionDesc conDesc = new GiopConnectionDesc(null, null); // create the reply ReturnMessage retMsg = new ReturnMessage((Int32) 3, new object[0], 0, null, msg); MemoryStream targetStream = new MemoryStream(); m_handler.SerialiseOutgoingReplyMessage(retMsg, msg, version, targetStream, conDesc); // check to serialised stream targetStream.Seek(0, SeekOrigin.Begin); CdrInputStreamImpl cdrIn = new CdrInputStreamImpl(targetStream); cdrIn.ConfigStream(0, new GiopVersion(1, 2)); // first is Giop-magic byte data; AssertBytesFollowing(m_giopMagic, cdrIn); // Giop version data = (byte) cdrIn.ReadOctet(); Assert.AreEqual(1, data); data = (byte) cdrIn.ReadOctet(); Assert.AreEqual(2, data); // flags: big-endian, no fragements data = (byte) cdrIn.ReadOctet(); Assert.AreEqual(0, data); // Giop Msg type: reply data = (byte) cdrIn.ReadOctet(); Assert.AreEqual(1, data); // Giop Msg length uint msgLength = cdrIn.ReadULong(); cdrIn.SetMaxLength(msgLength); // req-id Assert.AreEqual(5, cdrIn.ReadULong()); // response status: NO_EXCEPTION Assert.AreEqual(0, cdrIn.ReadULong()); // ignore service contexts SkipServiceContexts(cdrIn); // Giop 1.2, must be aligned on 8 cdrIn.ForceReadAlign(Aligns.Align8); // now return value is following Assert.AreEqual(3, cdrIn.ReadLong()); }
public void TestLocateRequestDeserialisation() { MemoryStream sourceStream = new MemoryStream(); // prepare msg uint requestId = 5; GiopVersion version = new GiopVersion(1, 2); CdrOutputStreamImpl cdrOut = new CdrOutputStreamImpl(sourceStream, 0, version); cdrOut.WriteOpaque(m_giopMagic); // version cdrOut.WriteOctet(version.Major); cdrOut.WriteOctet(version.Minor); // flags cdrOut.WriteOctet(0); // msg-type: request cdrOut.WriteOctet((byte)GiopMsgTypes.LocateRequest); // msg-length cdrOut.WriteULong(22); // request-id cdrOut.WriteULong(requestId); // target: key type cdrOut.WriteULong(0); cdrOut.WriteULong(10); // key length byte[] objectKey = new byte[] { 116, 101, 115, 116, 111, 98, 106, 101, 99, 116 }; // testobject cdrOut.WriteOpaque(objectKey); // create a connection context: this is needed for request deserialisation GiopConnectionDesc conDesc = new GiopConnectionDesc(null, null); // go to stream begin sourceStream.Seek(0, SeekOrigin.Begin); // deserialise request message LocateRequestMessage result = m_handler.ParseIncomingLocateRequestMessage(sourceStream); // now check if values are correct Assert.IsTrue(result != null, "deserialised message is null"); Assert.AreEqual(requestId, result.RequestId); Assert.NotNull(result.ObjectKey); Assert.NotNull(result.TargetUri); Assert.AreEqual("testobject", result.TargetUri); }
/// <summary>registeres connections from received listen points. Those connections /// can be used for callbacks.</summary> /// <remarks>for use case (1)</remarks> internal void RegisterBidirectionalConnection(GiopConnectionDesc receivedOnDesc, Array receivedListenPoints) { // ask transport factory to create the connection key for the listenPoints for (int i = 0; i < receivedListenPoints.Length; i++) { string conKey = m_transportFactory.GetEndPointKeyForBidirEndpoint(receivedListenPoints.GetValue(i)); if (conKey != null) { lock(this) { if (!IsBidirConnectionAlreadyRegistered(conKey, receivedOnDesc)) { // new / different connection for listen-point GiopBidirInitiatedConnection connection = new GiopBidirInitiatedConnection(conKey, receivedOnDesc.TransportHandler, this); Trace.WriteLine(String.Format("register bidirectional connection to {0}", conKey)); IList cons = (IList)m_bidirConnections[conKey]; if (cons == null) { cons = new ArrayList(); m_bidirConnections[conKey] = cons; } cons.Add(connection); RegisterConnection(conKey, connection); // register the new connection SetConnectionAvailable(conKey, connection); } else { Trace.WriteLine(String.Format("received listen points for already registered bidirectional connection to {0}", conKey)); } } } } }
private bool IsBidirConnectionAlreadyRegistered(string conKey, GiopConnectionDesc receivedOnDesc) { IList known = (IList)m_bidirConnections[conKey]; if (known != null) { foreach (GiopClientConnection con in known) { if (con.Desc.TransportHandler == receivedOnDesc.TransportHandler) { return true; // received on same transport handler to the same target -> same connection. } } } return false; }
/// <summary> /// this method handles the incoming messages from one client; /// it's called by the IServerListener /// </summary> private void ProcessClientMessages(IServerTransport transport) { GiopTransportMessageHandler handler = new GiopTransportMessageHandler(transport, m_headerFlags); GiopConnectionDesc conDesc = new GiopConnectionDesc(m_bidirConnectionManager, handler); handler.InstallReceiver(m_transportSink, conDesc, m_serverThreadsMaxPerConnection); handler.ConnectionClosed += new GiopTransportMessageHandler.ConnectionClosedDelegate(EndClientMessages); lock (m_activeClients.SyncRoot) { m_activeClients.Add(handler); Debug.WriteLine("added client; peer addr: " + handler.Transport.GetPeerAddress()); Debug.WriteLine("added client; new number of active: " + m_activeClients.Count); } handler.StartMessageReception(); }
public void TestGiopConnectionDescSetCodeSetNegotiated() { GiopConnectionDesc desc = new GiopConnectionDesc(null, null); desc.SetCodeSetNegotiated(); Assert.IsTrue( desc.IsCodeSetNegotiated(),"Codeset negotiated"); Assert.IsTrue( !desc.IsCodeSetDefined(),"Codeset not user defined"); }
public void TestGiopConnectionDescSetCodeSet() { int charSet = 0x5010001; int wcharSet = 0x10100; GiopConnectionDesc desc = new GiopConnectionDesc(null, null); desc.SetNegotiatedCodeSets(charSet, wcharSet); Assert.IsTrue( desc.IsCodeSetNegotiated(),"Codeset negotiated"); Assert.AreEqual(charSet, desc.CharSet,"char set"); Assert.AreEqual(wcharSet, desc.WCharSet,"wchar set"); Assert.IsTrue(desc.IsCodeSetDefined(),"Codeset user defined"); }
public void TestRequestDeserialisation() { MemoryStream sourceStream = new MemoryStream(); // prepare msg uint requestId = 5; byte responseFlags = 3; string methodName = "Add"; int nrOfArgs = 2; int arg1 = 1; int arg2 = 2; GiopVersion version = new GiopVersion(1, 2); CdrOutputStreamImpl cdrOut = new CdrOutputStreamImpl(sourceStream, 0, version); cdrOut.WriteOpaque(m_giopMagic); // version cdrOut.WriteOctet(version.Major); cdrOut.WriteOctet(version.Minor); // flags cdrOut.WriteOctet(0); // msg-type: request cdrOut.WriteOctet(0); // msg-length cdrOut.WriteULong(68); // request-id cdrOut.WriteULong(requestId); // response-flags cdrOut.WriteOctet(responseFlags); cdrOut.WritePadding(3); // target: key type cdrOut.WriteULong(0); cdrOut.WriteULong(10); // key length cdrOut.WriteOpaque(new byte[] { 116, 101, 115, 116, 111, 98, 106, 101, 99, 116 }); // testobject // method name cdrOut.WriteString(methodName); // no service contexts cdrOut.WriteULong(0); cdrOut.ForceWriteAlign(Aligns.Align8); // parameters cdrOut.WriteLong(arg1); cdrOut.WriteLong(arg2); // create a connection context: this is needed for request deserialisation GiopConnectionDesc conDesc = new GiopConnectionDesc(null, null); // go to stream begin sourceStream.Seek(0, SeekOrigin.Begin); IMessage result = null; TestService service = new TestService(); try { // object which should be called string uri = "testobject"; RemotingServices.Marshal(service, uri); // deserialise request message result = m_handler.ParseIncomingRequestMessage(sourceStream, conDesc); } catch (RequestDeserializationException e) { throw e; } finally { RemotingServices.Disconnect(service); } // now check if values are correct Assert.IsTrue(result != null, "deserialised message is null"); Assert.AreEqual(requestId, result.Properties[SimpleGiopMsg.REQUEST_ID_KEY]); Assert.AreEqual(version, result.Properties[SimpleGiopMsg.GIOP_VERSION_KEY]); Assert.AreEqual(responseFlags, result.Properties[SimpleGiopMsg.RESPONSE_FLAGS_KEY]); Assert.AreEqual("testobject", result.Properties[SimpleGiopMsg.URI_KEY]); Assert.AreEqual("Ch.Elca.Iiop.Tests.TestService", result.Properties[SimpleGiopMsg.TYPENAME_KEY]); Assert.AreEqual(methodName, result.Properties[SimpleGiopMsg.METHODNAME_KEY]); object[] args = (object[])result.Properties[SimpleGiopMsg.ARGS_KEY]; Assert.IsTrue(args != null, "args is null"); Assert.AreEqual(nrOfArgs, args.Length); Assert.AreEqual(arg1, args[0]); Assert.AreEqual(arg2, args[1]); }
public void TestLocateReplySerialisation() { uint requestId = 5; byte[] objectKey = new byte[] { 116, 101, 115, 116, 111, 98, 106, 101, 99, 116 }; // testobject string targetUri = "testobject"; GiopVersion version = new GiopVersion(1, 2); LocateRequestMessage locReq = new LocateRequestMessage(requestId, objectKey, targetUri); // create a connection context GiopConnectionDesc conDesc = new GiopConnectionDesc(null, null); // create the reply LocateStatus replyStatus = LocateStatus.OBJECT_HERE; LocateReplyMessage locReply = new LocateReplyMessage(replyStatus); MemoryStream targetStream = new MemoryStream(); m_handler.SerialiseOutgoingLocateReplyMessage(locReply, locReq, version, targetStream, conDesc); // check to serialised stream targetStream.Seek(0, SeekOrigin.Begin); CdrInputStreamImpl cdrIn = new CdrInputStreamImpl(targetStream); cdrIn.ConfigStream(0, version); // first is Giop-magic byte data; AssertBytesFollowing(m_giopMagic, cdrIn); // Giop version data = (byte) cdrIn.ReadOctet(); Assert.AreEqual(1, data); data = (byte) cdrIn.ReadOctet(); Assert.AreEqual(2, data); // flags: big-endian, no fragements data = (byte) cdrIn.ReadOctet(); Assert.AreEqual(0, data); // Giop Msg type: locate reply data = (byte) cdrIn.ReadOctet(); Assert.AreEqual((byte)GiopMsgTypes.LocateReply, data); // Giop Msg length uint msgLength = cdrIn.ReadULong(); cdrIn.SetMaxLength(msgLength); // req-id Assert.AreEqual(requestId, cdrIn.ReadULong()); // the location status Assert.AreEqual((uint)replyStatus, cdrIn.ReadULong()); }
public void TestWCharSetNotDefinedServer() { byte[] sourceContent = new byte[] { 0, 0, 0, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 116, 101, 115, 116, 117, 114, 105, 0, 0, 0, 0, 12, 69, 99, 104, 111, 87, 83, 116, 114, 105, 110, 103, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 116, 0, 101, 0, 115, 0, 116}; MemoryStream sourceStream = new MemoryStream(sourceContent); // create a connection context: this is needed for request deserialisation GiopConnectionDesc conDesc = new GiopConnectionDesc(null, null); // go to stream begin sourceStream.Seek(0, SeekOrigin.Begin); GiopMessageBodySerialiser ser = new GiopMessageBodySerialiser( new ArgumentsSerializerFactory(m_serFactory)); CdrInputStreamImpl cdrSourceStream = new CdrInputStreamImpl(sourceStream); cdrSourceStream.ConfigStream(0, new GiopVersion(1, 2)); cdrSourceStream.SetMaxLength((uint)sourceContent.Length); IMessage result = null; TestStringInterfaceImpl service = new TestStringInterfaceImpl(); try { // object which should be called string uri = "testuri"; RemotingServices.Marshal(service, uri); // deserialise request message result = ser.DeserialiseRequest(cdrSourceStream, new GiopVersion(1,2), conDesc, InterceptorManager.EmptyInterceptorOptions); Assert.Fail("no exception, although code set not set"); } catch (RequestDeserializationException rde) { Assert.NotNull(rde.Reason, "rde inner exception"); Assert.AreEqual(typeof(BAD_PARAM), rde.Reason.GetType(), "rde type"); } finally { RemotingServices.Disconnect(service); } }
internal GiopServerConnection(GiopConnectionDesc conDesc, GiopReceivedRequestMessageDispatcher msgDispatcher) { m_conDesc = conDesc; m_msgDispatcher = msgDispatcher; }