public override V3Message execute(Request message, RequestContext context) { Object returnValue = null; #if(FULL_BUILD) if (body.body == null) body.body = new object[0]; else if (!body.body.GetType().IsArray) body.body = new object[] { body.body }; try { if (Registry.ServiceRegistry.GetMapping(destination).Equals("*")) destination = source; ThreadContext.getProperties()[ORBConstants.REQUEST_HEADERS] = headers; ThreadContext.getProperties()[ORBConstants.CLIENT_ID] = clientId; returnValue = Invoker.handleInvoke( message, destination, operation, (Object[])( (Object[])body.body )[0], context ); } catch (Exception exception) { return new ErrMessage(messageId, exception); } #endif return new AckMessage(messageId, clientId, returnValue); }
public static void SerializeResponse( Request message, Stream stream ) { IProtocolFormatter formatter = message.GetFormatter(); MessageWriter.writeObject( message, formatter ); ProtocolBytes protocolBytes = formatter.GetBytes(); formatter.Cleanup(); stream.Write( protocolBytes.bytes, 0, protocolBytes.length ); stream.Flush(); }
public IPrincipal CheckCredentials(string userid, string password, Request message) { var user = _userDataAccess.FindByUserNameAndPassword(userid, password); if (user==null) { Error.UserNotFoundException(userid); } return user; }
public override V3Message execute( Request message, RequestContext context ) { String dsId = (String)this.headers["DSId"]; String woId = (String)this.headers["WebORBClientId"]; IDestination destObj = ORBConfig.GetInstance().GetDataServices().GetDestinationManager().GetDestination(destination); if (Log.isLogging(LoggingConstants.INFO)) Log.log(LoggingConstants.INFO, "Delivering message to destination " + destination); if (messageId == null) messageId = Guid.NewGuid().ToString(); if (destObj == null) { String error = "Unknown destination - " + destination + ". Make sure the destination is properly configured."; if (Log.isLogging(LoggingConstants.ERROR)) Log.log(LoggingConstants.ERROR, error); return new ErrMessage(messageId, new Exception(error)); } Object[] bodyParts = (Object[])this.body.body; if( bodyParts != null && bodyParts.Length > 0 ) { for (int i = 0; i < bodyParts.Length; i++) { if (bodyParts[i] is IAdaptingType ) { bodyParts[i] = ((IAdaptingType) bodyParts[i]).defaultAdapt(); } else if (bodyParts[i].GetType().IsArray) { Object[] arrayPart = (Object[]) bodyParts[i]; for (int j = 0; j < arrayPart.Length; j++) { if (arrayPart[j] is IAdaptingType ) arrayPart[j] = ((IAdaptingType) arrayPart[j]).defaultAdapt(); } } } destObj.messagePublished(woId, bodyParts[0]); destObj.GetServiceHandler().AddMessage( (Hashtable)this.headers, this ); } return new AckMessage(messageId, clientId, null, new Hashtable()); }
public override V3Message execute(Request message, RequestContext context) { return null; }
// ********************** DATA TYPE SERIALIZATION *********************** public virtual void BeginWriteMessage( Request message ) { }
public override V3Message execute( Request message, RequestContext context ) { object returnValue = null; switch ( operation ) { case SUBSCRIBE_OPERATION: { IDestination destObj = ORBConfig.GetInstance().GetDataServices().GetDestinationManager().GetDestination(destination); Hashtable headers = new Hashtable(); RTMPConnection connection = (RTMPConnection) ConnectionHub.getConnectionLocal(); if (destObj != null) { String selectorName = (String) this.headers["DSSelector"]; String subtopic = (String) this.headers["DSSubtopic"]; String dsId = connection == null ? (String) this.headers["DSId"] : connection.GetHashCode().ToString(); String channel = (String) this.headers["DSEndpoint"]; Subscriber subscriber = SubscriptionsManager.GetInstance().getSubscriber( Subscriber.buildId(dsId, destObj.GetName(), subtopic, selectorName)); if (clientId == null || clientId.Equals("")) clientId = Guid.NewGuid().ToString().ToUpper(); if (subscriber != null) { if (subscriber.addClient(clientId.ToString())) destObj.GetServiceHandler().HandleSubscribe(subscriber, clientId.ToString(), this); return new AckMessage(messageId, clientId, null, headers); } object wsContext = ThreadContext.getProperties()[ORBConstants.WEB_SOCKET_MODE]; if (wsContext != null) { subscriber = new WebSocketSubscriber(selectorName, destObj, (UserContext) wsContext); } else if (connection != null) { subscriber = new DedicatedSubscriber(selectorName, destObj); subscriber.setChannelId(RTMPHandler.getChannelId()); subscriber.setConnection(connection); } else { subscriber = SubscriberFactory.CreateSubscriber(channel, selectorName, destObj); } subscriber.setDSId(dsId); subscriber.setSubtopic(subtopic); subscriber.addClient((String) clientId); try { SubscriptionsManager.GetInstance().AddSubscriber(dsId, destObj.GetName(), subscriber); } catch (Exception e) { if (Log.isLogging(LoggingConstants.EXCEPTION)) Log.log(LoggingConstants.EXCEPTION, e); } destObj.GetServiceHandler().HandleSubscribe(subscriber, clientId.ToString(), this); } else { String error = "Unknown destination " + destination + ". Cannot handle subscription request"; if (Log.isLogging(LoggingConstants.ERROR)) Log.log(LoggingConstants.ERROR, error); return new ErrMessage(messageId, new Exception(error)); } return new AckMessage(messageId, clientId, null, headers); } break; case UNSUBSCRIBE_OPERATION: { String subtopic = (String) this.headers["DSSubtopic"]; String dsId = (String) this.headers["DSId"]; String selectorName = (String) this.headers["DSSelector"]; RTMPConnection connection = (RTMPConnection) ConnectionHub.getConnectionLocal(); if (connection != null) dsId = connection.GetHashCode().ToString(); Subscriber subscriber = SubscriptionsManager.GetInstance().getSubscriber( Subscriber.buildId(dsId, destination, subtopic, selectorName)); if (subscriber != null) { SubscriptionsManager.GetInstance().unsubscribe(subscriber, clientId.ToString(), this); } } break; case DISCONNECT_OPERATION: { String dsId = (String) this.headers["DSId"]; RTMPConnection connection = (RTMPConnection) ConnectionHub.getConnectionLocal(); if (connection != null) dsId = connection.GetHashCode().ToString(); SubscriptionsManager subscriptionsManager = SubscriptionsManager.GetInstance(); List<Subscriber> subscribers = subscriptionsManager.getSubscribersByDsId(dsId); if (subscribers != null) foreach (Subscriber subscriber in subscribers ) if (subscriber != null) subscriptionsManager.unsubscribe(subscriber, this); subscriptionsManager.removeSubscriber(dsId); } break; case POLL_OPERATION: { String dsId = (String) this.headers["DSId"]; RTMPConnection connection = (RTMPConnection) ConnectionHub.getConnectionLocal(); if (connection != null) dsId = connection.GetHashCode().ToString() + ""; try { WebORBArray<V3Message> messages = new WebORBArray<V3Message>(SubscriptionsManager.GetInstance().getMessages(dsId)); if (messages.Count == 0) return new AckMessage(null, null, null, new Hashtable()); return new CommandMessage(CLIENT_SYNC_OPERATION, messages); } catch (Exception e) { String error = "Invalid client id " + dsId; if (Log.isLogging(LoggingConstants.ERROR)) Log.log(LoggingConstants.ERROR, error, e); return new ErrMessage(messageId, new Exception(error)); } } break; case CLIENT_PING_OPERATION: { Hashtable headers = new Hashtable(); RTMPConnection connection = (RTMPConnection) ConnectionHub.getConnectionLocal(); if (connection != null) headers.Add("DSId", connection.GetHashCode().ToString()); else headers.Add("DSId", Guid.NewGuid().ToString().ToUpper()); return new AckMessage(messageId, clientId, null, headers); } break; case LOGOUT_OPERATION: { ThreadContext.setCallerCredentials(null, null); Thread.CurrentPrincipal = null; } break; case LOGIN_OPERATION: { String credentials = (String) ((IAdaptingType) ((object[]) body.body)[0]).defaultAdapt(); byte[] bytes = Convert.FromBase64String(credentials); credentials = new String(Encoding.UTF8.GetChars(bytes)); IAuthenticationHandler authHandler = ORBConfig.GetInstance().getSecurity().GetAuthenticationHandler(); if (authHandler == null) { ErrMessage errorMessage = new ErrMessage(messageId, new ServiceException("Missing authentication handler")); errorMessage.faultCode = "Client.Authentication"; return errorMessage; } int index = credentials.IndexOf(":"); string userid = null; string password = null; if (index != -1 && index != 0 && index != credentials.Length - 1) { userid = credentials.Substring(0, index); password = credentials.Substring(index + 1); try { IPrincipal principal = authHandler.CheckCredentials(userid, password, message); try { Thread.CurrentPrincipal = principal; ThreadContext.currentHttpContext().User = principal; } catch (Exception exception) { if (Log.isLogging(LoggingConstants.ERROR)) Log.log(LoggingConstants.ERROR, "Unable to set current principal. Make sure your current permission set allows Principal Control", exception); throw exception; } Credentials creds = new Credentials(); creds.userid = userid; creds.password = password; ThreadContext.setCallerCredentials(creds, principal); } catch (Exception exception) { ErrMessage errorMessage = new ErrMessage(messageId, exception); errorMessage.faultCode = "Client.Authentication"; return errorMessage; } } else { ErrMessage errorMessage = new ErrMessage(messageId, new ServiceException("Invalid credentials")); errorMessage.faultCode = "Client.Authentication"; return errorMessage; } } break; } return new AckMessage( messageId, clientId, returnValue, new Hashtable() ); }
public abstract V3Message execute( Request message, RequestContext context );
public override V3Message execute( Request message, RequestContext context ) { //throw new Exception( "AckMessage should never be execution target" ); return this; }
public Request readMessage(Stream input) { FlashorbBinaryReader reader = new FlashorbBinaryReader(input); try { if (Log.isLogging(LoggingConstants.DEBUG)) Log.log(LoggingConstants.DEBUG, "MessageReader:: parsing stream"); int version = reader.ReadUnsignedShort(); int totalHeaders = reader.ReadUnsignedShort(); if (Log.isLogging(LoggingConstants.DEBUG)) Log.log(LoggingConstants.DEBUG, "MessageReader:: parsing message - version: " + version + " totalHeaders: " + totalHeaders); Header[] headers = new Header[totalHeaders]; for (int i = 0; i < totalHeaders; i++) headers[i] = readHeader(reader); int totalBodyParts = reader.ReadUnsignedShort(); if (Log.isLogging(LoggingConstants.DEBUG)) Log.log(LoggingConstants.DEBUG, "MessageReader:: Total body parts: " + totalBodyParts); Body[] bodies = new Body[totalBodyParts]; for (int i = 0; i < totalBodyParts; i++) bodies[i] = readBodyPart(reader); if (Log.isLogging(LoggingConstants.DEBUG)) Log.log(LoggingConstants.DEBUG, "MessageReader:: returning AMFMessage"); Request request = new Request(version, headers, bodies); request.SetFormatter(version == 3 ? (IProtocolFormatter)new AmfV3Formatter() : (IProtocolFormatter)new AmfFormatter()); return request; } catch (Exception exception) { if (Log.isLogging(LoggingConstants.EXCEPTION)) Log.log(LoggingConstants.EXCEPTION, "Exception: " + exception.Message + " StackTrace: " + exception.StackTrace); return null; } }
public string GetProtocolName(Request input) { return "amf" + (int)input.getVersion(); }
public LicenseException( string message, Request requestObject ) : base( message ) { this.requestObject = requestObject; }