gorilla-xmlrpc
gorilla-xmlrpc copied to clipboard
Problem marshalling XML-RPC service response back to client (unless I didn't define interface correctly)
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?
Actually, this may be related to issue #16, since if you don't provide arguments, and only the keyword, then we hit the error mentioned here, so it's not with the response/reply part yet, but rather a problem translating KeywordAguments in the XML-RPC call to go struct (definition below):
type KeywordAndArgsInput struct {
KeywordName string
KeywordAguments []interface{}
}
where a sample XML-RPC call looks like
<methodCall>
<methodName>run_keyword</methodName>
<params>
<param><value><string>foo</string></value></param>
<param><value><array><data></data></array></value>
</param>
</params>
</methodCall>