Jython inherit from Java class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Fink

    #1

    Jython inherit from Java class

    I wrote a Jython class that inherits from a Java class and (thats the
    plan) overrides one method. Everything should stay the same.

    If I run this nothing happens whereas if I run the Java class it says:
    usage: java fit.FitServer [-v] host port socketTicket
    -v verbose

    I think this is because I do not understand the jython mechanism for
    inheritance (yet).

    JyFitServer.py:
    ===========
    import fit.FitServer
    import fitnesse.compon ents.FitProtoco l
    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 FitServer(fit.F itServer):
    # call constructor of superclass
    def __init__(self, host, port, verbose):
    FitServer.__ini t__(self, host, port, verbose)

    # override process method
    def process(self):
    self.fixture.li stener = self.fixtureLis tener
    print "hello, I am JyFitServer!"
    try:
    size = FitProtocol.rea dSize(self.sock etReader)
    if size > 0:
    try:
    document =
    FitProtocol.rea dDocument(self. socketReader, size)
    tables = Parse(document)
    fixture = Fixture()
    fixture.listene r = self.fixtureLis tener;
    fixture.doTable s(tables)
    self.counts.tal ly(self.fixture .counts)
    except FitParseExcepti on, e:
    self.exception( e)
    except Exception, e:
    self.exception( e)



    Please help,
    Mark Fink

  • Alan Kennedy

    #2
    Re: Jython inherit from Java class

    [Mark Fink][color=blue]
    > I wrote a Jython class that inherits from a Java class and (thats the
    > plan) overrides one method. Everything should stay the same.
    >
    > If I run this nothing happens whereas if I run the Java class it says:
    > usage: java fit.FitServer [-v] host port socketTicket
    > -v verbose
    >
    > I think this is because I do not understand the jython mechanism for
    > inheritance (yet).[/color]

    1. Are you running jythonc?

    If yes, I think your class and file should have the same name, i.e.
    Class FitServer should be in a file called "FitServer. py". I recommend
    calling your class something different from the base class, e.g.
    MyJythonFitServ er, to prevent namespace clashes.

    2. If your main function in jython? If yes, please post the code so we
    can see how you're instantiating your objects?

    3. How are you running this? I.e. show us a command line session which
    uses your class.
    [color=blue]
    > JyFitServer.py:
    > ===========[/color]
    [color=blue]
    > class FitServer(fit.F itServer):
    > # call constructor of superclass
    > def __init__(self, host, port, verbose):
    > FitServer.__ini t__(self, host, port, verbose)[/color]
    ^^^^^^^^^
    Shouldn't this be:
    [color=blue]
    > fit.FitServer._ _init__(self, host, port, verbose)[/color]

    I'm not sure the latter is cause of your problems, but it might be.

    HTH,

    --
    alan kennedy
    ------------------------------------------------------
    email alan: http://xhaus.com/contact/alan

    Comment

    • Kent Johnson

      #3
      Re: Jython inherit from Java class

      Mark Fink wrote:[color=blue]
      > I wrote a Jython class that inherits from a Java class and (thats the
      > plan) overrides one method. Everything should stay the same.
      >
      > If I run this nothing happens whereas if I run the Java class it says:
      > usage: java fit.FitServer [-v] host port socketTicket
      > -v verbose[/color]

      It sounds like the Java class has a main() function. When you run it as
      an application, the Java runtime looks for the main() function in the
      class you tell it to run.

      Even in Java, this behaviour is not preserved by inheritance, a subclass
      has to have its own main() to be executable.

      Jython (and Python) works a little differently, your module is executed
      from start to finish when you run it. Any statements that are not inside
      a class or function definition will be executed. (Actually the class and
      function definitions are executed to, but not in the same way...)

      You might get the behaviour you want if you put the line
      import sys
      fit.FitServer.m ain(sys.argv)

      at the end of your file. This will run the main() function of the Java
      class.

      Kent
      [color=blue]
      >
      > I think this is because I do not understand the jython mechanism for
      > inheritance (yet).
      >
      > JyFitServer.py:
      > ===========
      > import fit.FitServer
      > import fitnesse.compon ents.FitProtoco l
      > 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 FitServer(fit.F itServer):
      > # call constructor of superclass
      > def __init__(self, host, port, verbose):
      > FitServer.__ini t__(self, host, port, verbose)
      >
      > # override process method
      > def process(self):
      > self.fixture.li stener = self.fixtureLis tener
      > print "hello, I am JyFitServer!"
      > try:
      > size = FitProtocol.rea dSize(self.sock etReader)
      > if size > 0:
      > try:
      > document =
      > FitProtocol.rea dDocument(self. socketReader, size)
      > tables = Parse(document)
      > fixture = Fixture()
      > fixture.listene r = self.fixtureLis tener;
      > fixture.doTable s(tables)
      > self.counts.tal ly(self.fixture .counts)
      > except FitParseExcepti on, e:
      > self.exception( e)
      > except Exception, e:
      > self.exception( e)
      >
      >
      >
      > Please help,
      > Mark Fink
      >[/color]

      Comment

      • Mark Fink

        #4
        Re: Jython inherit from Java class

        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.IOExcep tion: CreateProcess: jython
        D:\AUT_TEST\wor kspace\JyFIT\fi t\JyFitServer.p y
        -Dpython.path='D :\AUT_TEST\work space\JyFIT'
        D:\AUT_TEST\fit nesse\fitnesse. jar localhost 1234 23 error=2
        at java.lang.Proce ssImpl.create(N ative Method)
        at java.lang.Proce ssImpl.<init>(U nknown Source)
        at java.lang.Proce ssImpl.start(Un known Source)
        at java.lang.Proce ssBuilder.start (Unknown Source)
        at java.lang.Runti me.exec(Unknown Source)
        at java.lang.Runti me.exec(Unknown Source)
        at java.lang.Runti me.exec(Unknown Source)
        at
        FitServerTest.F itServerTest.pr epareSessionPro cess(FitServerT est.java:163)
        at
        FitServerTest.F itServerTest.te stSimpleStartUp (FitServerTest. java:36)
        at sun.reflect.Nat iveMethodAccess orImpl.invoke0( Native Method)
        at sun.reflect.Nat iveMethodAccess orImpl.invoke(U nknown Source)
        at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(Unknown Source)
        at java.lang.refle ct.Method.invok e(Unknown Source)
        at junit.framework .TestCase.runTe st(TestCase.jav a:154)
        at junit.framework .TestCase.runBa re(TestCase.jav a:127)
        at junit.framework .TestResult$1.p rotect(TestResu lt.java:106)
        at junit.framework .TestResult.run Protected(TestR esult.java:124)
        at junit.framework .TestResult.run (TestResult.jav a:109)
        at junit.framework .TestCase.run(T estCase.java:11 8)
        at junit.framework .TestSuite.runT est(TestSuite.j ava:208)
        at junit.framework .TestSuite.run( TestSuite.java: 203)
        at
        org.eclipse.jdt .internal.junit .runner.RemoteT estRunner.runTe sts(RemoteTestR unner.java:478)
        at
        org.eclipse.jdt .internal.junit .runner.RemoteT estRunner.run(R emoteTestRunner .java:344)
        at
        org.eclipse.jdt .internal.junit .runner.RemoteT estRunner.main( RemoteTestRunne r.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>jyt hon D:\\AUT_TEST\\w orkspace\\JyFIT \\fit\\JyFitSer ver.py
        -Dpython.path='D :\\AUT_TEST\\wo rkspace\\JyFIT'
        D:\\AUT_TEST\\f itnesse\\fitnes se.jar localhost 1234 23
        Traceback (innermost last):
        File "D:\\AUT_TEST\\ workspace\\JyFI T\\fit\\JyFitSe rver.py", line 42,
        in ?
        java.net.Connec tException: Connection refused: connect
        at java.net.PlainS ocketImpl.socke tConnect(Native Method)
        at java.net.PlainS ocketImpl.doCon nect(PlainSocke tImpl.java:333)
        at
        java.net.PlainS ocketImpl.conne ctToAddress(Pla inSocketImpl.ja va:195)
        at java.net.PlainS ocketImpl.conne ct(PlainSocketI mpl.java:182)
        at java.net.SocksS ocketImpl.conne ct(SocksSocketI mpl.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.e stablishConnect ion(Unknown Source)
        at fit.FitServer.e stablishConnect ion(Unknown Source)
        at fit.FitServer.r un(Unknown Source)
        at sun.reflect.Nat iveMethodAccess orImpl.invoke0( Native Method)
        at
        sun.reflect.Nat iveMethodAccess orImpl.invoke(N ativeMethodAcce ssorImpl.java:3 9)
        at
        sun.reflect.Del egatingMethodAc cessorImpl.invo ke(DelegatingMe thodAccessorImp l.java:25)
        at java.lang.refle ct.Method.invok e(Method.java:5 85)
        at
        org.python.core .PyReflectedFun ction.__call__( PyReflectedFunc tion.java)
        at org.python.core .PyMethod.__cal l__(PyMethod.ja va)
        at org.python.core .PyObject.__cal l__(PyObject.ja va)
        at org.python.core .PyInstance.inv oke(PyInstance. java)
        at
        org.python.pyco de._pyx0.f$0(D: \\AUT_TEST\\wor kspace\\JyFIT\\ fit\\JyFitServe r.py:42)
        at
        org.python.pyco de._pyx0.call_f unction(D:\\AUT _TEST\\workspac e\\JyFIT\\fit\\ JyFitServer.py)
        at org.python.core .PyTableCode.ca ll(PyTableCode. java)
        at org.python.core .PyCode.call(Py Code.java)
        at org.python.core .Py.runCode(Py. java)
        at org.python.core .__builtin__.ex ecfile_flags(__ builtin__.java)
        at
        org.python.util .PythonInterpre ter.execfile(Py thonInterpreter .java)
        at org.python.util .jython.main(jy thon.java)

        java.net.Connec tException: java.net.Connec tException: Connection
        refused: connect

        ###### And the Java FitServer:
        D:\AUT_TEST>jav a -cp D:\\AUT_TEST\\f itnesse\\fitnes se.jar fit.FitServer
        localhost 1234 23
        Exception in thread "main" java.net.Connec tException: Connection
        refused: connect
        at java.net.PlainS ocketImpl.socke tConnect(Native Method)
        at java.net.PlainS ocketImpl.doCon nect(Unknown Source)
        at java.net.PlainS ocketImpl.conne ctToAddress(Unk nown Source)
        at java.net.PlainS ocketImpl.conne ct(Unknown Source)
        at java.net.SocksS ocketImpl.conne ct(Unknown Source)
        at java.net.Socket .connect(Unknow n Source)
        at java.net.Socket .connect(Unknow n Source)
        at java.net.Socket .<init>(Unknow n Source)
        at java.net.Socket .<init>(Unknow n Source)
        at fit.FitServer.e stablishConnect ion(Unknown Source)
        at fit.FitServer.e stablishConnect ion(Unknown Source)
        at fit.FitServer.r un(Unknown Source)
        at fit.FitServer.m ain(Unknown Source)

        .... not to bad.
        That is the code with everything commented out:
        import sys
        import fit.FitServer
        import fitnesse.compon ents.FitProtoco l
        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.li stener = self.fixtureLis tener
        print "hello, I am JyFitServer!"
        try:
        size = FitProtocol.rea dSize(self.sock etReader)
        if size > 0:
        try:
        document =
        FitProtocol.rea dDocument(self. socketReader, size)
        tables = Parse(document)
        fixture = Fixture()
        fixture.listene r = self.fixtureLis tener;
        fixture.doTable s(tables)
        self.counts.tal ly(self.fixture .counts)
        except FitParseExcepti on, 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.exi tCode()

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

        Comment

        • Mark Fink

          #5
          Re: Jython inherit from Java class

          I observed something strange when I tried to compile the jython class:
          D:\AUT_TEST\wor kspace\JyFIT\fi t>jythonc JyFitServer.py
          processing JyFitServer

          Required packages:
          fitnesse.util
          java.io
          java.net
          fitnesse.compon ents*

          Creating adapters:

          Creating .java files:
          JyFitServer module
          JyFitServer extends fit.FitServer

          Compiling .java to .class...
          Compiling with args: ['C:\\Programme\ \Java\\jdk1.5.0 _06\\bin\\javac ',
          '-classpath',
          'D:/AUT_TEST/JyFIT_port/fit;D:\\AUT_TES T\\Jython21\\jy thon.jar;C:\\Pr ogramme\\Java\\ jdk1.5.0_06\\li b\\tools.jar;C: \\
          Java\\jboss-4.0.0\\server\\ default\\lib\\m ysql-connector-java-2.0.14-bin.jar;C:\\Jav a\\jboss-4.0.0\\client\\ jboss-j2ee.jar;C:\\Ja va\\jboss-4.0.0\\client\\ jboss-client.jar;C:\\ Java\\jboss-4.0.0\\client
          \\jbosssx-client.jar;C:\\ Java\\jboss-4.0.0\\client\\ jnp-client.jar;C:\\ Java\\jboss-4.0.0\\client\\ jnet.jar;C:\\Ja va\\jboss-4.0.0\\client\\ jboss-common-client.jar;C:\\ Java\\jboss-4.0.0\\tomcat-4.1.x\\c
          ommon\\lib\\ser vlet.jar;D:\\AU T_TEST\\Jython2 1\\jython.jar;D :\\AUT_TEST\\fi tnesse\\fitness e.jar;D:\\AUT_T EST\\JyFIT_port ;%CLASSPATH%;.\ \jpywork;;D:\\A UT_TEST\\Jython 21\\Tools\\jyth onc;D:\\AUT_TES T\\wo
          rkspace\\JyFIT\ \fit\\.;D:\\AUT _TEST\\Jython21 \\Lib;D:\\AUT_T EST\\workspace\ \JyFIT;D:\\AUT_ TEST\\fitnesse\ \fitnesse.jar;D :\\AUT_TEST\\Jy thon21',
          '.\\jpywork\\Jy FitServer.java']
          1 D:\AUT_TEST\Jyt hon21\org\pytho n\core\Py.java: 989: as of release 1.4,
          'assert' is a keyword, and may not be used as an identifier
          (try -source 1.3 or lower to use 'assert' as an identifier)
          public static void assert(PyObject test, PyObject message) {
          ^
          D:\AUT_TEST\Jyt hon21\org\pytho n\core\Py.java: 995: as of release 1.4,
          'assert' is a keyword, and may not be used as an identifier
          (try -source 1.3 or lower to use 'assert' as an identifier)
          public static void assert(PyObject test) {
          ^
          D:\AUT_TEST\Jyt hon21\org\pytho n\core\Py.java: 996: ')' expected
          assert(test, Py.None);
          ^
          D:\AUT_TEST\Jyt hon21\org\pytho n\parser\Python Grammar.java:67 39: as of
          release 1.5, 'enum' is a keyword, and may not be used as an identifier
          (try -source 1.4 or lower to use 'enum' as an identifier)
          for (java.util.Enum eration enum = jj_expentries.e lements();
          enum.hasMoreEle ments();) {
          ^
          D:\AUT_TEST\Jyt hon21\org\pytho n\parser\Python Grammar.java:67 39: as of
          release 1.5, 'enum' is a keyword, and may not be used as an identifier
          (try -source 1.4 or lower to use 'enum' as an identifier)
          for (java.util.Enum eration enum = jj_expentries.e lements();
          enum.hasMoreEle ments();) {
          ^
          D:\AUT_TEST\Jyt hon21\org\pytho n\parser\Python Grammar.java:67 40: as of
          release 1.5, 'enum' is a keyword, and may not be used as an identifier
          (try -source 1.4 or lower to use 'enum' as an identifier)
          int[] oldentry = (int[])(enum.nextElem ent());
          ^
          D:\AUT_TEST\Jyt hon21\org\pytho n\core\Py.java: 996: incompatible types
          found : org.python.core .PyObject
          required: boolean
          assert(test, Py.None);
          ^
          D:\AUT_TEST\Jyt hon21\org\pytho n\core\PyBeanPr operty.java:36: warning:
          non-varargs call of varargs method with inexact argument type for last
          parameter;
          cast to java.lang.Objec t for a varargs call
          cast to java.lang.Objec t[] for a non-varargs call and to suppress this
          warning
          Object value = getMethod.invok e(iself, Py.EmptyObjects );
          ^
          Note: Some input files use or override a deprecated API.
          Note: Recompile with -Xlint:deprecati on for details.
          Note: Some input files use unchecked or unsafe operations.
          Note: Recompile with -Xlint:unchecked for details.
          7 errors
          1 warning

          ERROR DURING JAVA COMPILATION... EXITING

          D:\AUT_TEST\wor kspace\JyFIT\fi t>
          Looks like something in the Jython core causes the problem
          (org\python\cor e\Py.java) any Ideas what I can do?

          Comment

          • Kent Johnson

            #6
            Re: Jython inherit from Java class

            Mark Fink wrote:[color=blue]
            > I observed something strange when I tried to compile the jython class:
            > 'assert' is a keyword, and may not be used as an identifier
            > (try -source 1.3 or lower to use 'assert' as an identifier)
            > public static void assert(PyObject test, PyObject message) {[/color]
            [color=blue]
            > Looks like something in the Jython core causes the problem
            > (org\python\cor e\Py.java) any Ideas what I can do?[/color]

            I think jythonc is not compatible with Java 1.5, try compiling with 1.4.

            Kent

            Comment

            • Frank LaFond

              #7
              Re: Jython inherit from Java class

              Jython 2.2 Alpha 1 supports Java 1.5

              Frank.

              Kent Johnson wrote:[color=blue]
              > Mark Fink wrote:
              >[color=green]
              >> I observed something strange when I tried to compile the jython class:
              >> 'assert' is a keyword, and may not be used as an identifier
              >> (try -source 1.3 or lower to use 'assert' as an identifier)
              >> public static void assert(PyObject test, PyObject message) {[/color]
              >
              >[color=green]
              >> Looks like something in the Jython core causes the problem
              >> (org\python\cor e\Py.java) any Ideas what I can do?[/color]
              >
              >
              > I think jythonc is not compatible with Java 1.5, try compiling with 1.4.
              >
              > Kent[/color]

              Comment

              • Mark Fink

                #8
                Re: Jython inherit from Java class

                Please enlighten me. This seemed so easy yust inherit from a Java class
                overwrite one method - done. At the moment I do not know how to proceed
                :-((
                Jython or jythonc?
                =============== ===
                In general is it better to run programms with the jython interpreter or
                is it better to compile them first? I had the impression that the
                inheritance does not work with the interpreter. Is that right?

                2.1 or 2.2a
                ===========
                The programm did not compile with the 2.1 version and Java 1.5. But
                with 2.2a it compiled but 2.2a is an alpha version. Assuming the
                programm would compile with the Java 1.4 version would it be better
                (saver, more stable, performance) to use 2.1 or 2.2a?

                Inherit from java baseclass or reimplement the whole thing in jython?
                =============== =============== =============== =============== =========
                All the problems with Jython stated when I wanted to inherit from a
                Java baseclass. I wounder if I would have more success when
                implementing it in pure Jython. Regarding the inheritance I had an
                empty wrapper arround the Java baseclass and 70% of the unit test
                passed. But the performance was ~ factor 10 slower than using the base
                class directly. Does this mean that there is overhead with the
                inheritanc construct and that this implementation path would always be
                so slow. On the other hand would a 100% Jython solution be faster?

                Mark

                Comment

                • Kent Johnson

                  #9
                  Re: Jython inherit from Java class

                  Frank LaFond wrote:[color=blue]
                  > Jython 2.2 Alpha 1 supports Java 1.5[/color]

                  It is also buggy and IIRC has a broken jythonc which is what the OP is
                  trying to use.

                  Kent

                  Comment

                  • Kent Johnson

                    #10
                    Re: Jython inherit from Java class

                    Mark Fink wrote:[color=blue]
                    > Please enlighten me. This seemed so easy yust inherit from a Java class
                    > overwrite one method - done. At the moment I do not know how to proceed
                    > :-(([/color]

                    It should be easy.
                    [color=blue]
                    > Jython or jythonc?
                    > =============== ===
                    > In general is it better to run programms with the jython interpreter or
                    > is it better to compile them first? I had the impression that the
                    > inheritance does not work with the interpreter. Is that right?[/color]

                    I personally avoid jythonc, I have not had success with it. Others
                    apparently have and use it.

                    Inheritance works fine without jythonc. The limitation in non-compiled
                    Jython is in the methods that are visible to Java code. Java code will
                    only see methods of a Jython class that are declared in a Java class or
                    interface that the Jython class extends or implements.

                    For example:

                    Java:

                    public class Foo {
                    public int value() { return 3; }
                    }

                    public interface Bar {
                    public int anotherValue();
                    }

                    Jython:
                    class Baz(Foo, Bar):
                    def value(self): return 5
                    def anotherValue(se lf): return 7
                    def somethingComple telyDifferent(s elf): return 42

                    Now, a Java client that has an instance of Baz will be able to call
                    baz.value()
                    baz.anotherValu e()
                    but
                    baz.somethingCo mpletelyDiffere nt()
                    will not be possible even using Java introspection.

                    OTOH a Jython client will be able to access all three methods of baz.
                    [color=blue]
                    >
                    > 2.1 or 2.2a
                    > ===========
                    > The programm did not compile with the 2.1 version and Java 1.5. But
                    > with 2.2a it compiled but 2.2a is an alpha version. Assuming the
                    > programm would compile with the Java 1.4 version would it be better
                    > (saver, more stable, performance) to use 2.1 or 2.2a?[/color]

                    IMO Jython 2.2a1 is not near ready for production use. Jython 2.1 is
                    very stable and usable.
                    [color=blue]
                    > Inherit from java baseclass or reimplement the whole thing in jython?
                    > =============== =============== =============== =============== =========
                    > All the problems with Jython stated when I wanted to inherit from a
                    > Java baseclass. I wounder if I would have more success when
                    > implementing it in pure Jython. Regarding the inheritance I had an
                    > empty wrapper arround the Java baseclass and 70% of the unit test
                    > passed. But the performance was ~ factor 10 slower than using the base
                    > class directly. Does this mean that there is overhead with the
                    > inheritanc construct and that this implementation path would always be
                    > so slow. On the other hand would a 100% Jython solution be faster?[/color]

                    Inheritance from Java works well and I have never seen performance
                    problems like this.

                    Java JUnit uses introspection to find test methods so it won't find
                    methods of a Jython class.

                    HTH,
                    Kent

                    Comment

                    • Kent Johnson

                      #11
                      Re: Jython inherit from Java class

                      Mark Fink wrote:[color=blue]
                      > 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??[/color]

                      Since you are getting the same error from the Java server and the Jython
                      subclass maybe you should figure out the Java problem first? It seems to
                      be a problem making a socket connection of some kind.

                      Kent
                      [color=blue]
                      > ###### And the Java FitServer:
                      > D:\AUT_TEST>jav a -cp D:\\AUT_TEST\\f itnesse\\fitnes se.jar fit.FitServer
                      > localhost 1234 23
                      > Exception in thread "main" java.net.Connec tException: Connection
                      > refused: connect
                      > at java.net.PlainS ocketImpl.socke tConnect(Native Method)
                      > at java.net.PlainS ocketImpl.doCon nect(Unknown Source)
                      > at java.net.PlainS ocketImpl.conne ctToAddress(Unk nown Source)
                      > at java.net.PlainS ocketImpl.conne ct(Unknown Source)
                      > at java.net.SocksS ocketImpl.conne ct(Unknown Source)
                      > at java.net.Socket .connect(Unknow n Source)
                      > at java.net.Socket .connect(Unknow n Source)
                      > at java.net.Socket .<init>(Unknow n Source)
                      > at java.net.Socket .<init>(Unknow n Source)
                      > at fit.FitServer.e stablishConnect ion(Unknown Source)
                      > at fit.FitServer.e stablishConnect ion(Unknown Source)
                      > at fit.FitServer.r un(Unknown Source)
                      > at fit.FitServer.m ain(Unknown Source)[/color]

                      Comment

                      • Mark Fink

                        #12
                        Re: Jython inherit from Java class

                        Hi Kent,
                        many thanks for your help! In the meantime I received my "Jython
                        Essentials" book and hope that I have much fewer questions in the near
                        future.
                        One last question for this thread. I tried to inherit from a Java class
                        and override on method. I figured that this approach was nonsense
                        because the method used private attributes of the Java class. Now I
                        read that there is injection used in Jython. Jython uses setter and
                        getter methods to do the injection, right? Unfortunately the Java class
                        has no setters and getters for the private members. Is there another
                        way to override the method besides rewriting the Java class or is this
                        approach really doomed?

                        Cheers,
                        Mark

                        Comment

                        • Kent Johnson

                          #13
                          Re: Jython inherit from Java class

                          Mark Fink wrote:[color=blue]
                          > Hi Kent,
                          > many thanks for your help! In the meantime I received my "Jython
                          > Essentials" book and hope that I have much fewer questions in the near
                          > future.
                          > One last question for this thread. I tried to inherit from a Java class
                          > and override on method. I figured that this approach was nonsense
                          > because the method used private attributes of the Java class. Now I
                          > read that there is injection used in Jython. Jython uses setter and
                          > getter methods to do the injection, right? Unfortunately the Java class
                          > has no setters and getters for the private members. Is there another
                          > way to override the method besides rewriting the Java class or is this
                          > approach really doomed?[/color]

                          I don't know what you mean by injection in this context. But Jython has
                          a property "python.securit y.respectJavaAc cessibility" which may help -
                          if you set it to false (on the command line or the Jython registry (see
                          the docs)) then Jython code can access private members of Java objects.

                          It seems a bit of a hack but it might help you out. Changing the Java
                          class to make the private members be protected seems like a better fix
                          if you can do it.

                          Kent

                          Comment

                          Working...