* lib/soap/**/*.rb, lib/wsdl/**/*.rb, lib/xsd/**/*.rb: changed license; GPL2 -> Ruby's.
* lib/soap/rpc/driver.rb, lib/soap/wsdlDriver.rb, lib/soap/streamHandler.rb: add interface to streamhandler.
* lib/soap/marshal.rb: raise error if parse fails.
* lib/soap/netHttpClient.rb: add https support. Patched by Oliver M. Bolzer.
* lib/soap/netHttpClient.rb: dump HTTP response message body by itself.
* lib/soap/rpc/driver.rb, lib/soap/rpc/proxy.rb, lib/soap/wsdlDriver.rb: add driver#mandatorycharset interface to foce using charset for parsing response from buggy server.
* lib/soap/encodingstyle/soapHandler.rb: support Apache Axis's half typed multi-ref array.
* lib/soap/mapping/factory.rb, lib/soap/mapping/registry.rb: map SOAPStruct which has multi-accessors which name are the same, to an array.
* lib/soap/rpc/element.rb: fixed illegal parameter order.
* lib/soap/rpc/element.rb: element name of response message could have the name other than 'return'.
* lib/wsdl/operation.rb, lib/wsdl/operationBinding.rb, lib/wsdl/soap/classDefCreator.rb, lib/wsdl/soap/methodDefCreator.rb, lib/wsdl/soap/methodDefCreatorSupport.rb: WSDL/1.1 allows plural fault definition in a operation. [ruby-talk:84948]
* test/wsdl/multiplefault.wsdl, test/wsdl/test_multiplefault.rb: add test for above fix.
* lib/wsdl/soap/complexType.rb: support WSDL array definition with maxOccures="unbound".
* lib/xsd/charset.rb: use cp932 under emx. Patched by Siena. / SHINAGAWA, Norihide in [ruby-dev:21972]
* lib/xsd/xmlparser/parser.rb: set @charset nil by default. Nil means 'follow encoding declaration in XML'.
* sample/soap/digraph.rb, sample/wsdl/amazon/wsdlDriver.rb, sample/wsdl/googleSearch/sampleClient.rb, sample/wsdl/googleSearch/wsdlDriver.rb, test/wsdl/test_emptycomplextype.rb, test/wsdl/marshal/test_wsdlmarshal.rb, test/xsd/test_xmlschemaparser.rb: use File.open(...) { |f| f.read } instead of File.open(...).read. [ruby-dev:21964]
* test/wsdl/emptycomplextype.wsdl, test/wsdl/test_emptycomplextype.rb: simplify the test case.
* test/wsdl/axisArray/*: add tests for axis's array encoding.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-25 02:31:33 -05:00
|
|
|
# SOAP4R - SOAP handler servlet for WEBrick
|
2004-07-03 09:33:20 -04:00
|
|
|
# Copyright (C) 2001, 2002, 2003, 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
* lib/soap/**/*.rb, lib/wsdl/**/*.rb, lib/xsd/**/*.rb: changed license; GPL2 -> Ruby's.
* lib/soap/rpc/driver.rb, lib/soap/wsdlDriver.rb, lib/soap/streamHandler.rb: add interface to streamhandler.
* lib/soap/marshal.rb: raise error if parse fails.
* lib/soap/netHttpClient.rb: add https support. Patched by Oliver M. Bolzer.
* lib/soap/netHttpClient.rb: dump HTTP response message body by itself.
* lib/soap/rpc/driver.rb, lib/soap/rpc/proxy.rb, lib/soap/wsdlDriver.rb: add driver#mandatorycharset interface to foce using charset for parsing response from buggy server.
* lib/soap/encodingstyle/soapHandler.rb: support Apache Axis's half typed multi-ref array.
* lib/soap/mapping/factory.rb, lib/soap/mapping/registry.rb: map SOAPStruct which has multi-accessors which name are the same, to an array.
* lib/soap/rpc/element.rb: fixed illegal parameter order.
* lib/soap/rpc/element.rb: element name of response message could have the name other than 'return'.
* lib/wsdl/operation.rb, lib/wsdl/operationBinding.rb, lib/wsdl/soap/classDefCreator.rb, lib/wsdl/soap/methodDefCreator.rb, lib/wsdl/soap/methodDefCreatorSupport.rb: WSDL/1.1 allows plural fault definition in a operation. [ruby-talk:84948]
* test/wsdl/multiplefault.wsdl, test/wsdl/test_multiplefault.rb: add test for above fix.
* lib/wsdl/soap/complexType.rb: support WSDL array definition with maxOccures="unbound".
* lib/xsd/charset.rb: use cp932 under emx. Patched by Siena. / SHINAGAWA, Norihide in [ruby-dev:21972]
* lib/xsd/xmlparser/parser.rb: set @charset nil by default. Nil means 'follow encoding declaration in XML'.
* sample/soap/digraph.rb, sample/wsdl/amazon/wsdlDriver.rb, sample/wsdl/googleSearch/sampleClient.rb, sample/wsdl/googleSearch/wsdlDriver.rb, test/wsdl/test_emptycomplextype.rb, test/wsdl/marshal/test_wsdlmarshal.rb, test/xsd/test_xmlschemaparser.rb: use File.open(...) { |f| f.read } instead of File.open(...).read. [ruby-dev:21964]
* test/wsdl/emptycomplextype.wsdl, test/wsdl/test_emptycomplextype.rb: simplify the test case.
* test/wsdl/axisArray/*: add tests for axis's array encoding.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-25 02:31:33 -05:00
|
|
|
|
|
|
|
# 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;
|
|
|
|
# either the dual license version in 2003, or any later version.
|
2003-09-24 11:18:44 -04:00
|
|
|
|
|
|
|
|
|
|
|
require 'webrick/httpservlet/abstract'
|
|
|
|
require 'webrick/httpstatus'
|
|
|
|
require 'soap/rpc/router'
|
|
|
|
require 'soap/streamHandler'
|
|
|
|
|
|
|
|
module SOAP
|
|
|
|
module RPC
|
|
|
|
|
|
|
|
|
|
|
|
class SOAPlet < WEBrick::HTTPServlet::AbstractServlet
|
|
|
|
public
|
|
|
|
attr_reader :app_scope_router
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@router_map = {}
|
|
|
|
@app_scope_router = ::SOAP::RPC::Router.new(self.class.name)
|
2004-07-03 09:33:20 -04:00
|
|
|
@headerhandlerfactory = []
|
|
|
|
@app_scope_headerhandler = nil
|
2003-09-24 11:18:44 -04:00
|
|
|
end
|
|
|
|
|
2004-07-03 09:33:20 -04:00
|
|
|
# Add servant factory whose object has request scope. A servant object is
|
|
|
|
# instanciated for each request.
|
2003-09-24 11:18:44 -04:00
|
|
|
#
|
2004-07-03 09:33:20 -04:00
|
|
|
# Bear in mind that servant factories are distinguished by HTTP SOAPAction
|
2003-09-24 11:18:44 -04:00
|
|
|
# header in request. Client which calls request-scoped servant must have a
|
2004-07-03 09:33:20 -04:00
|
|
|
# SOAPAction header which is a namespace of the servant factory.
|
2003-09-24 11:18:44 -04:00
|
|
|
# I mean, use Driver#add_method_with_soapaction instead of Driver#add_method
|
|
|
|
# at client side.
|
|
|
|
#
|
2004-07-03 09:33:20 -04:00
|
|
|
# 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
|
2003-09-24 11:18:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Add servant object which has application scope.
|
|
|
|
def add_rpc_servant(obj, namespace)
|
|
|
|
router = @app_scope_router
|
|
|
|
SOAPlet.add_servant_to_router(router, obj, namespace)
|
|
|
|
add_router(namespace, router)
|
|
|
|
end
|
|
|
|
alias add_servant add_rpc_servant
|
|
|
|
|
2004-07-03 09:33:20 -04:00
|
|
|
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
|
2003-09-24 11:18:44 -04:00
|
|
|
|
|
|
|
###
|
|
|
|
## Servlet interfaces for WEBrick.
|
|
|
|
#
|
|
|
|
def get_instance(config, *options)
|
|
|
|
@config = config
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def require_path_info?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def do_GET(req, res)
|
|
|
|
res.header['Allow'] = 'POST'
|
|
|
|
raise WEBrick::HTTPStatus::MethodNotAllowed, "GET request not allowed."
|
|
|
|
end
|
|
|
|
|
|
|
|
def do_POST(req, res)
|
|
|
|
namespace = parse_soapaction(req.meta_vars['HTTP_SOAPACTION'])
|
|
|
|
router = lookup_router(namespace)
|
2004-07-03 09:33:20 -04:00
|
|
|
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)
|
* import soap4r/1.5.2;
* lib/soap/{attachment.rb,baseData.rb,encodingstyle/soapHandler.rb}:
introduce SOAPExternalReference class as a referenct to SOAPEnvelope
external content.
* lib/soap/{attachment.rb,mimemessage.rb}: great SwA (SOAP messages
with Attachments) support code by Jamie Herre.
* lib/soap/{element.rb,marshal.rb,parser.rb,processor.rb,
streamHandler.rb,wsdlDriver.rb}: SwA support.
* lib/soap/rpc/{cgistub.rb,driver.rb,element.rb,proxy.rb,router.rb,
soaplet.rb}: SwA support and refactoring.
* lib/soap/generator.rb, lib/soap/mapping/mapping.rb: follow
SOAPReference#initialize signature change.
* lib/soap/mapping/factory.rb: deleted unused methods.
* lib/soap/mapping/rubytypeFactory.rb: do no ignore case while xsi:type
string <-> Ruby class name matching.
* lib/xsd/datatypes.rb: check the smallest positive non-zero
single-precision float exactly instead of packing with "f".
[ruby-talk:88822]
* test/soap/test_basetype.rb, test/xsd/test_xsd.rb: use 1.402e-45, not
1.4e-45. 1.4e-45 is smaller than 2 ** -149...
* test/soap/test_basetype.rb, test/soap/marshal/test_marshal.rb,
test/xsd/test_xsd.rb: use "(-1.0 / (1.0 / 0.0))" instead of "-0.0".
* test/soap/test_streamhandler.rb: revert to the previous test that
warns "basic_auth unsupported under net/http".
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-01-05 21:20:51 -05:00
|
|
|
res.status = WEBrick::HTTPStatus::RC_INTERNAL_SERVER_ERROR
|
2004-07-03 09:33:20 -04:00
|
|
|
res.body = conn_data.send_string
|
|
|
|
res['content-type'] = conn_data.send_contenttype || "text/xml"
|
* import soap4r/1.5.2;
* lib/soap/{attachment.rb,baseData.rb,encodingstyle/soapHandler.rb}:
introduce SOAPExternalReference class as a referenct to SOAPEnvelope
external content.
* lib/soap/{attachment.rb,mimemessage.rb}: great SwA (SOAP messages
with Attachments) support code by Jamie Herre.
* lib/soap/{element.rb,marshal.rb,parser.rb,processor.rb,
streamHandler.rb,wsdlDriver.rb}: SwA support.
* lib/soap/rpc/{cgistub.rb,driver.rb,element.rb,proxy.rb,router.rb,
soaplet.rb}: SwA support and refactoring.
* lib/soap/generator.rb, lib/soap/mapping/mapping.rb: follow
SOAPReference#initialize signature change.
* lib/soap/mapping/factory.rb: deleted unused methods.
* lib/soap/mapping/rubytypeFactory.rb: do no ignore case while xsi:type
string <-> Ruby class name matching.
* lib/xsd/datatypes.rb: check the smallest positive non-zero
single-precision float exactly instead of packing with "f".
[ruby-talk:88822]
* test/soap/test_basetype.rb, test/xsd/test_xsd.rb: use 1.402e-45, not
1.4e-45. 1.4e-45 is smaller than 2 ** -149...
* test/soap/test_basetype.rb, test/soap/marshal/test_marshal.rb,
test/xsd/test_xsd.rb: use "(-1.0 / (1.0 / 0.0))" instead of "-0.0".
* test/soap/test_streamhandler.rb: revert to the previous test that
warns "basic_auth unsupported under net/http".
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-01-05 21:20:51 -05:00
|
|
|
end
|
2003-09-24 11:18:44 -04:00
|
|
|
end
|
|
|
|
|
* import soap4r/1.5.2;
* lib/soap/{attachment.rb,baseData.rb,encodingstyle/soapHandler.rb}:
introduce SOAPExternalReference class as a referenct to SOAPEnvelope
external content.
* lib/soap/{attachment.rb,mimemessage.rb}: great SwA (SOAP messages
with Attachments) support code by Jamie Herre.
* lib/soap/{element.rb,marshal.rb,parser.rb,processor.rb,
streamHandler.rb,wsdlDriver.rb}: SwA support.
* lib/soap/rpc/{cgistub.rb,driver.rb,element.rb,proxy.rb,router.rb,
soaplet.rb}: SwA support and refactoring.
* lib/soap/generator.rb, lib/soap/mapping/mapping.rb: follow
SOAPReference#initialize signature change.
* lib/soap/mapping/factory.rb: deleted unused methods.
* lib/soap/mapping/rubytypeFactory.rb: do no ignore case while xsi:type
string <-> Ruby class name matching.
* lib/xsd/datatypes.rb: check the smallest positive non-zero
single-precision float exactly instead of packing with "f".
[ruby-talk:88822]
* test/soap/test_basetype.rb, test/xsd/test_xsd.rb: use 1.402e-45, not
1.4e-45. 1.4e-45 is smaller than 2 ** -149...
* test/soap/test_basetype.rb, test/soap/marshal/test_marshal.rb,
test/xsd/test_xsd.rb: use "(-1.0 / (1.0 / 0.0))" instead of "-0.0".
* test/soap/test_streamhandler.rb: revert to the previous test that
warns "basic_auth unsupported under net/http".
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-01-05 21:20:51 -05:00
|
|
|
if res.body.is_a?(IO)
|
2003-09-24 11:18:44 -04:00
|
|
|
res.chunked = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
class RequestRouter < ::SOAP::RPC::Router
|
2004-07-03 09:33:20 -04:00
|
|
|
attr_accessor :factory
|
|
|
|
|
|
|
|
def initialize(namespace = nil)
|
2003-09-24 11:18:44 -04:00
|
|
|
super(namespace)
|
|
|
|
@namespace = namespace
|
2004-07-03 09:33:20 -04:00
|
|
|
@factory = nil
|
2003-09-24 11:18:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def route(soap_string)
|
2004-07-03 09:33:20 -04:00
|
|
|
obj = @factory.create
|
2003-09-24 11:18:44 -04:00
|
|
|
namespace = self.actor
|
|
|
|
router = ::SOAP::RPC::Router.new(@namespace)
|
|
|
|
SOAPlet.add_servant_to_router(router, obj, namespace)
|
|
|
|
router.route(soap_string)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-07-03 09:33:20 -04:00
|
|
|
def setup_request_router(namespace)
|
|
|
|
router = @router_map[namespace] || RequestRouter.new(namespace)
|
|
|
|
add_router(namespace, router)
|
|
|
|
router
|
|
|
|
end
|
|
|
|
|
2003-09-24 11:18:44 -04:00
|
|
|
def add_router(namespace, router)
|
|
|
|
@router_map[namespace] = router
|
|
|
|
end
|
|
|
|
|
|
|
|
def parse_soapaction(soapaction)
|
|
|
|
if /^"(.*)"$/ =~ soapaction
|
|
|
|
soapaction = $1
|
|
|
|
end
|
|
|
|
if soapaction.empty?
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
soapaction
|
|
|
|
end
|
|
|
|
|
|
|
|
def lookup_router(namespace)
|
|
|
|
if namespace
|
|
|
|
@router_map[namespace] || @app_scope_router
|
|
|
|
else
|
|
|
|
@app_scope_router
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-07-03 09:33:20 -04:00
|
|
|
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
|
|
|
|
|
2003-09-24 11:18:44 -04:00
|
|
|
class << self
|
|
|
|
public
|
|
|
|
def add_servant_to_router(router, obj, namespace)
|
|
|
|
::SOAP::RPC.defined_methods(obj).each do |name|
|
2004-07-03 09:33:20 -04:00
|
|
|
begin
|
|
|
|
add_servant_method_to_router(router, obj, namespace, name)
|
|
|
|
rescue SOAP::RPC::MethodDefinitionError => e
|
|
|
|
p e if $DEBUG
|
|
|
|
end
|
2003-09-24 11:18:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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(
|
2004-07-03 09:33:20 -04:00
|
|
|
(1..method.arity.abs).collect { |i| "p#{ i }" })
|
2003-09-24 11:18:44 -04:00
|
|
|
router.add_method(obj, qname, soapaction, name, param_def)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|