| Class | SOAP::RPC::SOAPlet |
| In: |
lib/soap/rpc/soaplet.rb
|
| Parent: | WEBrick::HTTPServlet::AbstractServlet |
| options | [R] |
# File lib/soap/rpc/soaplet.rb, line 45
45: def initialize(router = nil)
46: @router = router || ::SOAP::RPC::Router.new(self.class.name)
47: @options = {}
48: @config = {}
49: end
for backward compatibility
# File lib/soap/rpc/soaplet.rb, line 57
57: def add_servant(obj, namespace)
58: @router.add_rpc_servant(obj, namespace)
59: end
# File lib/soap/rpc/soaplet.rb, line 61
61: def allow_content_encoding_gzip=(allow)
62: @options[:allow_content_encoding_gzip] = allow
63: end
for backward compatibility
# File lib/soap/rpc/soaplet.rb, line 52
52: def app_scope_router
53: @router
54: end
# File lib/soap/rpc/soaplet.rb, line 77
77: def do_GET(req, res)
78: res.header['Allow'] = 'POST'
79: raise WEBrick::HTTPStatus::MethodNotAllowed, "GET request not allowed"
80: end
# File lib/soap/rpc/soaplet.rb, line 82
82: def do_POST(req, res)
83: logger.debug { "SOAP request: " + req.body } if logger
84: begin
85: conn_data = ::SOAP::StreamHandler::ConnectionData.new
86: setup_req(conn_data, req)
87: @router.external_ces = @options[:external_ces]
88: conn_data = @router.route(conn_data)
89: setup_res(conn_data, req, res)
90: rescue Exception => e
91: conn_data = @router.create_fault_response(e)
92: res.status = WEBrick::HTTPStatus::RC_INTERNAL_SERVER_ERROR
93: res.body = conn_data.send_string
94: res['content-type'] = conn_data.send_contenttype || "text/xml"
95: end
96: if res.body.is_a?(IO)
97: res.chunked = true
98: logger.debug { "SOAP response: (chunked response not logged)" } if logger
99: else
100: logger.debug { "SOAP response: " + res.body } if logger
101: end
102: end
# File lib/soap/rpc/soaplet.rb, line 139
139: def encode_gzip(req, outstring)
140: unless encode_gzip?(req)
141: return nil
142: end
143: begin
144: ostream = StringIO.new
145: gz = Zlib::GzipWriter.new(ostream)
146: gz.write(outstring)
147: ostream.string
148: ensure
149: gz.close
150: end
151: end
# File lib/soap/rpc/soaplet.rb, line 153
153: def encode_gzip?(req)
154: @options[:allow_content_encoding_gzip] and defined?(::Zlib) and
155: req['accept-encoding'] and
156: req['accept-encoding'].split(/,\s*/).include?('gzip')
157: end
# File lib/soap/rpc/soaplet.rb, line 130
130: def parse_soapaction(soapaction)
131: if !soapaction.nil? and !soapaction.empty?
132: if /^"(.+)"$/ =~ soapaction
133: return $1
134: end
135: end
136: nil
137: end
# File lib/soap/rpc/soaplet.rb, line 110
110: def setup_req(conn_data, req)
111: conn_data.receive_string = req.body
112: conn_data.receive_contenttype = req['content-type']
113: conn_data.soapaction = parse_soapaction(req.meta_vars['HTTP_SOAPACTION'])
114: end
# File lib/soap/rpc/soaplet.rb, line 116
116: def setup_res(conn_data, req, res)
117: res['content-type'] = conn_data.send_contenttype
118: if conn_data.is_fault
119: res.status = WEBrick::HTTPStatus::RC_INTERNAL_SERVER_ERROR
120: end
121: if outstring = encode_gzip(req, conn_data.send_string)
122: res['content-encoding'] = 'gzip'
123: res['content-length'] = outstring.size
124: res.body = outstring
125: else
126: res.body = conn_data.send_string
127: end
128: end