/// <summary> /// reads a locate-request message from the message input stream msgInput /// and formulates an answer. /// </summary> /// <returns></returns> internal Stream SerialiseOutgoingLocateReplyMessage(LocateReplyMessage replyMsg, LocateRequestMessage requestMsg, GiopVersion version, Stream targetStream, GiopConnectionDesc conDesc) { GiopHeader header = new GiopHeader(version.Major, version.Minor, m_headerFlags, GiopMsgTypes.LocateReply); CdrMessageOutputStream msgOutput = new CdrMessageOutputStream(targetStream, header); // serialize the message m_ser.SerialiseLocateReply(msgOutput.GetMessageContentWritingStream(), version, requestMsg.RequestId, replyMsg); msgOutput.CloseStream(); // write to the stream return(targetStream); }
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()); }
/// <summary> /// reads a locate-request message from the message input stream msgInput /// and formulates an answer. /// </summary> /// <returns></returns> internal Stream SerialiseOutgoingLocateReplyMessage(LocateReplyMessage replyMsg, LocateRequestMessage requestMsg, GiopVersion version, Stream targetStream, GiopConnectionDesc conDesc) { GiopHeader header = new GiopHeader(version.Major, version.Minor, m_headerFlags, GiopMsgTypes.LocateReply); CdrMessageOutputStream msgOutput = new CdrMessageOutputStream(targetStream, header); // serialize the message m_ser.SerialiseLocateReply(msgOutput.GetMessageContentWritingStream(), version, requestMsg.RequestId, replyMsg); msgOutput.CloseStream(); // write to the stream return targetStream; }
/// <summary> /// serialises a locate reply message. /// </summary> /// <param name="forwardAddr"> /// specifies the IOR of the object to forward the call to. This parameter must be != null, /// if LocateStatus is OBJECT_FORWARD. /// </param> public void SerialiseLocateReply(CdrOutputStream targetStream, GiopVersion version, uint forRequestId, LocateReplyMessage msg) { targetStream.WriteULong(forRequestId); switch (msg.Status) { case LocateStatus.OBJECT_HERE: targetStream.WriteULong((uint)msg.Status); break; default: Debug.WriteLine("Locate reply status not supported"); throw new NotSupportedException("not supported"); } }
/// <summary> /// process a giop locate request message. /// </summary> private ServerProcessing ProcessLocateRequestMessage(IServerChannelSinkStack sinkStack, ITransportHeaders requestHeaders, CdrMessageInputStream msgInput, GiopServerConnection serverCon, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream) { responseHeaders = null; LocateRequestMessage deserReqMsg = m_messageHandler.ParseIncomingLocateRequestMessage(msgInput); // TODO: dummy implementation, don't check yet LocateReplyMessage response = new LocateReplyMessage(LocateStatus.OBJECT_HERE); responseMsg = response; PrepareResponseHeaders(ref responseHeaders, serverCon); // get the stream into which the message should be serialied from a stream handling // sink in the stream handling chain responseStream = GetResponseStreamFor(sinkStack, responseMsg, responseHeaders); m_messageHandler.SerialiseOutgoingLocateReplyMessage(response, deserReqMsg, msgInput.Header.Version, responseStream, serverCon.ConDesc); return ServerProcessing.Complete; }