Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoded logging #88

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/savon/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def method_missing(method, *args, &block) #:doc:
super unless @wsdl.respond_to? soap_action

setup_objects *@wsdl.operation_from(soap_action), &block
Response.new @request.soap(@soap)
@request.soap(@soap)
end

# Expects a SOAP operation Hash and sets up Savon::SOAP and Savon::WSSE. Yields them to a given
Expand Down
8 changes: 4 additions & 4 deletions lib/savon/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def soap(soap)
http.use_ssl = @soap.endpoint.ssl?

log_request
@response = http.start do |h|
@response = Response.new(http.start do |h|
h.request request(:soap) { |request| request.body = @soap.to_xml }
end
end)
log_response
@response
end
Expand All @@ -126,8 +126,8 @@ def log_request

# Logs the SOAP response.
def log_response
log "SOAP response (status #{@response.code}):"
log @response.body
log "SOAP response (status #{@response.http.code}):"
log @response.to_s
end

# Returns a Net::HTTP request for a given +type+. Yields the request to an optional block.
Expand Down
26 changes: 22 additions & 4 deletions spec/savon/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,18 @@


describe "when executing a SOAP request" do
let(:fixture) { nil }
before :each do
operation = WSDLFixture.authentication(:operations)[:authenticate]
action, input = operation[:action], operation[:input]
@soap = Savon::SOAP.new action, input, EndpointHelper.soap_endpoint
@soap = Savon::SOAP.new action, input, EndpointHelper.soap_endpoint(fixture)
end

it "should return the Net::HTTP response" do
it "should return the Savon response" do
soap_response = @request.soap @soap

soap_response.should be_a(Net::HTTPResponse)
soap_response.body.should == ResponseFixture.authentication
soap_response.should be_a(Savon::Response)
soap_response.http.body.should == ResponseFixture.authentication
end

it "should include Accept-Encoding gzip if it is enabled" do
Expand All @@ -107,6 +108,23 @@

@request.soap @soap
end

describe "the logger" do
before { Savon::Request.log = true }
after { Savon::Request.log = false }
let(:fixture) { :gzip }

it "logs the response XML when gzip is enabled" do
@request = Savon::Request.new :wsdl => EndpointHelper.wsdl_endpoint(fixture), :gzip => true
a_post = Net::HTTP::Post.new(@soap.endpoint.request_uri, {})

@request.expects(:log).with(anything).at_least(4)
@request.expects(:log).with(GzipResponseFixture.message).never
@request.expects(:log).with("A short gzip encoded message\n").once

@request.soap @soap
end
end
end

it "should not include host when creating HTTP requests" do
Expand Down
1 change: 1 addition & 0 deletions spec/support/endpoint_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def self.soap_endpoint(type = nil)
when :soap_fault then "http://soapfault.example.com/Service?wsdl"
when :http_error then "http://httperror.example.com/Service?wsdl"
when :invalid then "http://invalid.example.com/Service?wsdl"
when :gzip then "http://gzip.example.com/Service?wsdl"
else "http://example.com/validation/1.0/AuthenticationService"
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/support/http_stubs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
FakeWeb.register_uri :get, EndpointHelper.wsdl_endpoint, :body => WSDLFixture.authentication
FakeWeb.register_uri :post, EndpointHelper.soap_endpoint, :body => ResponseFixture.authentication

# Some WSDL and SOAP request.
FakeWeb.register_uri :get, EndpointHelper.wsdl_endpoint(:gzip), :body => WSDLFixture.authentication
FakeWeb.register_uri :post, EndpointHelper.soap_endpoint(:gzip), :body => GzipResponseFixture.message

# WSDL and SOAP request with a Savon::SOAPFault.
FakeWeb.register_uri :get, EndpointHelper.wsdl_endpoint(:soap_fault), :body => WSDLFixture.authentication
FakeWeb.register_uri :post, EndpointHelper.soap_endpoint(:soap_fault), :body => ResponseFixture.soap_fault
Expand Down