我刚刚开始在ruby on rails世界,并设法获得以下模型来发出请求并返回响应。它使用'savon_model'宝石,它有'savon','httpi'和'httpclient'宝石作为依赖。
class Incident
include Savon::Model
client do
http.auth.basic "testuser", ""
http.headers["Accept-Encoding"] = "gzip, deflate"
http.headers["SOAPAction"] = '"RetrieveKeysList"'
end
endpoint "http://localhost:13080/SM/7/ws"
namespace "http://schemas.hp.com/SM/7"
actions "RetrieveIncidentKeysListRequest"
def self.all
response = client.request("RetrieveIncidentKeysListRequest") do
soap.body = {'wsdl:model' =>
{'wsdl:keys' =>"",
'wsdl:instance' =>""}
}
end
h = response.to_hash
ActiveRecord::Base.logger.debug "********value of H is #{h}"
return h[:retrieve_incident_keys_list_response][:keys]
end
end
我有两个问题:
1)请求首先发出匿名soap请求,验证失败,然后发出第二个请求,正确验证并返回响应。响应在一秒左右内返回。我的模型代码中是否存在导致初始匿名请求的错误?
POST /SM/7/ws HTTP/1.1
accept-encoding: gzip, deflate
soapaction: "RetrieveKeysList"
content-type: text/xml;charset=UTF-8
date: Mon, 13 Dec 2010 12:54:11 GMT
content-length: 427
host: localhost:13080
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="http://schemas.hp.com/SM/7" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><RetrieveIncidentKeysListRequest><wsdl:model><wsdl:keys></wsdl:keys><wsdl:instance></wsdl:instance></wsdl:model></RetrieveIncidentKeysListRequest></env:Body></env:Envelope>
HTTP/1.1 401
Set-Cookie: JSESSIONID=E7FFF77B44531BE3E28B239F0A900A5A; Path=/SM
WWW-Authenticate: Basic realm="CASM"
Connection: close
Content-Type: text/html;charset=utf-8
Content-Length: 40
Date: Mon, 13 Dec 2010 12:54:11 GMT
POST /SM/7/ws HTTP/1.1
accept-encoding: gzip, deflate
soapaction: "RetrieveKeysList"
content-type: text/xml;charset=UTF-8
cookie: JSESSIONID=E7FFF77B44531BE3E28B239F0A900A5A
authorization: Basic ZmFsY29uOg==
date: Mon, 13 Dec 2010 12:54:12 GMT
content-length: 427
host: localhost:13080
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="http://schemas.hp.com/SM/7" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><RetrieveIncidentKeysListRequest><wsdl:model><wsdl:keys></wsdl:keys><wsdl:instance></wsdl:instance></wsdl:model></RetrieveIncidentKeysListRequest></env:Body></env:Envelope>
HTTP/1.1 200
Set-Cookie: JSESSIONID=21EE41B79757FA9C0E31FAB886A2899D; Path=/SM
Keep-Alive: timeout=1200000, max=1000
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/xml;charset=utf-8
Content-Length: 9014
Date: Mon, 13 Dec 2010 12:54:14 GMT
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><RetrieveIncidentKeysListResponse xmlns="http://schemas.hp.com/SM/7" xmlns:cmn="http://schemas.hp.com/SM/7/Common" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" message="Success" query="" returnCode="0" schemaRevisionDate="2010-08-26" schemaRevisionLevel="1" status="SUCCESS" xsi:schemaLocation="http://schemas.hp.com/SM/7 http://localhost:13080/SM/7/ws/Incident.xsd"><keys><IncidentID type="String">IM10001</IncidentID></keys><keys><IncidentID type="String">IM10002</IncidentID></keys><keys><IncidentID type="String">IM10003</IncidentID></keys><keys><IncidentID type="String">IM10004</IncidentID></keys><keys><IncidentID type="String">IM10005</IncidentID></keys><keys><IncidentID type="String">IM10006</IncidentID></keys><keys><IncidentID type="String">IM10007</IncidentID></keys><keys><IncidentID type="String">IM10008</IncidentID></keys><keys><IncidentID type="String">IM10009</IncidentID></keys><keys><IncidentID type="String">IM10010</IncidentID></keys><keys><IncidentID type="String">IM10011</IncidentID></keys><keys><IncidentID type="String">IM10012</IncidentID></keys><keys><IncidentID type="String">IM10014</IncidentID></keys><keys><IncidentID type="String">IM10015</IncidentID></keys><keys><IncidentID type="String">IM10016</IncidentID></keys><keys><IncidentID type="String">IM10017</IncidentID></keys><keys><IncidentID type="String">IM10018</IncidentID></keys><keys><IncidentID type="String">IM10019</IncidentID></keys><keys><IncidentID type="String">IM10020</IncidentID></keys><keys><IncidentID type="String">IM10021</IncidentID></keys><keys><IncidentID type="String">IM10022</IncidentID></keys><keys><IncidentID type="String">IM10023</IncidentID></keys><keys><IncidentID type="String">IM10024</IncidentID></keys><keys><IncidentID type="String">IM10025</IncidentID></keys><keys><IncidentID type="String">IM10026</IncidentID></keys><keys><IncidentID type="String">IM10027</IncidentID></keys><keys><IncidentID type="String">IM10028</IncidentID></keys><keys><IncidentID type="String">IM10029</IncidentID></keys><keys><IncidentID type="String">IM10030</IncidentID></keys><keys><IncidentID type="String">IM10031</IncidentID></keys><keys><IncidentID type="String">IM10032</IncidentID></keys><keys><IncidentID type="String">IM10033</IncidentID></keys><keys><IncidentID type="String">IM10034</IncidentID></keys><keys><IncidentID type="String">IM10035</IncidentID></keys><keys><IncidentID type="String">IM10036</IncidentID></keys><keys><IncidentID type="String">IM10037</IncidentID></keys><keys><IncidentID type="String">IM10038</IncidentID></keys><keys><IncidentID type="String">IM10039</IncidentID></keys><keys><IncidentID type="String">IM10040</IncidentID></keys><keys><IncidentID type="String">IM10041</IncidentID></keys><keys><IncidentID type="String">IM10042</IncidentID></keys><keys><IncidentID type="String">IM10043</IncidentID></keys><keys><IncidentID type="String">IM10044</IncidentID></keys><keys><IncidentID type="String">IM10045</IncidentID></keys><keys><IncidentID type="String">IM10046</IncidentID></keys><keys><IncidentID type="String">IM10047</IncidentID></keys><keys><IncidentID type="String">IM10048</IncidentID></keys><keys><IncidentID type="String">IM10049</IncidentID></keys><keys><IncidentID type="String">IM10050</IncidentID></keys><keys><IncidentID type="String">IM10051</IncidentID></keys><keys><IncidentID type="String">IM10052</IncidentID></keys><keys><IncidentID type="String">IM10053</IncidentID></keys><keys><IncidentID type="String">IM10054</IncidentID></keys><keys><IncidentID type="String">IM10055</IncidentID></keys><keys><IncidentID type="String">IM10057</IncidentID></keys><keys><IncidentID type="String">IM10058</IncidentID></keys><keys><IncidentID type="String">IM10059</IncidentID></keys><keys><IncidentID type="String">IM10060</IncidentID></keys><keys><IncidentID type="String">IM10061</IncidentID></keys><keys><IncidentID type="String">IM10062</IncidentID></keys><keys><IncidentID type="String">IM10063</IncidentID></keys><keys><IncidentID type="String">IM10064</IncidentID></keys><keys><IncidentID type="String">IM10065</IncidentID></keys><keys><IncidentID type="String">IM10066</IncidentID></keys><keys><IncidentID type="String">IM10067</IncidentID></keys><keys><IncidentID type="String">IM10068</IncidentID></keys><keys><IncidentID type="String">IM10069</IncidentID></keys><keys><IncidentID type="String">IM10070</IncidentID></keys><keys><IncidentID type="String">IM10071</IncidentID></keys><keys><IncidentID type="String">IM10072</IncidentID></keys><keys><IncidentID type="String">IM10073</IncidentID></keys><keys><IncidentID type="String">IM10074</IncidentID></keys><keys><IncidentID type="String">IM10075</IncidentID></keys><keys><IncidentID type="String">IM10076</IncidentID></keys><keys><IncidentID type="String">IM10077</IncidentID></keys><keys><IncidentID type="String">IM10078</IncidentID></keys><keys><IncidentID type="String">IM10079</IncidentID></keys><keys><IncidentID type="String">IM10080</IncidentID></keys><keys><IncidentID type="String">IM10081</IncidentID></keys><keys><IncidentID type="String">IM10082</IncidentID></keys><keys><IncidentID type="String">IM10083</IncidentID></keys><keys><IncidentID type="String">IM10084</IncidentID></keys><keys><IncidentID type="String">IM10085</IncidentID></keys><keys><IncidentID type="String">IM10086</IncidentID></keys><keys><IncidentID type="String">IM10087</IncidentID></keys><keys><IncidentID type="String">IM10088</IncidentID></keys><keys><IncidentID type="String">IM10089</IncidentID></keys><keys><IncidentID type="String">IM10090</IncidentID></keys><keys><IncidentID type="String">IM10091</IncidentID></keys><keys><IncidentID type="String">IM10092</IncidentID></keys><keys><IncidentID type="String">IM10093</IncidentID></keys><keys><IncidentID type="String">IM10094</IncidentID></keys><keys><IncidentID type="String">IM10095</IncidentID></keys><keys><IncidentID type="String">IM10096</IncidentID></keys><keys><IncidentID type="String">IM10097</IncidentID></keys><keys><IncidentID type="String">IM10098</IncidentID></keys><keys><IncidentID type="String">IM10099</IncidentID></keys><keys><IncidentID type="String">IM10100</IncidentID></keys><keys><IncidentID type="String">IM10101</IncidentID></keys><keys><IncidentID type="String">IM10102</IncidentID></keys><keys><IncidentID type="String">IM10103</IncidentID></keys><keys><IncidentID type="String">IM10104</IncidentID></keys><keys><IncidentID type="String">IM10105</IncidentID></keys><keys><IncidentID type="String">IM10106</IncidentID></keys><keys><IncidentID type="String">IM10107</IncidentID></keys><keys><IncidentID type="String">IM10108</IncidentID></keys><keys><IncidentID type="String">IM10109</IncidentID></keys><keys><IncidentID type="String">IM10110</IncidentID></keys><keys><IncidentID type="String">IM10111</IncidentID></keys><keys><IncidentID type="String">IM10112</IncidentID></keys><keys><IncidentID type="String">IM10113</IncidentID></keys><keys><IncidentID type="String">IM10114</IncidentID></keys><keys><IncidentID type="String">IM10115</IncidentID></keys><keys><IncidentID type="String">IM10116</IncidentID></keys><keys><IncidentID type="String">IM10117</IncidentID></keys><keys><IncidentID type="String">IM10118</IncidentID></keys><keys><IncidentID type="String">IM10119</IncidentID></keys><keys><IncidentID type="String">IM10120</IncidentID></keys><keys><IncidentID type="String">IM10121</IncidentID></keys><keys><IncidentID type="String">IM10122</IncidentID></keys><keys><IncidentID type="String">IM10123</IncidentID></keys><keys><IncidentID type="String">IM10124</IncidentID></keys><keys><IncidentID type="String">IM10125</IncidentID></keys><keys><IncidentID type="String">IM10126</IncidentID></keys><keys><IncidentID type="String">IM10127</IncidentID></keys><keys><IncidentID type="String">IM10128</IncidentID></keys><keys><IncidentID type="String">IM10129</IncidentID></keys><keys><IncidentID type="String">IM10130</IncidentID></keys><keys><IncidentID type="String">IM10131</IncidentID></keys><keys><IncidentID type="String">IM10132</IncidentID></keys><keys><IncidentID type="String">IM10133</IncidentID></keys><keys><IncidentID type="String">IM10134</IncidentID></keys><keys><IncidentID type="String">IM10135</IncidentID></keys><keys><IncidentID type="String">IM10136</IncidentID></keys><keys><IncidentID type="String">IM10137</IncidentID></keys><keys><IncidentID type="String">IM10138</IncidentID></keys><keys><IncidentID type="String">IM10140</IncidentID></keys><keys><IncidentID type="String">IM10141</IncidentID></keys><keys><IncidentID type="String">IM10142</IncidentID></keys><keys><IncidentID type="String">IM10143</IncidentID></keys><keys><IncidentID type="String">IM10144</IncidentID></keys><keys><IncidentID type="String">IM10145</IncidentID></keys></RetrieveIncidentKeysListResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
2)即使请求被解析并且返回响应,如上面的日志(来自请求应用程序而不是rails应用程序),请求在rails端超时,并且没有任何内容写入屏幕。下面是development.log条目和堆栈跟踪的最后几行:
development.log
Started GET "/incidents" for 127.0.0.1 at 2010-12-13 12:59:33 +0000
Processing by IncidentsController#index as HTML
Completed in 63517ms
HTTPClient::ReceiveTimeoutError (execution expired):
app/models/incident.rb:15:in `all'
app/controllers/incidents_controller.rb:5:in `index'
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.0ms)
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout
Stack Trace的最后几行
httpclient (2.1.5.2) lib/httpclient/session.rb:804:in `readpartial'
httpclient (2.1.5.2) lib/httpclient/session.rb:804:in `block in read_body_length'
httpclient (2.1.5.2) lib/httpclient/timeout.rb:128:in `timeout'
httpclient (2.1.5.2) lib/httpclient/session.rb:802:in `read_body_length'
httpclient (2.1.5.2) lib/httpclient/session.rb:591:in `get_body'
httpclient (2.1.5.2) lib/httpclient.rb:958:in `do_get_block'
httpclient (2.1.5.2) lib/httpclient.rb:765:in `block in do_request'
httpclient (2.1.5.2) lib/httpclient.rb:848:in `protect_keep_alive_disconnected'
httpclient (2.1.5.2) lib/httpclient.rb:764:in `do_request'
httpclient (2.1.5.2) lib/httpclient.rb:666:in `request'
httpclient (2.1.5.2) lib/httpclient.rb:596:in `post'
httpi (0.7.2) lib/httpi/adapter/httpclient.rb:34:in `block in post'
httpi (0.7.2) lib/httpi/adapter/httpclient.rb:66:in `do_request'
httpi (0.7.2) lib/httpi/adapter/httpclient.rb:33:in `post'
httpi (0.7.2) lib/httpi.rb:93:in `block in post'
httpi (0.7.2) lib/httpi.rb:147:in `with'
httpi (0.7.2) lib/httpi.rb:91:in `post'
对于长篇大论的消息道歉,我们将非常感谢任何帮助。
由于 乔尔