Jython inherit from Java class

Mark Fink mark at mark-fink.de
Fri Feb 10 12:55:38 EST 2006


Alan, Kent, many thanks this really helped!
But there is still a problem I guess with inheritance. I use the java
testsuit supplied with the original to test the server. If I use the
Java FitServer the testsuite can be completed. I commented everything
out from my class and it does not work??
Thats the trace when I run the JUnit testsuit:
java.io.IOException: CreateProcess: jython
D:\AUT_TEST\workspace\JyFIT\fit\JyFitServer.py
-Dpython.path='D:\AUT_TEST\workspace\JyFIT'
D:\AUT_TEST\fitnesse\fitnesse.jar localhost 1234 23 error=2
	at java.lang.ProcessImpl.create(Native Method)
	at java.lang.ProcessImpl.<init>(Unknown Source)
	at java.lang.ProcessImpl.start(Unknown Source)
	at java.lang.ProcessBuilder.start(Unknown Source)
	at java.lang.Runtime.exec(Unknown Source)
	at java.lang.Runtime.exec(Unknown Source)
	at java.lang.Runtime.exec(Unknown Source)
	at
FitServerTest.FitServerTest.prepareSessionProcess(FitServerTest.java:163)
	at
FitServerTest.FitServerTest.testSimpleStartUp(FitServerTest.java:36)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

Unfortunately I do not get much information at the prompt because both
Java FitServer and JyFitServer behave the same there.
D:\AUT_TEST>jython D:\\AUT_TEST\\workspace\\JyFIT\\fit\\JyFitServer.py
-Dpython.path='D:\\AUT_TEST\\workspace\\JyFIT'
D:\\AUT_TEST\\fitnesse\\fitnesse.jar localhost 1234 23
Traceback (innermost last):
  File "D:\\AUT_TEST\\workspace\\JyFIT\\fit\\JyFitServer.py", line 42,
in ?
java.net.ConnectException: Connection refused: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:507)
        at java.net.Socket.connect(Socket.java:457)
        at java.net.Socket.<init>(Socket.java:365)
        at java.net.Socket.<init>(Socket.java:178)
        at fit.FitServer.establishConnection(Unknown Source)
        at fit.FitServer.establishConnection(Unknown Source)
        at fit.FitServer.run(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at
org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
        at org.python.core.PyMethod.__call__(PyMethod.java)
        at org.python.core.PyObject.__call__(PyObject.java)
        at org.python.core.PyInstance.invoke(PyInstance.java)
        at
org.python.pycode._pyx0.f$0(D:\\AUT_TEST\\workspace\\JyFIT\\fit\\JyFitServer.py:42)
        at
org.python.pycode._pyx0.call_function(D:\\AUT_TEST\\workspace\\JyFIT\\fit\\JyFitServer.py)
        at org.python.core.PyTableCode.call(PyTableCode.java)
        at org.python.core.PyCode.call(PyCode.java)
        at org.python.core.Py.runCode(Py.java)
        at org.python.core.__builtin__.execfile_flags(__builtin__.java)
        at
org.python.util.PythonInterpreter.execfile(PythonInterpreter.java)
        at org.python.util.jython.main(jython.java)

java.net.ConnectException: java.net.ConnectException: Connection
refused: connect

###### And the Java FitServer:
D:\AUT_TEST>java -cp D:\\AUT_TEST\\fitnesse\\fitnesse.jar fit.FitServer
localhost 1234 23
Exception in thread "main" java.net.ConnectException: Connection
refused: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(Unknown Source)
        at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
        at java.net.PlainSocketImpl.connect(Unknown Source)
        at java.net.SocksSocketImpl.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.<init>(Unknown Source)
        at java.net.Socket.<init>(Unknown Source)
        at fit.FitServer.establishConnection(Unknown Source)
        at fit.FitServer.establishConnection(Unknown Source)
        at fit.FitServer.run(Unknown Source)
        at fit.FitServer.main(Unknown Source)

... not to bad.
That is the code with everything commented out:
import sys
import fit.FitServer
import fitnesse.components.FitProtocol
from fit.Parse import Parse
from fit.Fixture import Fixture

# Inherit from original Java FitServer Implementation by Robert C.
Martin and Micah D. Martin
class JyFitServer(fit.FitServer):
    """
    # call constructor of superclass
    def __init__(self, host, port, verbose):
        fit.FitServer.__init__(self, host, port, verbose)

    # override process method
    def process(self):
        self.fixture.listener = self.fixtureListener
        print "hello, I am JyFitServer!"
        try:
            size = FitProtocol.readSize(self.socketReader)
            if size > 0:
                try:
                    document =
FitProtocol.readDocument(self.socketReader, size)
                    tables = Parse(document)
                    fixture = Fixture()
                    fixture.listener = self.fixtureListener;
                    fixture.doTables(tables)
                    self.counts.tally(self.fixture.counts)
                except FitParseException, e:
                    self.exception(e)
        except Exception, e:
            self.exception(e)
    """

# this is main
jyFitServer = JyFitServer()
sys.argv.pop(0) # remove first parameter
sys.argv.pop(0) # remove first parameter
sys.argv.pop(0) # remove first parameter
sys.argv.pop(0) # remove first parameter
#print sys.argv
jyFitServer.run(sys.argv)
#return jyFitServer.exitCode()

I have the feeling that I am almost there. Yust something small
missing.




More information about the Python-list mailing list