In: |
soap/rpc/soaplet.rb
|
Parent: | WEBrick::HTTPServlet::AbstractServlet |
app_scope_router | [R] |
# File soap/rpc/soaplet.rb, line 143 def add_servant_method_to_router(router, obj, namespace, name) qname = XSD::QName.new(namespace, name) soapaction = nil method = obj.method(name) param_def = ::SOAP::RPC::SOAPMethod.create_param_def( (1..method.arity.abs).collect { |i| "p#{ i }" }) router.add_method(obj, qname, soapaction, name, param_def) end
# File soap/rpc/soaplet.rb, line 137 def add_servant_to_router(router, obj, namespace) ::SOAP::RPC.defined_methods(obj).each do |name| add_servant_method_to_router(router, obj, namespace, name) end end
# File soap/rpc/soaplet.rb, line 22 def initialize @router_map = {} @app_scope_router = ::SOAP::RPC::Router.new(self.class.name) end
Add servant klass whose object has request scope. A servant object is instantiated for each request.
Bare in mind that servant klasses are distinguished by HTTP SOAPAction header in request. Client which calls request-scoped servant must have a SOAPAction header which is a namespace of the servant klass. I mean, use Driver#add_method_with_soapaction instead of Driver#add_method at client side.
# File soap/rpc/soaplet.rb, line 36 def add_rpc_request_servant(klass, namespace, mapping_registry = nil) router = RequestRouter.new(klass, namespace, mapping_registry) add_router(namespace, router) end
Add servant object which has application scope.
# File soap/rpc/soaplet.rb, line 42 def add_rpc_servant(obj, namespace) router = @app_scope_router SOAPlet.add_servant_to_router(router, obj, namespace) add_router(namespace, router) end
# File soap/rpc/soaplet.rb, line 62 def do_GET(req, res) res.header['Allow'] = 'POST' raise WEBrick::HTTPStatus::MethodNotAllowed, "GET request not allowed." end
# File soap/rpc/soaplet.rb, line 67 def do_POST(req, res) namespace = parse_soapaction(req.meta_vars['HTTP_SOAPACTION']) router = lookup_router(namespace) is_fault = false charset = ::SOAP::StreamHandler.parse_media_type(req['content-type']) begin response_stream, is_fault = router.route(req.body, charset) rescue Exception => e response_stream = router.create_fault_response(e) is_fault = true end res.body = response_stream res['content-type'] = "text/xml; charset=\"#{charset}\"" if response_stream.is_a?(IO) res.chunked = true end if is_fault res.status = WEBrick::HTTPStatus::RC_INTERNAL_SERVER_ERROR end end