/// <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); }
private void PrepareResponseHeaders(ref ITransportHeaders headers, GiopServerConnection con) { if (headers == null) { headers = new TransportHeaders(); } headers[GiopServerConnection.SERVER_TR_HEADER_KEY] = con; }
private void ProcessRequestInternal(Stream requestStream, GiopServerConnection serverCon) { #if DEBUG OutputHelper.LogStream(requestStream); #endif requestStream.Seek(0, SeekOrigin.Begin); // assure stream is read from beginning in formatter // the out params returned form later sinks IMessage responseMsg; ITransportHeaders responseHeaders; Stream responseStream; // create the sink stack for async processing of message ServerChannelSinkStack sinkStack = new ServerChannelSinkStack(); sinkStack.Push(this, serverCon); // empty transport headers for this protocol ITransportHeaders requestHeaders = new TransportHeaders(); requestHeaders[GiopServerConnection.SERVER_TR_HEADER_KEY] = serverCon; requestHeaders[CommonTransportKeys.IPAddress] = serverCon.TransportHandler.GetPeerAddress(); // next sink will process the request-message ServerProcessing result = NextChannelSink.ProcessMessage(sinkStack, null, /* no RequestMessage in transport handler */ requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream); switch (result) { case ServerProcessing.Complete: try { sinkStack.Pop(this); } catch (Exception) { } #if DEBUG Debug.WriteLine("Send response sync"); OutputHelper.LogStream(responseStream); #endif serverCon.TransportHandler.SendResponse(responseStream); break; case ServerProcessing.Async: sinkStack.StoreAndDispatch(this, serverCon); // this sink wants to handle response // no reply, async break; case ServerProcessing.OneWay: try { sinkStack.Pop(this); } catch (Exception) { } // no message to send break; default: // should not arrive here Trace.WriteLine("internal problem, invalid processing state: " + result); throw new omg.org.CORBA.INTERNAL(568, omg.org.CORBA.CompletionStatus.Completed_MayBe); } }
/// <summary>serialises an Exception as GIOP reply message</summary> private void SerialiseExceptionResponse(IServerResponseChannelSinkStack sinkStack, IMessage requestMsg, GiopServerConnection con, IMessage responseMsg, ref ITransportHeaders headers, out Stream stream) { // serialise an exception response headers = new TransportHeaders(); SerialiseResponse(sinkStack, requestMsg, con, responseMsg, ref headers, out stream); }
/// <summary>serialises the .NET msg to a GIOP reply message</summary> private void SerialiseResponse(IServerResponseChannelSinkStack sinkStack, IMessage requestMsg, GiopServerConnection con, IMessage responseMsg, ref ITransportHeaders headers, out Stream stream) { GiopVersion version = (GiopVersion)requestMsg.Properties[SimpleGiopMsg.GIOP_VERSION_KEY]; PrepareResponseHeaders(ref headers, con); // get the stream into which the message should be serialied from a stream handling // sink in the stream handling chain stream = GetResponseStreamFor(sinkStack, responseMsg, headers); m_messageHandler.SerialiseOutgoingReplyMessage(responseMsg, requestMsg, version, stream, con.ConDesc); }
/// <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; }
public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream) { responseMsg = null; responseHeaders = null; responseStream = null; CdrMessageInputStream msgInput = new CdrMessageInputStream(requestStream); GiopServerConnection serverCon = (GiopServerConnection) requestHeaders[GiopServerConnection.SERVER_TR_HEADER_KEY]; try { if (msgInput.Header.GiopType == GiopMsgTypes.Request) { return(ProcessRequestMessage(sinkStack, requestHeaders, msgInput, serverCon, out responseMsg, out responseHeaders, out responseStream)); } else if (msgInput.Header.GiopType == GiopMsgTypes.LocateRequest) { return(ProcessLocateRequestMessage(sinkStack, requestHeaders, msgInput, serverCon, out responseMsg, out responseHeaders, out responseStream)); } else { Trace.WriteLine("Processing problem on server connection after unexpected message of type " + msgInput.Header.GiopType); throw new NotSupportedException("wrong message type in server side formatter: " + msgInput.Header.GiopType); } } finally { try { requestStream.Close(); // not needed any more } catch { // ignore } } }
/// <summary> /// process a giop request message. /// </summary> private ServerProcessing ProcessRequestMessage(IServerChannelSinkStack sinkStack, ITransportHeaders requestHeaders, CdrMessageInputStream msgInput, GiopServerConnection serverCon, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream) { IMessage deserReqMsg = null; responseHeaders = null; try { try { // deserialise the request deserReqMsg = m_messageHandler.ParseIncomingRequestMessage(msgInput, serverCon.ConDesc); } finally { //request deserialised -> safe to read next request while processing request in servant // (or sending request deserialisation exception) try { serverCon.NotifyDeserialiseRequestComplete(); } catch (Exception ne) { // unexpected exception. Abort message processing, problem with transport. throw new NotifyReadRequestException("Problem while trying to inform transport about request deserialistion.", ne); } } // processing may be done asynchronous, therefore push this sink on the stack to process a response async AsyncServerProcessingData asyncData = new AsyncServerProcessingData(deserReqMsg, serverCon); sinkStack.Push(this, asyncData); ServerProcessing processingResult; try { // forward the call to the next message handling sink processingResult = m_nextSink.ProcessMessage(sinkStack, deserReqMsg, requestHeaders, null, out responseMsg, out responseHeaders, out responseStream); } catch (Exception) { sinkStack.Pop(this); throw; } switch (processingResult) { case ServerProcessing.Complete: sinkStack.Pop(this); // not async // send the response SerialiseResponse(sinkStack, deserReqMsg, serverCon, responseMsg, ref responseHeaders, out responseStream); break; case ServerProcessing.Async: sinkStack.Store(this, asyncData); // this sink want's to process async response break; case ServerProcessing.OneWay: // nothing to do, because no response expected sinkStack.Pop(this); break; } return(processingResult); } catch (MessageHandling.RequestDeserializationException deserEx) { // exception from DeserialisRequest responseMsg = deserEx.ResponseMessage; // an exception was thrown during deserialization SerialiseExceptionResponse(sinkStack, deserEx.RequestMessage, serverCon, responseMsg, ref responseHeaders, out responseStream); return(ServerProcessing.Complete); } catch (NotifyReadRequestException nrre) { Trace.WriteLine("Failed to inform transport about request deserialisation. Processing problem on server connection after unexpected exception: " + nrre.InnerException); throw nrre; } catch (Exception e) { // serialise an exception response if (deserReqMsg != null) { if (deserReqMsg is IMethodCallMessage) { responseMsg = new ReturnMessage(e, (IMethodCallMessage)deserReqMsg); } else { responseMsg = new ReturnMessage(e, null); // no usable information present } SerialiseExceptionResponse(sinkStack, deserReqMsg, serverCon, responseMsg, ref responseHeaders, out responseStream); } else { throw e; } return(ServerProcessing.Complete); // send back an error msg } }
/// <summary> /// process a giop locate request /// </summary> /// <param name="requestStream">the request stream</param> /// <remarks>is called by GiopTransportMessageHandler</remarks> public void ProcessLocateRequest(Stream requestStream, GiopServerConnection serverCon) { Trace.WriteLine("Process Locate request"); ProcessRequestInternal(requestStream, serverCon); Trace.WriteLine("Locate request processed"); }
internal AsyncServerProcessingData(IMessage reqMsg, GiopServerConnection serverCon) : base(reqMsg, serverCon.ConDesc) { m_serverCon = serverCon; }
/// <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; }
/// <summary> /// process a giop request message. /// </summary> private ServerProcessing ProcessRequestMessage(IServerChannelSinkStack sinkStack, ITransportHeaders requestHeaders, CdrMessageInputStream msgInput, GiopServerConnection serverCon, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream) { IMessage deserReqMsg = null; responseHeaders = null; try { try { // deserialise the request deserReqMsg = m_messageHandler.ParseIncomingRequestMessage(msgInput, serverCon.ConDesc); } finally { //request deserialised -> safe to read next request while processing request in servant // (or sending request deserialisation exception) try { serverCon.NotifyDeserialiseRequestComplete(); } catch (Exception ne) { // unexpected exception. Abort message processing, problem with transport. throw new NotifyReadRequestException("Problem while trying to inform transport about request deserialistion.", ne); } } // processing may be done asynchronous, therefore push this sink on the stack to process a response async AsyncServerProcessingData asyncData = new AsyncServerProcessingData(deserReqMsg, serverCon); sinkStack.Push(this, asyncData); ServerProcessing processingResult; try { // forward the call to the next message handling sink processingResult = m_nextSink.ProcessMessage(sinkStack, deserReqMsg, requestHeaders, null, out responseMsg, out responseHeaders, out responseStream); } catch (Exception) { sinkStack.Pop(this); throw; } switch (processingResult) { case ServerProcessing.Complete: sinkStack.Pop(this); // not async // send the response SerialiseResponse(sinkStack, deserReqMsg, serverCon, responseMsg, ref responseHeaders, out responseStream); break; case ServerProcessing.Async: sinkStack.Store(this, asyncData); // this sink want's to process async response break; case ServerProcessing.OneWay: // nothing to do, because no response expected sinkStack.Pop(this); break; } return processingResult; } catch (MessageHandling.RequestDeserializationException deserEx) { // exception from DeserialisRequest responseMsg = deserEx.ResponseMessage; // an exception was thrown during deserialization SerialiseExceptionResponse(sinkStack, deserEx.RequestMessage, serverCon, responseMsg, ref responseHeaders, out responseStream); return ServerProcessing.Complete; } catch (NotifyReadRequestException nrre) { Trace.WriteLine("Failed to inform transport about request deserialisation. Processing problem on server connection after unexpected exception: " + nrre.InnerException); throw nrre; } catch (Exception e) { // serialise an exception response if (deserReqMsg != null) { if (deserReqMsg is IMethodCallMessage) { responseMsg = new ReturnMessage(e, (IMethodCallMessage) deserReqMsg); } else { responseMsg = new ReturnMessage(e, null); // no usable information present } SerialiseExceptionResponse(sinkStack, deserReqMsg, serverCon, responseMsg, ref responseHeaders, out responseStream); } else { throw e; } return ServerProcessing.Complete; // send back an error msg } }
private void ProcessRequestInternal(Stream requestStream, GiopServerConnection serverCon) { #if DEBUG OutputHelper.LogStream(requestStream); #endif requestStream.Seek(0, SeekOrigin.Begin); // assure stream is read from beginning in formatter // the out params returned form later sinks IMessage responseMsg; ITransportHeaders responseHeaders; Stream responseStream; // create the sink stack for async processing of message ServerChannelSinkStack sinkStack = new ServerChannelSinkStack(); sinkStack.Push(this, serverCon); // empty transport headers for this protocol ITransportHeaders requestHeaders = new TransportHeaders(); requestHeaders[GiopServerConnection.SERVER_TR_HEADER_KEY] = serverCon; requestHeaders[CommonTransportKeys.IPAddress] = serverCon.TransportHandler.GetPeerAddress(); // next sink will process the request-message ServerProcessing result = NextChannelSink.ProcessMessage(sinkStack, null, /* no RequestMessage in transport handler */ requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream); switch (result) { case ServerProcessing.Complete : try { sinkStack.Pop(this); } catch (Exception) { } #if DEBUG Debug.WriteLine("Send response sync"); OutputHelper.LogStream(responseStream); #endif serverCon.TransportHandler.SendResponse(responseStream); break; case ServerProcessing.Async : sinkStack.StoreAndDispatch(this, serverCon); // this sink wants to handle response // no reply, async break; case ServerProcessing.OneWay : try { sinkStack.Pop(this); } catch (Exception) { } // no message to send break; default: // should not arrive here Trace.WriteLine("internal problem, invalid processing state: " + result); throw new omg.org.CORBA.INTERNAL(568, omg.org.CORBA.CompletionStatus.Completed_MayBe); } }