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. } }
/// <summary>reads an incoming Giop request-message from the Stream sourceStream</summary> /// <returns>the .NET request message created from this Giop-message</returns> internal IMessage ParseIncomingRequestMessage(Stream sourceStream, GiopConnectionDesc conDesc) { CdrMessageInputStream msgInput = new CdrMessageInputStream(sourceStream); return(ParseIncomingRequestMessage(msgInput, conDesc)); }
/// <summary> /// constructor for the in direction. /// </summary> internal GiopServerRequest(GiopConnectionDesc conDesc, IInterceptionOption[] interceptionOptions) { m_requestMessage = new SimpleGiopMsg(); m_requestCallMessage = null; // not yet created; will be created from requestMessage later. m_replyMessage = null; // not yet available m_conDesc = conDesc; InitalizeForInterception(interceptionOptions); }
/// <summary>reads an incoming Giop request-message from the message input stream msgInput</summary> /// <returns>the .NET request message created from this Giop-message</returns> internal IMessage ParseIncomingRequestMessage(CdrMessageInputStream msgInput, GiopConnectionDesc conDesc) { CdrInputStream msgBody = msgInput.GetMessageContentReadingStream(); // deserialize the message body (the GIOP-request id is included in this message) return(m_ser.DeserialiseRequest(msgBody, msgInput.Header.Version, conDesc, m_interceptionOptions)); }
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 TestGiopConnectionDescSetCodeSetNegotiated() { GiopConnectionDesc desc = new GiopConnectionDesc(null, null); desc.SetCodeSetNegotiated(); Assert.IsTrue( desc.IsCodeSetNegotiated(), "Codeset negotiated"); Assert.IsTrue( !desc.IsCodeSetDefined(), "Codeset not user defined"); }
/// <summary> /// constructor for the out-direction /// </summary> /// <param name="request">the request message, may be null</param> /// <param name="reply">the reply message</param> internal GiopServerRequest(IMessage request, ReturnMessage reply, GiopConnectionDesc conDesc, IInterceptionOption[] interceptionOptions) { if (request is IMethodCallMessage) { m_requestCallMessage = (IMethodCallMessage)request; } m_requestMessage = request; m_replyMessage = reply; m_conDesc = conDesc; InitalizeForInterception(interceptionOptions); }
/// <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()); }
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 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>serialises an outgoing .NET reply Message on server side</summary> internal void SerialiseOutgoingReplyMessage(IMessage replyMsg, IMessage requestMsg, GiopVersion version, Stream targetStream, GiopConnectionDesc conDesc) { if (replyMsg is ReturnMessage) { // write a CORBA response message into the stream targetStream GiopHeader header = new GiopHeader(version.Major, version.Minor, m_headerFlags, GiopMsgTypes.Reply); CdrMessageOutputStream msgOutput = new CdrMessageOutputStream(targetStream, header); GiopServerRequest request = new GiopServerRequest(requestMsg, (ReturnMessage)replyMsg, conDesc, m_interceptionOptions); // serialize the message m_ser.SerialiseReply(request, msgOutput.GetMessageContentWritingStream(), version, conDesc); msgOutput.CloseStream(); // write to the stream } else { throw new NotImplementedException("handling for this type of .NET message is not implemented at the moment, type: " + replyMsg.GetType()); } }
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 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]); }
/// <summary> /// set the codesets for the stream after codeset service descision /// </summary> /// <param name="cdrStream"></param> private void SetCodeSet(CdrOutputStream cdrStream, GiopConnectionDesc conDesc) { if (conDesc.IsCodeSetDefined()) { // set the codeset, if one is chosen cdrStream.CharSet = conDesc.CharSet; cdrStream.WCharSet = conDesc.WCharSet; } // otherwise: use cdrStream default. }
/// <summary>reads an incoming Giop request-message from the message input stream msgInput</summary> /// <returns>the .NET request message created from this Giop-message</returns> internal IMessage ParseIncomingRequestMessage(CdrMessageInputStream msgInput, GiopConnectionDesc conDesc) { CdrInputStream msgBody = msgInput.GetMessageContentReadingStream(); // deserialize the message body (the GIOP-request id is included in this message) return m_ser.DeserialiseRequest(msgBody, msgInput.Header.Version, conDesc, m_interceptionOptions); }
/// <summary>reads an incoming Giop request-message from the Stream sourceStream</summary> /// <returns>the .NET request message created from this Giop-message</returns> internal IMessage ParseIncomingRequestMessage(Stream sourceStream, GiopConnectionDesc conDesc) { CdrMessageInputStream msgInput = new CdrMessageInputStream(sourceStream); return ParseIncomingRequestMessage(msgInput, conDesc); }
internal IMessage DeserialiseReply(CdrInputStream cdrStream, GiopVersion version, GiopClientRequest request, GiopConnectionDesc conDesc) { ServiceContextList cntxColl = null; IMessage response = null; try { if (version.IsBeforeGiop1_2()) { // for GIOP 1.0 / 1.1, the service context is placed here cntxColl = DeserialiseContext(cdrStream); // deserialize the service contexts } cdrStream.ReadULong(); // skip request id, already handled by transport uint responseStatus = cdrStream.ReadULong(); if (!version.IsBeforeGiop1_2()) { // for GIOP 1.2 and later, service context is here cntxColl = DeserialiseContext(cdrStream); // deserialize the service contexts } // set codeset for stream SetCodeSet(cdrStream, conDesc); switch (responseStatus) { case 0 : Trace.WriteLine("deserializing normal reply for methodCall: " + request.MethodToCall); response = DeserialiseNormalReply(cdrStream, version, request); UpdateClientRequestWithReplyData(request, response, cntxColl); request.InterceptReceiveReply(); break; case 1 : Exception userEx = DeserialiseUserException(cdrStream, version); // the error .NET message for this exception is created in the formatter UpdateClientRequestWithReplyData(request, new ReturnMessage(userEx, request.Request), cntxColl); userEx = request.InterceptReceiveException(userEx); response = new ReturnMessage(userEx, request.Request); // definitive exception only available here, because interception chain may change exception break; case 2 : Exception systemEx = DeserialiseSystemError(cdrStream, version); // the error .NET message for this exception is created in the formatter UpdateClientRequestWithReplyData(request, new ReturnMessage(systemEx, request.Request), cntxColl); systemEx = request.InterceptReceiveException(systemEx); response = new ReturnMessage(systemEx, request.Request); // definitive exception only available here, because interception chain may change exception break; case 3 : case 4 : // LOCATION_FORWARD / LOCATION_FORWARD_PERM: // --> deserialise it and return location fwd message response = DeserialiseLocationFwdReply(cdrStream, version, request); UpdateClientRequestWithReplyData(request, response, cntxColl); request.InterceptReceiveOther(); break; default : // deseralization of reply error, unknown reply status: responseStatus // the error .NET message for this exception is created in the formatter throw new MARSHAL(2401, CompletionStatus.Completed_MayBe); } } catch (Exception ex) { Trace.WriteLine("exception while deserialising reply: " + ex); try { cdrStream.SkipRest(); } catch (Exception) { // ignore this one, already problems. } if (!request.IsReplyInterceptionChainCompleted()) { // reply interception chain not yet called for this reply // deserialisation not ok: interception not called; // call interceptors with this exception. request.Reply = new ReturnMessage(ex, request.Request as IMethodCallMessage); Exception newException = request.InterceptReceiveException(ex); // exception may be changed by interception point if (ex != newException) { throw newException; // exception have been changed by interception point } } throw; } return response; }
/// <summary> /// perform code set establishment on the client side /// </summary> protected void PerformCodeSetEstablishmentClient(IIorProfile targetProfile, GiopConnectionDesc conDesc, ServiceContextList cntxColl) { if (targetProfile.Version.IsAfterGiop1_0()) { if (!conDesc.IsCodeSetNegotiated()) { Codec codec = m_codecFactory.create_codec(new Encoding(ENCODING_CDR_ENCAPS.ConstVal, targetProfile.Version.Major, targetProfile.Version.Minor)); object codeSetComponent = CodeSetService.FindCodeSetComponent(targetProfile, codec); if (codeSetComponent != null) { int charSet = CodeSetService.ChooseCharSet((CodeSetComponentData)codeSetComponent); int wcharSet = CodeSetService.ChooseWCharSet((CodeSetComponentData)codeSetComponent); conDesc.SetNegotiatedCodeSets(charSet, wcharSet); } else { conDesc.SetCodeSetNegotiated(); } if (conDesc.IsCodeSetDefined()) { // only insert a codeset service context, if a codeset is selected CodeSetService.InsertCodeSetServiceContext(cntxColl, conDesc.CharSet, conDesc.WCharSet); } } } else { // giop 1.0; don't send code set service context; don't check again conDesc.SetCodeSetNegotiated(); } }
/// <summary> /// Deserialises the Giop Message body for a request /// </summary> /// <param name="cdrStream"></param> /// <param name="version"></param> /// <returns></returns> internal IMessage DeserialiseRequest(CdrInputStream cdrStream, GiopVersion version, GiopConnectionDesc conDesc, IInterceptionOption[] interceptionOptions) { MethodCall methodCallInfo = null; GiopServerRequest serverRequest = new GiopServerRequest(conDesc, interceptionOptions); serverRequest.Version = version; try { ServiceContextList cntxColl = null; if (version.IsBeforeGiop1_2()) { // GIOP 1.0 / 1.1 cntxColl = DeserialiseContext(cdrStream); // Service context deser } // read the request-ID and set it as a message property uint requestId = cdrStream.ReadULong(); serverRequest.RequestId = requestId; Trace.WriteLine("received a message with reqId: " + requestId); // read response-flags: byte respFlags = cdrStream.ReadOctet(); Debug.WriteLine("response-flags: " + respFlags); cdrStream.ReadPadding(3); // read reserved bytes serverRequest.ResponseFlags = respFlags; // decode the target of this request byte[] objectKey; serverRequest.RequestUri = ReadTarget(cdrStream, version, out objectKey); serverRequest.ObjectKey = objectKey; serverRequest.RequestMethodName = cdrStream.ReadString(); Trace.WriteLine("call for .NET object: " + serverRequest.RequestUri + ", methodName: " + serverRequest.RequestMethodName); if (version.IsBeforeGiop1_2()) { // GIOP 1.0 / 1.1 uint principalLength = cdrStream.ReadULong(); cdrStream.ReadOpaque((int)principalLength); } else { cntxColl = DeserialiseContext(cdrStream); // Service context deser } PerformCodeSetEstablishmentServer(version, conDesc, cntxColl); // set codeset for stream SetCodeSet(cdrStream, conDesc); // request header deserialised serverRequest.RequestServiceContext = cntxColl; serverRequest.InterceptReceiveRequestServiceContexts(); serverRequest.SetThreadScopeCurrentFromPICurrent(); // copy request scope picurrent to thread scope pi-current serverRequest.ResolveTargetType(); // determine the .net target object type and check if target object is available ArgumentsSerializer argSer = m_argSerFactory.Create(serverRequest.ServerTypeType); MethodInfo called = argSer.GetMethodInfoFor(serverRequest.RequestMethodName); serverRequest.ResolveCalledMethod(called); // set target method and handle special cases IDictionary contextElements; DeserialiseRequestBody(cdrStream, version, serverRequest, argSer, out contextElements); methodCallInfo = new MethodCall(serverRequest.Request); if (contextElements != null) { AddContextElementsToCallContext(methodCallInfo.LogicalCallContext, contextElements); } serverRequest.UpdateWithFinalRequest(methodCallInfo); serverRequest.InterceptReceiveRequest(); // all information now available return methodCallInfo; } catch (Exception e) { // an Exception encountered during deserialisation try { cdrStream.SkipRest(); // skip rest of the message, to not corrupt the stream } catch (Exception) { // ignore exception here, already an other exception leading to problems } ReturnMessage exceptionResponse; exceptionResponse = new ReturnMessage(e, methodCallInfo); throw new RequestDeserializationException(e, serverRequest.Request, exceptionResponse); // send exception interception point will be called when serialising exception response } }
/// <summary> /// serialises the message body for a GIOP request /// </summary> /// <param name="clientRequest">the giop request Msg</param> /// <param name="targetStream"></param> /// <param name="version">the Giop version to use</param> /// <param name="conDesc">the connection used for this request</param> internal void SerialiseRequest(GiopClientRequest clientRequest, CdrOutputStream targetStream, IIorProfile targetProfile, GiopConnectionDesc conDesc) { Trace.WriteLine(String.Format("serializing request for method {0}; uri {1}; id {2}", clientRequest.MethodToCall, clientRequest.CalledUri, clientRequest.RequestId)); try { clientRequest.SetRequestPICurrentFromThreadScopeCurrent(); // copy from thread scope picurrent before processing request ArgumentsSerializer ser = m_argSerFactory.Create(clientRequest.MethodToCall.DeclaringType); // determine the request method to send string idlRequestName = ser.GetRequestNameFor(clientRequest.MethodToCall); clientRequest.RequestMethodName = idlRequestName; clientRequest.InterceptSendRequest(); GiopVersion version = targetProfile.Version; ServiceContextList cntxColl = clientRequest.RequestServiceContext; // set code-set for the stream PerformCodeSetEstablishmentClient(targetProfile, conDesc, cntxColl); SetCodeSet(targetStream, conDesc); if (version.IsBeforeGiop1_2()) { // for GIOP 1.0 / 1.1 SerialiseContext(targetStream, cntxColl); // service context } targetStream.WriteULong(clientRequest.RequestId); byte responseFlags = 0; if (version.IsBeforeGiop1_2()) { // GIOP 1.0 / 1.1 responseFlags = 1; } else { // reply-expected, no DII-call --> must be 0x03, no reply --> must be 0x00 responseFlags = 3; } if (clientRequest.IsOneWayCall) { responseFlags = 0; } // check if one-way // write response-flags targetStream.WriteOctet(responseFlags); targetStream.WritePadding(3); // reserved bytes WriteTarget(targetStream, targetProfile.ObjectKey, version); // write the target-info targetStream.WriteString(clientRequest.RequestMethodName); // write the method name if (version.IsBeforeGiop1_2()) { // GIOP 1.0 / 1.1 targetStream.WriteULong(0); // no principal } else { // GIOP 1.2 SerialiseContext(targetStream, cntxColl); // service context } SerialiseRequestBody(targetStream, clientRequest, version, ser); } catch (Exception ex) { Debug.WriteLine("exception while serialising request: " + ex); Exception newException = clientRequest.InterceptReceiveException(ex); // interception point may change exception if (newException == ex) { throw; } else { throw newException; // exception has been changed by interception point } } }
/// <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>serialize the GIOP message body of a repsonse message</summary> /// <param name="requestId">the requestId of the request, this response belongs to</param> internal void SerialiseReply(GiopServerRequest request, CdrOutputStream targetStream, GiopVersion version, GiopConnectionDesc conDesc) { Trace.WriteLine("serializing response for method: " + request.GetRequestedMethodNameInternal()); try { bool isExceptionReply = request.IsExceptionReply; Exception exceptionToSend = null; try { request.SetRequestPICurrentFromThreadScopeCurrent(); // copy from thread scope picurrent after processing request by servant // reply interception point if (!request.IsExceptionReply) { request.InterceptSendReply(); } else { exceptionToSend = request.InterceptSendException(request.IdlException); } } catch (Exception ex) { // update the reply with the exception from interception layer isExceptionReply = true; if (SerialiseAsSystemException(ex)) { exceptionToSend = ex; } else { exceptionToSend = new UNKNOWN(300, CompletionStatus.Completed_MayBe); } } ServiceContextList cntxColl = request.ResponseServiceContext; SetCodeSet(targetStream, conDesc); if (version.IsBeforeGiop1_2()) { // for GIOP 1.0 / 1.1 SerialiseContext(targetStream, cntxColl); // serialize the context } targetStream.WriteULong(request.RequestId); if (!isExceptionReply) { Trace.WriteLine("sending normal response to client"); targetStream.WriteULong(0); // reply status ok if (!version.IsBeforeGiop1_2()) { // for GIOP 1.2 and later, service context is here SerialiseContext(targetStream, cntxColl); // serialize the context } // serialize a response to a successful request SerialiseResponseOk(targetStream, request, version); Trace.WriteLine("reply body serialised"); } else { Trace.WriteLine("excpetion to send to client: " + exceptionToSend.GetType()); if (SerialiseAsSystemException(exceptionToSend)) { targetStream.WriteULong(2); // system exception } else if (SerialiseAsUserException(exceptionToSend)) { targetStream.WriteULong(1); // user exception } else { // should not occur targetStream.WriteULong(2); exceptionToSend = new INTERNAL(204, CompletionStatus.Completed_Yes); } if (!version.IsBeforeGiop1_2()) { // for GIOP 1.2 and later, service context is here SerialiseContext(targetStream, cntxColl); // serialize the context } AlignBodyIfNeeded(targetStream, version); if (SerialiseAsSystemException(exceptionToSend)) { SerialiseSystemException(targetStream, exceptionToSend); } else { SerialiseUserException(targetStream, (AbstractUserException)exceptionToSend); } Trace.WriteLine("exception reply serialised"); } } finally { request.ClearThreadScopePICurrent(); // no longer needed, clear afterwards to prevent access to stale data during next requests } }
/// <summary> /// perform code set establishment on the server side /// </summary> protected void PerformCodeSetEstablishmentServer(GiopVersion version, GiopConnectionDesc conDesc, ServiceContextList cntxColl) { if (version.IsAfterGiop1_0()) { if (!conDesc.IsCodeSetNegotiated()) { // check for code set establishment CodeSetServiceContext context = CodeSetService.FindCodeSetServiceContext(cntxColl); if (context != null) { CodeSetService.CheckCodeSetCompatible(context.CharSet, context.WCharSet); conDesc.SetNegotiatedCodeSets(context.CharSet, context.WCharSet); } } } else { conDesc.SetCodeSetNegotiated(); } }