How can I script a simple SOAP server to return static XML based on namespace of incoming request?
I need to do some testing for开发者_开发百科 an application that makes multiple SOAP calls to a third party application and then processes the result. I wanted to send specific data to the application under test from a program that simulates the third party application.
I realized that all I really needed was to have a server process that 1) accepts incoming SOAP calls from the application under test 2) determines what namespace is being used in the incoming SOAP call 3) returns a SOAP reponse using static XML based on that namespace.
I thought I'd simply use Ruby's SOAP::RPC::StandaloneServer, but that expects a single namespace in the constructor, so I was stumped (I did consider monkey-patching the code that handles namespaces, but that looked hard). Then, I thought I'd try something with Ruby's TCPServer. I got as far as the code below when I realized I had no idea how to correctly return the appropriate XML in the correct SOAP fashion.
require 'socket'
server = TCPServer.new('127.0.0.1', 9800)
loop {
client = server.accept
# This is for illustration only, it's clearly wrong
while line = client.gets
if line =~ /urn:foo/
# return the foo xml in the correct SOAP fashion
elsif line =~ /urn:bar/
# return the bar xml in the correct SOAP fashion
end
end
client.close
}
trap('INT') { exit }
Note that the application under test is not a Ruby application and it is not friendly to testing. Also note that I'd happily consider another solution (such as a Perl solution) if it was easier--I just started with Ruby since I have a little bit of experience with it.
You might want to try this instead, it does pretty much exactly what you want. http://www.soapui.org/
精彩评论