summaryrefslogtreecommitdiff
path: root/lib/soap/rpc/soaplet.rb
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-03 13:33:20 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-03 13:33:20 +0000
commitdf731e37a1953755edfedd1462995fa824ca22bf (patch)
tree38a98e1b29b3784843ad079fa003790c8f352f58 /lib/soap/rpc/soaplet.rb
parent0d6fa996d9e842fe435308cef68df06bc3596a76 (diff)
* added files:
* lib/soap/header/* * lib/soap/rpc/httpserver.rb * lib/wsdl/soap/cgiStubCreator.rb * lib/wsdl/soap/classDefCreator.rb * lib/wsdl/soap/classDefCreatorSupport.rb * lib/wsdl/soap/clientSkeltonCreator.rb * lib/wsdl/soap/driverCreator.rb * lib/wsdl/soap/mappingRegistryCreator.rb * lib/wsdl/soap/methodDefCreator.rb * lib/wsdl/soap/servantSkeltonCreator.rb * lib/wsdl/soap/standaloneServerStubCreator.rb * lib/wsdl/xmlSchema/enumeration.rb * lib/wsdl/xmlSchema/simpleRestriction.rb * lib/wsdl/xmlSchema/simpleType.rb * lib/xsd/codegen/* * lib/xsd/codegen.rb * sample/soap/authheader/* * sample/soap/raa2.4/* * sample/soap/ssl/* * sample/soap/swa/* * sample/soap/whois.rb * sample/wsdl/raa2.4/* * test/soap/header/* * test/soap/ssl/* * test/soap/struct/* * test/soap/swa/* * test/soap/wsdlDriver/* * test/wsdl/multiplefault.wsdl * test/wsdl/simpletype/* * test/wsdl/test_multiplefault.rb * modified files: * lib/soap/baseData.rb * lib/soap/element.rb * lib/soap/generator.rb * lib/soap/netHttpClient.rb * lib/soap/parser.rb * lib/soap/property.rb * lib/soap/soap.rb * lib/soap/streamHandler.rb * lib/soap/wsdlDriver.rb * lib/soap/wsdlDriver.rb * lib/soap/encodingstyle/handler.rb * lib/soap/encodingstyle/literalHandler.rb * lib/soap/encodingstyle/soapHandler.rb * lib/soap/mapping/factory.rb * lib/soap/mapping/mapping.rb * lib/soap/mapping/registry.rb * lib/soap/mapping/rubytypeFactory.rb * lib/soap/mapping/wsdlRegistry.rb * lib/soap/rpc/cgistub.rb * lib/soap/rpc/driver.rb * lib/soap/rpc/proxy.rb * lib/soap/rpc/router.rb * lib/soap/rpc/soaplet.rb * lib/soap/rpc/standaloneServer.rb * lib/wsdl/data.rb * lib/wsdl/definitions.rb * lib/wsdl/operation.rb * lib/wsdl/parser.rb * lib/wsdl/soap/definitions.rb * lib/wsdl/xmlSchema/complexContent.rb * lib/wsdl/xmlSchema/complexType.rb * lib/wsdl/xmlSchema/data.rb * lib/wsdl/xmlSchema/parser.rb * lib/wsdl/xmlSchema/schema.rb * lib/xsd/datatypes.rb * lib/xsd/qname.rb * sample/soap/sampleStruct/server.rb * sample/wsdl/amazon/AmazonSearch.rb * sample/wsdl/amazon/AmazonSearchDriver.rb * test/soap/test_property.rb * test/soap/calc/test_calc_cgi.rb * test/wsdl/test_emptycomplextype.rb * summary * add SOAP Header mustUnderstand support. * add HTTP client SSL configuration and Cookies support (works completely with http-access2). * add header handler for handling sending/receiving SOAP Header. * map Ruby's anonymous Struct to common SOAP Struct in SOAP Object Model. it caused error. * add WSDL simpleType support to restrict lexical value space. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/soap/rpc/soaplet.rb')
-rw-r--r--lib/soap/rpc/soaplet.rb102
1 files changed, 73 insertions, 29 deletions
diff --git a/lib/soap/rpc/soaplet.rb b/lib/soap/rpc/soaplet.rb
index 7cb5e32375..0c1427acf5 100644
--- a/lib/soap/rpc/soaplet.rb
+++ b/lib/soap/rpc/soaplet.rb
@@ -1,5 +1,5 @@
# SOAP4R - SOAP handler servlet for WEBrick
-# Copyright (C) 2001, 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+# Copyright (C) 2001, 2002, 2003, 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
# redistribute it and/or modify it under the same terms of Ruby's license;
@@ -22,20 +22,28 @@ public
def initialize
@router_map = {}
@app_scope_router = ::SOAP::RPC::Router.new(self.class.name)
+ @headerhandlerfactory = []
+ @app_scope_headerhandler = nil
end
- # Add servant klass whose object has request scope. A servant object is
- # instantiated for each request.
+ # Add servant factory whose object has request scope. A servant object is
+ # instanciated for each request.
#
- # Bare in mind that servant klasses are distinguished by HTTP SOAPAction
+ # Bear in mind that servant factories 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.
+ # SOAPAction header which is a namespace of the servant factory.
# I mean, use Driver#add_method_with_soapaction instead of Driver#add_method
# at client side.
#
- def add_rpc_request_servant(klass, namespace, mapping_registry = nil)
- router = RequestRouter.new(klass, namespace, mapping_registry)
- add_router(namespace, router)
+ # A factory must respond to :create.
+ #
+ def add_rpc_request_servant(factory, namespace, mapping_registry = nil)
+ unless factory.respond_to?(:create)
+ raise TypeError.new("factory must respond to 'create'")
+ end
+ router = setup_request_router(namespace)
+ router.factory = factory
+ router.mapping_registry = mapping_registry
end
# Add servant object which has application scope.
@@ -46,6 +54,17 @@ public
end
alias add_servant add_rpc_servant
+ def add_rpc_request_headerhandler(factory)
+ unless factory.respond_to?(:create)
+ raise TypeError.new("factory must respond to 'create'")
+ end
+ @headerhandlerfactory << factory
+ end
+
+ def add_rpc_headerhandler(obj)
+ @app_scope_headerhandler = obj
+ end
+ alias add_headerhandler add_rpc_headerhandler
###
## Servlet interfaces for WEBrick.
@@ -67,21 +86,23 @@ public
def do_POST(req, res)
namespace = parse_soapaction(req.meta_vars['HTTP_SOAPACTION'])
router = lookup_router(namespace)
- begin
- conn_data = ::SOAP::StreamHandler::ConnectionData.new
- conn_data.receive_string = req.body
- conn_data.receive_contenttype = req['content-type']
- conn_data = router.route(conn_data)
- if conn_data.is_fault
+ with_headerhandler(router) do |router|
+ begin
+ conn_data = ::SOAP::StreamHandler::ConnectionData.new
+ conn_data.receive_string = req.body
+ conn_data.receive_contenttype = req['content-type']
+ conn_data = router.route(conn_data)
+ if conn_data.is_fault
+ res.status = WEBrick::HTTPStatus::RC_INTERNAL_SERVER_ERROR
+ end
+ res.body = conn_data.send_string
+ res['content-type'] = conn_data.send_contenttype
+ rescue Exception => e
+ conn_data = router.create_fault_response(e)
res.status = WEBrick::HTTPStatus::RC_INTERNAL_SERVER_ERROR
+ res.body = conn_data.send_string
+ res['content-type'] = conn_data.send_contenttype || "text/xml"
end
- res.body = conn_data.send_string
- res['content-type'] = conn_data.send_contenttype
- rescue Exception => e
- conn_data = router.create_fault_response(e)
- res.status = WEBrick::HTTPStatus::RC_INTERNAL_SERVER_ERROR
- res.body = conn_data.send_string
- res['content-type'] = conn_data.send_contenttype || "text/xml"
end
if res.body.is_a?(IO)
@@ -92,17 +113,16 @@ public
private
class RequestRouter < ::SOAP::RPC::Router
- def initialize(klass, namespace, mapping_registry = nil)
+ attr_accessor :factory
+
+ def initialize(namespace = nil)
super(namespace)
- if mapping_registry
- self.mapping_registry = mapping_registry
- end
- @klass = klass
@namespace = namespace
+ @factory = nil
end
def route(soap_string)
- obj = @klass.new
+ obj = @factory.create
namespace = self.actor
router = ::SOAP::RPC::Router.new(@namespace)
SOAPlet.add_servant_to_router(router, obj, namespace)
@@ -110,6 +130,12 @@ private
end
end
+ def setup_request_router(namespace)
+ router = @router_map[namespace] || RequestRouter.new(namespace)
+ add_router(namespace, router)
+ router
+ end
+
def add_router(namespace, router)
@router_map[namespace] = router
end
@@ -132,11 +158,29 @@ private
end
end
+ def with_headerhandler(router)
+ if @app_scope_headerhandler and
+ !router.headerhandler.include?(@app_scope_headerhandler)
+ router.headerhandler.add(@app_scope_headerhandler)
+ end
+ handlers = @headerhandlerfactory.collect { |f| f.create }
+ begin
+ handlers.each { |h| router.headerhandler.add(h) }
+ yield(router)
+ ensure
+ handlers.each { |h| router.headerhandler.delete(h) }
+ end
+ end
+
class << self
public
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)
+ begin
+ add_servant_method_to_router(router, obj, namespace, name)
+ rescue SOAP::RPC::MethodDefinitionError => e
+ p e if $DEBUG
+ end
end
end
@@ -145,7 +189,7 @@ private
soapaction = nil
method = obj.method(name)
param_def = ::SOAP::RPC::SOAPMethod.create_param_def(
- (1..method.arity.abs).collect { |i| "p#{ i }" })
+ (1..method.arity.abs).collect { |i| "p#{ i }" })
router.add_method(obj, qname, soapaction, name, param_def)
end
end