+ Reply to Thread
Results 1 to 8 of 8

Thread: Help writing new extension-<methodResponse> is an unsupported type

  1. #1

    Unhappy Help writing new extension-<methodResponse> is an unsupported type

    Hi all ,
    I am trying to understand XML-RPC and extension writing using python. The problem I am having seems to be dekiwiki config centric.

    I have registered a service using the following manifest

    <extension>
    <title>Calendar</title>
    <function>
    <name>gethari</name>
    <uri>http://67.207.145.173:8888</uri>
    <description>Test </description>
    <param name="year" type="num" optional="false">The year </param>
    <param name="month" type="num" optional="false"> The month</param>
    <return type="str" />

    </function>
    </extension>


    The code for that service is in python

    import SimpleXMLRPCServer
    from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler,SimpleXMLRPCRequestHand ler

    #The server function
    def gethari(year, month):
    # this sends stuff to stdout for troubleshooting purposes
    print year
    print month
    # The return stuff that should be received
    return "HOO " + "%s " % year + "%s " % month + "\n"

    server = SimpleXMLRPCServer.SimpleXMLRPCServer(("67.207.145 .173", 8888))
    server.register_introspection_functions()
    server.register_function(gethari)

    print "Listening on port 8888"
    server.serve_forever()




    Now I am trying to call that service , and get a response . In my wiki

    {{gethari (2008 , 8) }}

    But I get an error which says
    <methodResponse> is an unsupported type

    I know that the XML-RPC service is running because test scripts connect fine and produce output OK for eg
    #!/usr/bin/python
    import xmlrpclib
    server = xmlrpclib.ServerProxy("http://67.207.145.173:8888")

    month = server.gethari(2002, 8)
    print month


    Gives proper output "HOO 2002 8"

    But the dekiwiki seems to be sending no inputs as seen in the log file
    localhost bsc_api # python calendar.py
    Listening on port 8888

    67-207-145-173.slicehost.net - - [23/Mar/2008 20:09:40] "POST / HTTP/1.0" 200 -

    c-66-30-112-141.hsd1.ma.comcast.net - - [23/Mar/2008 20:22:26] "POST /RPC2 HTTP/1.0" 200 -
    2002
    8

    Does anyone know what I can do to write a correct XML-RPC extension that works with dekiwiki in python or perl or any non dot-net language.

    Thanks

  2. #2
    Join Date
    Jul 2006
    Location
    San Diego, CA
    Posts
    5,450

    Default

    First, here is a link to the spec, as it will undoubtely help:
    http://wiki.opengarden.org/Deki_Wiki...g_languages%3f

    Second, the problem you're running into is that Deki Wiki expects the response to be wrapped into a DekiScript XML-RPC document. For example, to return a string, emit the following:
    Code:
    <vale type="list">
        <value key="#" type="str">Hello World!</value>
    </value>
    Also make sure to set the content-type for the response to "application/xml". That should do the trick.
    Steve G. Bjorg - Chief Architect
    Did you check the MindTouch FAQ?
    Found a bug? Report it.
    Follow me on Twitter
    Find us on IRC: irc.freenode.net #mindtouch

  3. #3

    Red face dekiscript XML-RPC vs XML-RPC

    Hi SteveB

    Thanks for your reply..As is quite obvious I am an absolute beginner to XML-RPC and Dekiwiki and network programming with XMl messaging...
    So If I understand you right the dekiwiki speaks its own version of XML-RPC called Dekiscript XML-RPC.

    So in this case a string in Dekiscript XML-RPC is sent or received as

    <value type="str">Hello World!!!</value>


    Whereas the "standard" XMl-RPC spec sends a string as

    <value><string>Hello World!!!</string></value>

    So should I be looking at writing a server handler that speaks Dekiscript XML-RPC in python instead of just a plain old xml-rpc server instance.
    Also where in my dekiwiki install are the source files for the mono code that implements the standard extensions provided with dekiwiki.

    Your help is greatly appreciated
    harijay
    Last edited by harijay; 03-24-2008 at 06:19 PM.

  4. #4
    Join Date
    Jul 2006
    Location
    San Diego, CA
    Posts
    5,450

    Default

    Didn't know there was a "standard XML-RPC" spec, oops. Where is that located? For 1.11, we're looking at adding more web-friendly formats than DekiScript XML-RPC, like plain text for string (like you tried in your first attemp), etc.

    The C# code for reading DekiScrip XML-RPC is located in DekiScriptLitral::FromXml() in DekiScript.cs.

    DekiScript understands 8 kinds of literals: nil, bool, num, str, uri, map, list, and xml.

    Finally, note that results are always returned in a list. This will allow in the future to support returns of multiple values at once (like Lua). For now, only the first value is accessible in the return list though.
    Steve G. Bjorg - Chief Architect
    Did you check the MindTouch FAQ?
    Found a bug? Report it.
    Follow me on Twitter
    Find us on IRC: irc.freenode.net #mindtouch

  5. #5

    Default

    Hi Steve..its funny I was approaching this from the other end of the maze.. I thought that xml-rpc meant only one thing ..i.e a spec ( http://en.wikipedia.org/wiki/XML-RPC) which is famous for being less than two pages long as described by Dave Winer . That standard uses a particular schema for its message ( I am a newbie so standard disclaimers on accuracy of this statment apply ).

    The python library xmlrpclib which I was planning on using speaks this standard XMl-RPC as do other libraries that implement the spec (http://www.xmlrpc.com/directory/1568/implementations).

    But I guess I will have to write my own handler in python that understands and talks Dekiscript XML-RPC.

    Thanks for your help.
    I will post a hello world in python, when I get it working to the wiki.

  6. #6
    Join Date
    Jul 2006
    Location
    San Diego, CA
    Posts
    5,450

    Default

    Thanks for the link. I'll admit I was oblivious of it. I'll add support for the "official" XML-RPC into Deki Wiki. That should help a bit! However, I'll need to add one more data-type, namely <xml>, which can contain an arbitrary xml document in xml format.
    Steve G. Bjorg - Chief Architect
    Did you check the MindTouch FAQ?
    Found a bug? Report it.
    Follow me on Twitter
    Find us on IRC: irc.freenode.net #mindtouch

  7. #7

    Smile Gotcha! wrote my first HelloWorld with python code that speaks dekiscript

    Hi Steve,
    So I did get around to writing my hello world extension using python.
    Its rather simple and uses the CGIHTTPServer class and implements do_GET and do_POST as required by dekiwiki XML-RPC

    Having gone through this. It would be great if dekiwiki spoke standard XML-RPC as I would do anything to not write xml parsing and error handling code..a lot of which the XML-RPC implementations take care of for you.
    I can put this into the wiki somewhere so it saves someone some time.
    Thanks for your help and here goes

    #!/usr/bin/env python
    # This Hello world example creates a CGIHTTPServer that handles the
    # GET and post requirements to write a dekiwiki extension

    from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
    import CGIHTTPServer,cgi
    class MyHandler(CGIHTTPServer.CGIHTTPRequestHandler):
    # This class Handles simple strings sent by dekiwiki and wraps them in dekiscript xml-rpc and sends it back. This one prints the input sent to it. The function resides in the namespace "my" and is called print

    # Function to parse the xml string sent by the wiki

    def process_string_xml(self,dekixml):
    import xml.dom.minidom
    from xml.dom.minidom import Node
    doc = xml.dom.minidom.parseString(dekixml)
    dekistring = ''
    text = doc.getElementsByTagName("value")
    text[1].normalize()
    dekistring = text[1].lastChild.data
    return dekistring

    def do_GET(self):
    self.send_response(200)
    self.send_header('Content-type','application/xml')
    self.end_headers()
    str = '''<extension>
    <title>My Extension</title>
    <description>This extension contains my functions.</description>
    <namespace>my</namespace>
    <function>
    <name>print</name>
    <uri>http://ip.myserver.com</uri>
    <description>Writes a string or "Hello World!" if no parameter is provided.</description>
    <param name="text" type="str" optional="true">Text to write (default: "Hello World!")</param>
    <return type="str" />
    </function>
    </extension>'''
    self.wfile.write(str)

    def do_POST(self):
    data = self.rfile.read(int(self.headers["content-length"]))
    print data
    self.send_response(200)
    self.send_header('Content-type',"application/xml; charset=utf-8")
    # Actually parse data and get string that has to be wrapped in dekiscript
    dekistring = self.process_string_xml(data)
    response = '''<value type="list"><value type="str">%s</value></value>''' % dekistring
    print response
    self.send_header("Content-length", str(len(response)))
    self.end_headers()
    self.wfile.write(response)
    self.wfile.flush()
    self.connection.shutdown(1)

    def main():
    try:
    server = HTTPServer(('', 82), MyHandler)
    print 'Welcome to the machine...',
    print 'Press ^C once or twice to quit.'
    server.serve_forever()
    except KeyboardInterrupt:
    print '^C received, shutting down server'
    server.socket.close()

    if __name__ == '__main__':
    main()

  8. #8
    Join Date
    Jul 2006
    Location
    San Diego, CA
    Posts
    5,450

    Default

    Sweet! You should add it your new found knowledge under Extensions in Community Contributions
    Steve G. Bjorg - Chief Architect
    Did you check the MindTouch FAQ?
    Found a bug? Report it.
    Follow me on Twitter
    Find us on IRC: irc.freenode.net #mindtouch

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts