Issue with Java RPC-JSON package / TypeError: 'NoneType' object is not callable

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue with Java RPC-JSON package / TypeError: 'NoneType' object is not callable

claudef
Dear colleagues,

Testing a Java RPC-JSON package under Jython 2.7 beta 1. One of the classes with an empty argument input list, throws and error:

   invoker = JsonRpcInvoker()
TypeError: 'NoneType' object is not callable

The Java equivalent is:  JsonRpcInvoker invoker = new JsonRpcInvoker();
The import of the class seems to work OK.  

Code:
--------
..
sys.path.append(userdir + "/jsonrpc-1.0/jsonrpc-1.0-client.jar")
from org.json.rpc.client import *
..
        url = "http://localhost:8080/jsonrpc"
        transport = HttpJsonRpcClientTransport(URL(url))
        invoker = JsonRpcInvoker()                # <======= this line is causing the error:
        calc = invoker.get(transport, "calc", Calculator.class)
        result = calc.add(1, 2)
        print "Result = " + str(3)

Any idea what's wrong with the instantiation of this Java class, or how to fix it, or is it related to the dynamic class loader?

I've also tried with .newInstance() which also throws the same error.  

Regards,
Claude


Claude Falbriard
Certified IT Specialist L2 - Middleware
AMS Hortolândia / SP - Brazil
phone:    +55 13 9 9760 0453
cell:         +55 13 9 8117 3316
e-mail:    [hidden email]

------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Issue with Java RPC-JSON package / TypeError: 'NoneType' object is not callable

Alex Grönholm-3
09.05.2014 20:40, [hidden email] kirjoitti:
Dear colleagues,

Testing a Java RPC-JSON package under Jython 2.7 beta 1. One of the classes with an empty argument input list, throws and error:

   invoker = JsonRpcInvoker()
TypeError: 'NoneType' object is not callable

The Java equivalent is:  JsonRpcInvoker invoker = new JsonRpcInvoker();
The import of the class seems to work OK.  

Code:
--------
..
sys.path.append(userdir + "/jsonrpc-1.0/jsonrpc-1.0-client.jar")
from org.json.rpc.client import *
..
        url = "http://localhost:8080/jsonrpc"
        transport = HttpJsonRpcClientTransport(URL(url))
        invoker = JsonRpcInvoker()                # <======= this line is causing the error:
        calc = invoker.get(transport, "calc", Calculator.class)
        result = calc.add(1, 2)
        print "Result = " + str(3)

Any idea what's wrong with the instantiation of this Java class, or how to fix it, or is it related to the dynamic class loader?
Strange that you're not getting a syntax error from this because "class" is a reserved keyword in Python so "Calculator.class" cannot possibly work.
That said, have you checked that JsonRpcInvoker is not actually None (for whatever reason)?

I've also tried with .newInstance() which also throws the same error.  

Regards,
Claude


Claude Falbriard
Certified IT Specialist L2 - Middleware
AMS Hortolândia / SP - Brazil
phone:    +55 13 9 9760 0453
cell:         +55 13 9 8117 3316
e-mail:    [hidden email]


------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce


_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users


------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Issue with Java RPC-JSON package / TypeError: 'NoneType' object is not callable

claudef
Dear Alex,

Thanks for the comments, just to clarify, below I've added a copy of the corrected source code that worked fine. For defining the interface I've chosen a Java class, which I imported at the begin.

True, to avoid syntax error when calling the interface, I've removed the .class in the syntax, just wrote the class name.  

Hope the solution is useful. Spinning in my mind an idea to combine cPython code like Numpy & Matplotlib, but need to do some tests with data to check if it works well with larger matrix using the RPC sockets.  


Java Interface / Compiled with javac
============================

public interface Calculator {
   double add(double x, double y);
   double multiply(double x, double y);
}


Jython Client Code:  
================
 
# RPC-JSON test
# import Java Interface
import Calculator
import sys
from java.lang import *
from java.net import URL
sysProp = System.getProperties()
userdir = sysProp.getProperty("user.dir")
userdir = userdir.replace("\\", "/")  
print ("userdir = " + userdir)
sys.path.append(userdir + "/jsonrpc-1.0/jsonrpc-1.0-client.jar")
sys.path.append(userdir + "/google-gson-2.2.4/gson-2.2.4.jar")  
sys.path.append(userdir + "/slf4j-1.7.7/slf4j-api-1.7.7.jar")
sys.path.append(userdir + "/slf4j-1.7.7/slf4j-simple-1.7.7.jar")  
from com.google.gson import *
from org.slf4j import *
from org.json.rpc.client import JsonRpcInvoker
from org.json.rpc.client import HttpJsonRpcClientTransport
#
class httpclient1():
    #where the servlet is hosted

    def __init__(self):
        self.mydesc = "simple RPC test"

    def runit(self):
        url = "http://localhost:8080/jsonrpc"
        transport = HttpJsonRpcClientTransport(URL(url))
        invoker = JsonRpcInvoker()
        calc = invoker.get(transport, "calc", Calculator)
        result = calc.add(1, 2)
        print "Result = " + str(result)
if __name__ == "__main__":
    myclass = httpclient1()
    myclass.runit()


Regards,
Claude



Claude Falbriard
Certified IT Specialist L2 - Middleware
AMS Hortolândia / SP - Brazil
phone:    +55 13 9 9760 0453
cell:         +55 13 9 8117 3316
e-mail:    [hidden email]
blog:        
https://w3-connections.ibm.com/blogs/inovarMF/?lang=en_us

Project CallOwn Blue      




From:        Alex Grönholm <[hidden email]>
To:        [hidden email],
Date:        13/05/2014 17:17
Subject:        Re: [Jython-users] Issue with Java RPC-JSON package / TypeError: 'NoneType' object is not callable




09.05.2014 20:40, claudef@... kirjoitti:
Dear colleagues,

Testing a Java RPC-JSON package under Jython 2.7 beta 1. One of the classes with an empty argument input list, throws and error:


  invoker = JsonRpcInvoker()
TypeError: 'NoneType' object is not callable


The Java equivalent is:  
JsonRpcInvoker invoker = new JsonRpcInvoker();
The import of the class seems to work OK.  


Code:
--------

..

sys.path.append(userdir + "/jsonrpc-1.0/jsonrpc-1.0-client.jar")

from org.json.rpc.client import *

..

       url = "
http://localhost:8080/jsonrpc"
       transport = HttpJsonRpcClientTransport(URL(url))

       invoker = JsonRpcInvoker()                # <======= this line is causing the error:
       calc = invoker.get(transport, "calc", Calculator.class)

       result = calc.add(1, 2)

       print "Result = " + str(3)


Any idea what's wrong with the instantiation of this Java class, or how to fix it, or is it related to the dynamic class loader?

Strange that you're not getting a syntax error from this because "class" is a reserved keyword in Python so "Calculator.class" cannot possibly work.
That said, have you checked that JsonRpcInvoker is not actually None (for whatever reason)?


I've also tried with .newInstance() which also throws the same error.  


Regards,
Claude



Claude Falbriard
Certified IT Specialist L2 - Middleware
AMS Hortolândia / SP - Brazil
phone:    +55 13 9 9760 0453
cell:         +55 13 9 8117 3316
e-mail:    
claudef@...


------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce


_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users

------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users


------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users