Custom soap4r headers

I am working with soap4r and trying to use SOAP :: Header :: SimpleHandler, I am trying to get it to put a custom header in the outgoing message, but I can’t figure out how to get it, it should include attributes, not 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 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.

+3
source share
1 answer

soap4r is not very pretty. I poked around rdocs abit and it seems the easiest way to fix your problem would be to on_simple_outboundreturn the string representation of the element you want to create.

therefore instead

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

to try

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

- , , .

- . handsoap .

+3

Source: https://habr.com/ru/post/1704493/


All Articles