1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/soap/rpc/proxy.rb
nahi df731e37a1 * 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
2004-07-03 13:33:20 +00:00

171 lines
4.4 KiB
Ruby

# SOAP4R - RPC Proxy library.
# Copyright (C) 2000, 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;
# either the dual license version in 2003, or any later version.
require 'soap/soap'
require 'soap/processor'
require 'soap/mapping'
require 'soap/rpc/rpc'
require 'soap/rpc/element'
require 'soap/streamHandler'
require 'soap/mimemessage'
module SOAP
module RPC
class Proxy
include SOAP
public
attr_accessor :soapaction
attr_accessor :mandatorycharset
attr_accessor :allow_unqualified_element
attr_accessor :default_encodingstyle
attr_reader :method
def initialize(streamhandler, soapaction = nil)
@streamhandler = streamhandler
@soapaction = soapaction
@method = {}
@mandatorycharset = nil
@allow_unqualified_element = false
@default_encodingstyle = nil
end
class Request
include RPC
public
attr_reader :method
attr_reader :namespace
attr_reader :name
def initialize(model, values)
@method = model.dup
@namespace = @method.elename.namespace
@name = @method.elename.name
params = {}
if ((values.size == 1) and (values[0].is_a?(Hash)))
params = values[0]
else
i = 0
@method.each_param_name(SOAPMethod::IN, SOAPMethod::INOUT) do |name|
params[name] = values[i] || SOAPNil.new
i += 1
end
end
@method.set_param(params)
end
end
def add_method(qname, soapaction, name, param_def)
@method[name] = SOAPMethodRequest.new(qname, param_def, soapaction)
end
def create_request(name, *values)
if (@method.key?(name))
method = @method[name]
method.encodingstyle = @default_encodingstyle if @default_encodingstyle
else
raise SOAP::RPC::MethodDefinitionError.new(
"Method: #{ name } not defined.")
end
Request.new(method, values)
end
def invoke(req_header, req_body, soapaction = nil)
if req_header and !req_header.is_a?(SOAPHeader)
req_header = create_header(req_header)
end
if !req_body.is_a?(SOAPBody)
req_body = SOAPBody.new(req_body)
end
opt = create_options
opt[:external_content] = nil
req_env = SOAPEnvelope.new(req_header, req_body)
send_string = Processor.marshal(req_env, opt)
conn_data = StreamHandler::ConnectionData.new(send_string)
if ext = opt[:external_content]
mime = MIMEMessage.new
ext.each do |k, v|
mime.add_attachment(v.data)
end
mime.add_part(conn_data.send_string + "\r\n")
mime.close
conn_data.send_string = mime.content_str
conn_data.send_contenttype = mime.headers['content-type'].str
end
conn_data = @streamhandler.send(conn_data, soapaction)
if conn_data.receive_string.empty?
return nil, nil
end
unmarshal(conn_data, opt)
end
def call(req_header, name, *values)
req = create_request(name, *values)
invoke(req_header, req.method, req.method.soapaction || @soapaction)
end
def check_fault(body)
if body.fault
raise SOAP::FaultError.new(body.fault)
end
end
private
def unmarshal(conn_data, opt)
contenttype = conn_data.receive_contenttype
if /#{MIMEMessage::MultipartContentType}/i =~ contenttype
opt[:external_content] = {}
mime = MIMEMessage.parse("Content-Type: " + contenttype,
conn_data.receive_string)
mime.parts.each do |part|
value = Attachment.new(part.content)
value.contentid = part.contentid
obj = SOAPAttachment.new(value)
opt[:external_content][value.contentid] = obj if value.contentid
end
opt[:charset] = @mandatorycharset ||
StreamHandler.parse_media_type(mime.root.headers['content-type'].str)
env = Processor.unmarshal(mime.root.content, opt)
else
opt[:charset] = @mandatorycharset ||
::SOAP::StreamHandler.parse_media_type(contenttype)
env = Processor.unmarshal(conn_data.receive_string, opt)
end
env
end
def create_header(headers)
header = SOAPHeader.new()
headers.each do |content, mustunderstand, encodingstyle|
header.add(SOAPHeaderItem.new(content, mustunderstand, encodingstyle))
end
header
end
def create_options
opt = {}
opt[:default_encodingstyle] = @default_encodingstyle
if @allow_unqualified_element
opt[:allow_unqualified_element] = true
end
opt
end
end
end
end