Class: SipFSMModule::SipFSM
Constant Summary collapse
- FSM_STATE_ATTR =
'sipFSM_STATE'
Class Method Summary collapse
-
.create_request(app_session, method, from, to) ⇒ Object
CLASS methods —————————————————— creates and returns INVITE request.
-
.get_application_session_by_id(app_session_id) ⇒ Object
returns application session.
- .get_attr_const ⇒ Object
-
.get_fsm_state_by_app_id(app_session_id) ⇒ Object
returns sip-fsm state saved in application session attribute.
-
.get_sip_sessions_by_app_id(app_session_id) ⇒ Object
returns all SIP sessions bound to the given application session.
-
.http_get_application_session(http_request, create_flag, key_sufix = "") ⇒ Object
returns sip application session or creates one if flag is true.
Instance Method Summary collapse
-
#doRequest(request) ⇒ Object
Standard SIP servlet request dispatching is overriden and modified to call the DSL event methods.
-
#doResponse(response) ⇒ Object
Standard SIP servlet response dispatching is overriden and modified to call the DSL event methods.
-
#service(req, res) ⇒ Object
Method service is overriden in order to get servlet context.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, args) ⇒ Object (private)
Dynamic methods:
send_response_YYY - for sending response with
the code specified in the method name (send_response_200 etc.)
is_XXX? - check if the SIP request is of type (method) specified in the method name (is_INVITE? etc.)
143 144 145 146 147 148 149 150 151 |
# File 'lib/sipfsm.rb', line 143 def method_missing(name, args) if name.to_s =~ /send_response_(.*)/ args[0].create_response($1.to_i).send elsif name.to_s =~ /is_(.*)\?/ args[0].get_method == $1 else super end end |
Class Method Details
.create_request(app_session, method, from, to) ⇒ Object
CLASS methods —————————————————— creates and returns INVITE request
65 66 67 68 69 70 71 72 |
# File 'lib/sipfsm.rb', line 65 def self.create_request(app_session, method, from, to) sip_factory = $servlet_context.get_attribute('javax.servlet.sip.SipFactory') addr_from = sip_factory.create_address(sip_factory.create_uri(from[:uri]), from[:display_name]) addr_to = sip_factory.create_address(sip_factory.create_uri(to[:uri]), to[:display_name]) req = sip_factory.create_request(app_session, method, addr_from, addr_to); req end |
.get_application_session_by_id(app_session_id) ⇒ Object
returns application session
75 76 77 78 79 |
# File 'lib/sipfsm.rb', line 75 def self.get_application_session_by_id(app_session_id) return nil if !app_session_id util = $servlet_context.get_attribute('javax.servlet.sip.SipSessionsUtil') util.get_application_session_by_id(app_session_id) end |
.get_attr_const ⇒ Object
110 111 112 |
# File 'lib/sipfsm.rb', line 110 def self.get_attr_const FSM_STATE_ATTR end |
.get_fsm_state_by_app_id(app_session_id) ⇒ Object
returns sip-fsm state saved in application session attribute
93 94 95 96 97 98 99 100 101 |
# File 'lib/sipfsm.rb', line 93 def self.get_fsm_state_by_app_id(app_session_id) return nil if !app_session_id app_session = get_application_session_by_id(app_session_id) if app_session app_session.get_attribute(FSM_STATE_ATTR) else nil end end |
.get_sip_sessions_by_app_id(app_session_id) ⇒ Object
returns all SIP sessions bound to the given application session
104 105 106 107 108 |
# File 'lib/sipfsm.rb', line 104 def self.get_sip_sessions_by_app_id(app_session_id) return nil if !app_session_id app_session = get_application_session_by_id(app_session_id) app_session.get_sessions("SIP") end |
.http_get_application_session(http_request, create_flag, key_sufix = "") ⇒ Object
returns sip application session or creates one if flag is true
82 83 84 85 86 87 88 89 90 |
# File 'lib/sipfsm.rb', line 82 def self.http_get_application_session(http_request, create_flag, key_sufix="") # HttpSession <=> ConvergedHttpSession sid = http_request.env['java.servlet_request'].get_session().get_id util = $servlet_context.get_attribute('javax.servlet.sip.SipSessionsUtil') app_key = "sipfsmApp_#{key_sufix}#{sid}" app = util.get_application_session_by_key(app_key, create_flag) app end |
Instance Method Details
#doRequest(request) ⇒ Object
Standard SIP servlet request dispatching is overriden and modified to call the DSL event methods. However, if fsm not defined or fsm does not respond to the given SIP request, standard dispatching still works.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sipfsm.rb', line 26 def doRequest(request) m = request.get_method fsmm = "sip#{m}".to_sym st = run(request) if fsm_state_responds_to? st, fsmm send(fsmm, request, nil) elsif fsm_state_responds_to? st, :sipREQUEST_ANY send(:sipREQUEST_ANY, request, nil) else super end end |
#doResponse(response) ⇒ Object
Standard SIP servlet response dispatching is overriden and modified to call the DSL event methods.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sipfsm.rb', line 42 def doResponse(response) m = response.get_status.to_s st = run(response) resp_exact = "sipRESPONSE_#{m}".to_sym resp_group = "sipRESPONSE_#{m[/./].to_s}xx".to_sym if fsm_state_responds_to? st, resp_exact send(resp_exact, nil, response) elsif fsm_state_responds_to? st, resp_group send(resp_group, nil, response) elsif fsm_state_responds_to? st, :sipRESPONSE_ANY send(:sipRESPONSE_ANY, nil, response) else super end end |
#service(req, res) ⇒ Object
Method service is overriden in order to get servlet context. Then the service method of the Java base class is called.
17 18 19 20 21 |
# File 'lib/sipfsm.rb', line 17 def service(req, res) msg = req || res $servlet_context = msg.session.servlet_context if !$servlet_context super end |