gorilla-xmlrpc icon indicating copy to clipboard operation
gorilla-xmlrpc copied to clipboard

Problem marshalling XML-RPC service response back to client (unless I didn't define interface correctly)

Open daluu opened this issue 7 years ago • 1 comments

Here's the code I have:

type RunKeywordReturnValue struct{
  Return    interface{} `xml:"return"`
  Status    string      `xml:"status"`
  Output    string      `xml:"output"`
  Error     string      `xml:"error"`
  Traceback string      `xml:"traceback"`
}

func (h *RobotRemoteService) RunKeyword(r *http.Request, args *KeywordAndArgsInput, reply *RunKeywordReturnValue) error {
    //do stuff then return the results in struct below (sample static output shown):
    var retval interface{}
    retval = 42
    reply.Return = retval //truth of life
    reply.Status = "FAIL"
    reply.Output = "stdout from keyword execution gets piped into this"
    reply.Error = "gorrs not fully implemented yet, just a proof of concept design at the moment. stderr from keyword execution gets piped into this, by the way."
    reply.Traceback = "stack trace info goes here, if any..."
    return nil
}

Output should look something like this:

<methodResponse>
  <params>
    <param>
      <value><struct>
        <member>
          <name>return</name>
          <value><int>42</int></value>
        </member>
        <member>
          <name>status</name>
          <value><string>PASS</string></value>
       </member>
       <member>
         <name>output</name>
         <value><string></string></value>
       </member>
       <member>
         <name>error</name>
         <value><string></string></value>
        </member>
        <member>
          <name>traceback</name>
          <value><string></string></value>
        </member>
      </struct></value>
    </param>
  </params>
</methodResponse>

with some logging code, it looks like everything executes up to the return nil statement. But after that, the XML-RPC/RPC server part returns an fault message for the response:

<methodResponse>
  <fault>
    <value><struct>
      <member>
        <name>faultCode</name>
        <value><int>-32602</int></value>
      </member>
      <member>
        <name>faultString</name>
        <value><string>Invalid Method Parameters: fields type mismatch: string != []interface {}</string></value>
     </member>
    </struct></value>
  </fault>
</methodResponse>

what exactly might I be doing wrong in mapping the response struct, the XML-RPC service function signature, and the code that assigns values to the response in the function?

daluu avatar Oct 09 '16 00:10 daluu