class RSence::Plugins::Servlet__

Use the Servlet class to create responders for GET / POST urls.

A Servlet’s public API is accessible like the other plugins directly.

Responding to a URL consists of four phases:

  1. PluginManager calls every {Servlet__#match match} method

  2. The plugins that return true to the {Servlet__#match match} method are queried by their score -method

  3. The matched plugins are sorted by score, lowest score wins. If it’s a draw between equal scores, the choice is randomized.

  4. The {Servlet__#post post} or {Servlet__#get get} method is called, depending on the type of HTTP request.

Extension hooks for server events

These methods are provided as the basic server event hooks:

Extension hooks for REST events

Attributes

info[R]

@return [Hash] The {file:PluginBundleInfo meta-information} of the plugin bundle.

inited[R]

@private State of the plugin.

name[R]

@return [Symbol] The name of the plugin bundle

path[R]

@return [String] The absolute path of the plugin bundle.

Public Class Methods

bundle_type() click to toggle source

@private Class type identifier for the PluginManager. @return [:Servlet]

# File lib/rsence/plugins/servlet.rb, line 41
def self.bundle_type; :Servlet; end
new( bundle_name, bundle_info, bundle_path, plugin_manager ) click to toggle source

@private The constructor should not be accessed from anywhere else than the PluginManager, which does it automatically.

# File lib/rsence/plugins/servlet.rb, line 44
def initialize( bundle_name, bundle_info, bundle_path, plugin_manager )
  @info    = bundle_info
  @name    = bundle_name
  @path    = bundle_path
  @plugins = plugin_manager
  register
  @inited = false
end

Public Instance Methods

get( req, res, ses ) click to toggle source

Extend to do any GET request processing. Not doing anything by default.

@param [Request] req The HTTP Request object. @param [Response] res The HTTP Response object. @param [Hash] ses The session object, not implemented yet.

# File lib/rsence/plugins/servlet.rb, line 97
def get( req, res, ses ); end
match( uri, request_type=:get ) click to toggle source

Extend to return true for the certain uri and request_type conditions your servlet code handles.

@example Handles :get requests that begin with /foo

def match( uri, request_type )
  request_type == :get and uri.start_with?( '/foo' )
end

@param [String] uri The request uri (full “path” of the request url). @param [:get, :post] request_type The type of request. Only :get and :post are handled yet.

@return [true] to match @return [false] to not match. Returns false to everything, if not extended.

# File lib/rsence/plugins/servlet.rb, line 84
def match( uri, request_type=:get ); false; end
Also aliased as: match?
match?( uri, request_type=:get )
Alias for: match
post( req, res, ses ) click to toggle source

Extend to do any POST request processing. Not doing anything by default.

@param [Request] req The HTTP Request object. @param [Response] res The HTTP Response object. @param [Hash] ses The session object, not implemented yet.

# File lib/rsence/plugins/servlet.rb, line 104
def post( req, res, ses ); end
register() click to toggle source

@private Used by PluginManager to register the plugin

# File lib/rsence/plugins/servlet.rb, line 67
def register
  @plugins.register_bundle( self, @name )
  @inited = true
end
score() click to toggle source

If matched, returns score where lower is better. Score is needed for priority sorting, when several Servlet’s {#match} are returning true for the same request.

@return [Number]

# File lib/rsence/plugins/servlet.rb, line 90
def score; 100; end