Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

soap4r custom headers

I've been working with soap4r and trying to use the SOAP::Header::SimpleHandler, I'm trying to get it to put a custom header on the outgoing message, but I can't work out how to get it to include attributes rather than as subelements:

    class ServiceContext < SOAP::Header::SimpleHandler
  NAMESPACE = "http://context.core.datamodel.fs.documentum.emc.com/"
  def initialize()
    super(XSD::QName.new(NAMESPACE, 'ServiceContext'))
    XSD::QName.new(nil, "Identities")
  end

  def on_simple_outbound
    username = "username"
    password = "password"
    docbase = "Test"
    return {"Identities" => {"Username" => username, "Password" => password, "Docbase" => docbase}}
  end
end

which returns:

    <n1:ServiceContext xmlns:n1="http://context.core.datamodel.fs.documentum.emc.com/"
        env:mustUnderstand="0">
      <n1:Identities>
        <n1:Username>username</n1:Username>
        <n1:Password>password</n1:Password>
        <n1:Docbase>Test</n1:Docbase>
      </n1:Identities>
    </n1:ServiceContext>

what I need it to return is the following:

    <ServiceContext xmlns="http://context.core.datamodel.fs.documentum.emc.com/">
        <Identities xsi:type="RepositoryIdentity" userName="_USER_" password="_PWD_" repositoryName="_DOCBASE_" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
    </ServiceContext>

Any help is greatly appreciated.

like image 627
Luke Chadwick Avatar asked Jan 31 '26 08:01

Luke Chadwick


1 Answers

soap4r is not very pretty. I poked around the rdocs abit and it looks like the simplest way to fix your problem would be to have on_simple_outbound return the string representation of the element you want to create.

so instead of

return {"Identities" => {"Username" => username, "Password" => password, "Docbase" => docbase}}

try

%Q(<Identities xsi:type="RepositoryIdentity" userName="#{user}" password="#{password}" repositoryName="#{docbase}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>)

using something like builder, you could make it look more rubyish, but try that.

The other option would be to investigate newer soap libraries. handsoap looks interesting.

like image 163
BaroqueBobcat Avatar answered Feb 03 '26 01:02

BaroqueBobcat