public override void Invoke(AMFContext context) { AMFMessage amfMessage = context.AMFMessage; AMFHeader amfHeader = amfMessage.GetHeader(AMFHeader.DebugHeader); if (amfHeader != null) { //The value of the header ASObject asObject = amfHeader.Content as ASObject; //["error"]: {true} //["trace"]: {true} //["httpheaders"]: {false} //["coldfusion"]: {true} //["amf"]: {false} //["m_debug"]: {true} //["amfheaders"]: {false} //["recordset"]: {true} AMFBody amfBody = amfMessage.GetBodyAt(amfMessage.BodyCount - 1); //last body ResponseBody amfBodyOut = new ResponseBody(); amfBodyOut.Target = amfBody.Response + AMFBody.OnDebugEvents; amfBodyOut.Response = null; amfBodyOut.IsDebug = true; ArrayList headerResults = new ArrayList(); ArrayList result = new ArrayList(); headerResults.Add(result); if ((bool)asObject["httpheaders"] == true) { //If the client wants http headers result.Add(new HttpHeader( )); } if ((bool)asObject["amfheaders"] == true) { result.Add(new AMFRequestHeaders(amfMessage)); } ArrayList traceStack = NetDebug.GetTraceStack(); if ((bool)asObject["trace"] == true && traceStack != null && traceStack.Count > 0) { ArrayList tmp = new ArrayList(traceStack); result.Add(new TraceHeader(tmp)); NetDebug.Clear(); } //http://osflash.org/amf/envelopes/remoting/debuginfo amfBodyOut.Content = headerResults; context.MessageOutput.AddBody(amfBodyOut); } NetDebug.Clear(); }
public override void Invoke(AMFContext context) { AMFMessage aMFMessage = context.AMFMessage; AMFHeader header = aMFMessage.GetHeader("amf_server_debug"); if (header != null) { ASObject content = header.Content as ASObject; AMFBody bodyAt = aMFMessage.GetBodyAt(aMFMessage.BodyCount - 1); ResponseBody body = new ResponseBody { Target = bodyAt.Response + "/onDebugEvents", Response = null, IsDebug = true }; ArrayList list = new ArrayList(); ArrayList list2 = new ArrayList(); list.Add(list2); if ((bool)content["httpheaders"]) { list2.Add(new HttpHeader()); } if ((bool)content["amfheaders"]) { list2.Add(new AMFRequestHeaders(aMFMessage)); } ArrayList traceStack = NetDebug.GetTraceStack(); if ((((bool)content["trace"]) && (traceStack != null)) && (traceStack.Count > 0)) { ArrayList list4 = new ArrayList(traceStack); list2.Add(new TraceHeader(list4)); NetDebug.Clear(); } body.Content = list; context.MessageOutput.AddBody(body); } NetDebug.Clear(); }
internal IMessage RouteMessage(IMessage message, IEndpoint endpoint) { IService service = null; object obj2 = null; IMessage errorMessage = null; Exception exception2; CommandMessage message3 = message as CommandMessage; if ((message3 != null) && ((message3.operation == 8) || (message3.operation == 9))) { log.Debug(string.Format("Routing CommandMessage operation = {0}", message3.operation)); try { errorMessage = this.GetService("authentication-service").ServiceMessage(message3) as IMessage; } catch (SecurityException exception) { if (log.get_IsDebugEnabled()) { log.Debug(exception.Message); } errorMessage = ErrorMessage.GetErrorMessage(message, exception); } catch (Exception exception4) { exception2 = exception4; if (log.get_IsErrorEnabled()) { log.Error(__Res.GetString("MessageBroker_RoutingError"), exception2); } errorMessage = ErrorMessage.GetErrorMessage(message, exception2); } } else if ((message3 != null) && (message3.operation == 5)) { log.Debug("Routing CommandMessage ping"); errorMessage = new AcknowledgeMessage { body = true }; } else { log.Debug(string.Format("Routing message {0}", message.GetType().Name)); if (FluorineContext.Current != null) { FluorineContext.Current.RestorePrincipal(this.LoginCommand); } service = this.GetService(message); if (service != null) { try { service.CheckSecurity(message); obj2 = service.ServiceMessage(message); } catch (UnauthorizedAccessException exception3) { if (log.get_IsDebugEnabled()) { log.Debug(exception3.Message); } obj2 = ErrorMessage.GetErrorMessage(message, exception3); } catch (Exception exception6) { exception2 = exception6; if (log.get_IsErrorEnabled()) { log.Error(exception2.Message, exception2); } obj2 = ErrorMessage.GetErrorMessage(message, exception2); } } else { string str = __Res.GetString("Destination_NotFound", new object[] { message.destination }); if (log.get_IsErrorEnabled()) { log.Error(str); } obj2 = ErrorMessage.GetErrorMessage(message, new FluorineException(str)); } if (obj2 is IMessage) { errorMessage = obj2 as IMessage; } else { errorMessage = new AcknowledgeMessage { body = obj2 }; } } if (errorMessage is AsyncMessage) { ((AsyncMessage)errorMessage).correlationId = message.messageId; } errorMessage.destination = message.destination; errorMessage.clientId = message.clientId; if (message.HeaderExists("amf_server_debug")) { log.Debug("MessageBroker processing debug header"); ArrayList traceStack = NetDebug.GetTraceStack(); errorMessage.SetHeader("amf_server_debug", traceStack.ToArray(typeof(object)) as object[]); NetDebug.Clear(); } if ((FluorineContext.Current != null) && (FluorineContext.Current.Client != null)) { errorMessage.SetHeader("DSId", FluorineContext.Current.Client.Id); } return(errorMessage); }
/// <summary> /// Call this method in order to send a message from your code into the message routing system. /// The message is routed to a service that is defined to handle messages of this type. /// Once the service is identified, the destination property of the message is used to find a destination configured for that service. /// The adapter defined for that destination is used to handle the message. /// </summary> /// <param name="message">The message to be routed to a service.</param> /// <param name="endpoint">This can identify the endpoint that is sending the message but it is currently not used so you may pass in null.</param> /// <returns>The result of the message routing.</returns> internal IMessage RouteMessage(IMessage message, IEndpoint endpoint) { IService service = null; object result = null; IMessage responseMessage = null; if (log.IsDebugEnabled) { log.Debug(__Res.GetString(__Res.MessageBroker_RoutingMessage, message.ToString())); } CommandMessage commandMessage = message as CommandMessage; if (commandMessage != null && (commandMessage.operation == CommandMessage.LoginOperation || commandMessage.operation == CommandMessage.LogoutOperation)) //Login, Logout { try { service = GetService(AuthenticationService.ServiceId); result = service.ServiceMessage(commandMessage); responseMessage = result as IMessage; } catch (UnauthorizedAccessException uae) { if (log.IsDebugEnabled) { log.Debug(uae.Message); } responseMessage = ErrorMessage.GetErrorMessage(message, uae); } catch (SecurityException exception) { if (log.IsDebugEnabled) { log.Debug(exception.Message); } responseMessage = ErrorMessage.GetErrorMessage(message, exception); } catch (Exception exception) { if (log.IsErrorEnabled) { log.Error(__Res.GetString(__Res.MessageBroker_RoutingError), exception); } responseMessage = ErrorMessage.GetErrorMessage(message, exception); } } else if (commandMessage != null && commandMessage.operation == CommandMessage.ClientPingOperation) { responseMessage = new AcknowledgeMessage(); responseMessage.body = true; } else { //The only case when context is not set should be when one starts a new thread in the backend //if( FluorineContext.Current != null ) // FluorineContext.Current.RestorePrincipal(this.LoginCommand); _loginManager.RestorePrincipal(); service = GetService(message); if (service != null) { try { service.CheckSecurity(message); result = service.ServiceMessage(message); } catch (UnauthorizedAccessException uae) { if (log.IsDebugEnabled) { log.Debug(uae.Message); } result = ErrorMessage.GetErrorMessage(message, uae); } catch (SecurityException exception) { if (log.IsDebugEnabled) { log.Debug(exception.Message); } result = ErrorMessage.GetErrorMessage(message, exception); } catch (ServiceException exception) { if (log.IsDebugEnabled) { log.Debug(exception.Message); } result = ErrorMessage.GetErrorMessage(message, exception); } catch (Exception exception) { if (log.IsErrorEnabled) { log.Error(exception.Message, exception); } result = ErrorMessage.GetErrorMessage(message, exception); } } else { string msg = __Res.GetString(__Res.Destination_NotFound, message.destination); if (log.IsErrorEnabled) { log.Error(msg); } result = ErrorMessage.GetErrorMessage(message, new FluorineException(msg)); } if (!(result is IMessage)) { responseMessage = new AcknowledgeMessage(); responseMessage.body = result; } else { responseMessage = result as IMessage; } } if (responseMessage is AsyncMessage) { ((AsyncMessage)responseMessage).correlationId = message.messageId; } responseMessage.destination = message.destination; responseMessage.clientId = message.clientId; //Debug if (message.HeaderExists(AMFHeader.DebugHeader)) { log.Debug("MessageBroker processing debug header"); ArrayList traceStack = NetDebug.GetTraceStack(); responseMessage.SetHeader(AMFHeader.DebugHeader, traceStack.ToArray(typeof(object)) as object[]); NetDebug.Clear(); } //The only case when we do not have context should be when the server side initiates a push if (FluorineContext.Current != null && FluorineContext.Current.Client != null) { responseMessage.SetHeader(MessageBase.FlexClientIdHeader, FluorineContext.Current.Client.Id); } if (log.IsDebugEnabled) { log.Debug(__Res.GetString(__Res.MessageBroker_Response, responseMessage.ToString())); } return(responseMessage); }