Dukascopy
 
 
Wiki JStore Search Login

JFOREX-3562 JForex classloader issue with Google GData jars
 Post subject: JFOREX-3562 JForex classloader issue with Google GData jars Post rating: 0   New post Posted: Mon 07 Nov, 2011, 10:41 

User rating: 0
Joined: Thu 23 Jun, 2011, 07:26
Posts: 18
Location: United KingdomUnited Kingdom
I'm trying to integrate a JForex strategy with Google's online
spreadsheets using the GData jars. I simply want to update a spreadsheet using the Google GData APIs from within the strategy.

My hunch is that the JForex class loader is having issues with the google GData jars.

The Spreadsheet code is straightforward and works fine in Eclipse and
compiles ok in JForex editor.
Code
-------
package jforex;

import java.util.*;

import com.dukascopy.api.*;

// Google gdata imports
import com.google.gdata.client.spreadsheet.SpreadsheetService;
import com.google.gdata.data.spreadsheet.SpreadsheetEntry;
import com.google.gdata.data.spreadsheet.SpreadsheetFeed;
import com.google.gdata.client.spreadsheet.FeedURLFactory;
import com.google.gdata.client.spreadsheet.SpreadsheetQuery;
import com.google.gdata.client.spreadsheet.WorksheetQuery;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;
import com.google.gdata.data.spreadsheet.CellEntry;
import com.google.gdata.data.spreadsheet.CellFeed;
import com.google.gdata.data.spreadsheet.ListEntry;
import com.google.gdata.data.spreadsheet.WorksheetEntry;
import com.google.gdata.data.spreadsheet.WorksheetFeed;
import com.google.gdata.data.spreadsheet.Cell;
import com.google.gdata.client.spreadsheet.CellQuery;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

// Google gdata library jars
@Library("/home/google/gdata/java/lib/gdata-client-1.0.jar:/home/google/gdata/java/lib/gdata-client-meta-1.0.jar:/home/google/gdata/java/lib/gdata-spreadsheet-meta-3.0.jar:/home/google/gdata/java/lib/gdata-media-1.0.jar:/home/google/gdata/java/lib/gdata-spreadsheet-3.0.jar:/home/google/gdata/java/lib/gdata-core-1.0.jar:/home/google/gdata/java/deps/google-collect-1.0-rc1.jar:/home/google/gdata/java/deps/jsr305.jar")

@RequiresFullAccess
public class tradeit implements IStrategy {
       private IEngine engine;
       private IConsole console;
       private IHistory history;
       private IContext context;
       private IIndicators indicators;
       private IUserInterface userInterface;

      private SpreadsheetService sservice;
      private FeedURLFactory factory;

   public void onStart(IContext context) throws JFException {
       this.engine = context.getEngine();
       this.console = context.getConsole();
       this.history = context.getHistory();
       this.context = context;
       this.indicators = context.getIndicators();
       this.userInterface = context.getUserInterface();

       try {
           factory = FeedURLFactory.getDefault();

           sservice = new SpreadsheetService("jforextest");


sservice = new SpreadsheetService("jforextest"); <=== This line causes JForex strategy to stop with no errors - see Messages below.

-----------------
Messages
15:16:59 Strategy "tradeit" is stopped at 2011-11-05 15:16:59.337
GMT on the local computer with no parameters
15:16:59 Stopping "tradeit" strategy at 2011-11-05 15:16:59.332
GMT on the local computer
15:16:59 Strategy "tradeit" is started at 2011-11-05 15:16:59.287
GMT on the local computer with no parameters
15:16:59 Starting "tradeit" strategy at 2011-11-05 15:16:59.214
GMT on the local computer


-------------
I started the Java console to see if this would give any more
information and it does:
05.11.2011 15:16:59.331   SEVERE      connect.JForexTaskManager ] null
java.lang.ExceptionInInitializerError
       at jforex.tradeit.onStart(tradeit.java:117)
       at com.dukascopy.api.impl.execution.s.call(Unknown Source)
       at com.dukascopy.api.impl.connect.an.a(Unknown Source)
       at com.dukascopy.api.impl.connect.v.call(Unknown Source)
       at com.dukascopy.api.impl.connect.v.call(Unknown Source)
       at com.dukascopy.api.impl.execution.i.call(Unknown Source)
       at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
       at java.util.concurrent.FutureTask.run(Unknown Source)
       at com.dukascopy.api.impl.execution.e$a.f(Unknown Source)
       at com.dukascopy.api.impl.execution.e$a.run(Unknown Source)
       at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
       at com.google.gdata.client.Service.<clinit>(Service.java:97)
       ... 11 more

----------
Googling seems to support that the JForex class loader is having
problems.
Similar bug: https://bugs.eclipse.org/bugs/show_bug. ... &id=344239

It compiles fine in the JForex editor with the @Library and
imports, but using the actual jars at runtime is problematic.

I am running Fedora 15 (Linux) with Oracle Java 6 update 29 (latest)
and Firefox.

Regards,

Geoff.


 
 Post subject: Re: JForex classloader issue with Google GData jars Post rating: 0   New post Posted: Tue 08 Nov, 2011, 09:05 

User rating: 0
Joined: Thu 23 Jun, 2011, 07:26
Posts: 18
Location: United KingdomUnited Kingdom
Update: I tried the same code on a Windows XP host and get exactly the same symptoms.
N.B. @Library was changed to Windows friendly format, i.e. c:\\temp\\gdata\\java\\lib\\gdata-client-1.0.jar;c:\\temp\\gdata\\lib\\gdata-spreadsheet-3.0.jar.....


 
 Post subject: Re: JForex classloader issue with Google GData jars Post rating: 0   New post Posted: Fri 18 Nov, 2011, 16:37 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
qldvoipster wrote:
My hunch is that the JForex class loader is having issues with the google GData jars.
1) Have you managed to successfully run a non-JForex java application that uses the libraries? JForex uses standard java classloader, so if it is a java bug, then we can't do much about it.
2) Before launching the strategy in client, first you can try it in Standalone JForex API. There you don't need to use the @Library annotation.


 
 Post subject: Re: JForex classloader issue with Google GData jars Post rating: 0   New post Posted: Tue 14 Feb, 2012, 22:39 

User rating: 0
Joined: Thu 23 Jun, 2011, 07:26
Posts: 18
Location: United KingdomUnited Kingdom
Sorry for the delay. Couldn't log into the damn forum for some reason.

Okay, in answer to your questions.
1) I tried it out with a non-JForex application using these libraries and it works fine. You can download Google's GDATA jars and try out their demo applications for spreadsheets and it all works great.
2) It tried it with the standalone JForex API using Eclipse and instead of using the @Library syntax, I included the same Jars as external dependencies when I created my project. Again, it worked fine.

It is only playing up when run from the JForex environment. It never gets past the first GData library spreadsheet call.


 
 Post subject: Re: JForex classloader issue with Google GData jars Post rating: 0   New post Posted: Fri 17 Feb, 2012, 10:17 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Consider doing the following:
  1. Make an Eclipse project with a single class which makes the call
    sservice = new SpreadsheetService("jforextest");
    for instance:
    package jforex.test;

    //.. your imports

    public class SpreadSheetTest {

       public static void main(String[] args) {
          //.. initialization
          sservice = new SpreadsheetService("jforextest");
       }
    }
  2. Test if it works successfully in Eclipse.
  3. Then export the project with its dependencies to a jar file.
  4. Attach the jar to a strategy by using @Library (note that you would neet to add only one jar here). Add to startegy the call SpreadSheetTest.main(null). Test if it works in JForex environment.


 
 Post subject: Re: JForex classloader issue with Google GData jars Post rating: 0   New post Posted: Fri 24 Feb, 2012, 11:26 

User rating: 0
Joined: Thu 23 Jun, 2011, 07:26
Posts: 18
Location: United KingdomUnited Kingdom
Ok. Did as you requested. Bit of a kludge as you've got to make a runnable Jar from eclipse.
It worked fine in Eclipse, but I get exactly the same error as last time when the strategy launches in JForex.

24.02.2012 10:12:31.883 SEVERE connect.JForexTaskManager ] null
java.lang.ExceptionInInitializerError
at com.testpackage.jfutils.Spreadsheet.main(Spreadsheet.java:36)
at singlejartest.BoxBreakoutDB9.onStart(BoxBreakoutDB9.java:164)
at com.dukascopy.api.impl.execution.u.call(Unknown Source)
at com.dukascopy.api.impl.connect.au.a(Unknown Source)
at com.dukascopy.api.impl.connect.y.call(Unknown Source)
at com.dukascopy.api.impl.connect.y.call(Unknown Source)
at com.dukascopy.api.impl.execution.k.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at com.dukascopy.api.impl.execution.g$a.f(Unknown Source)
at com.dukascopy.api.impl.execution.g$a.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
at com.google.gdata.client.Service.<clinit>(Service.java:97)
... 12 more


Here is the code I used:
package com.testpackage.jfutils;


import com.google.gdata.client.spreadsheet.SpreadsheetService;
import com.google.gdata.data.spreadsheet.SpreadsheetEntry;
import com.google.gdata.data.spreadsheet.SpreadsheetFeed;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

/**
* This is a test template
*/

public class Spreadsheet {

public static void main(String[] args) {

try {

// Create a new Spreadsheet service
SpreadsheetService myService = new SpreadsheetService("My Application");
//myService.setUserCredentials(args[0],args[1]);
myService.setUserCredentials("[email protected]", "mypassword");

// Get a list of all entries
URL metafeedUrl = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
System.out.println("Getting Spreadsheet entries...\n");
SpreadsheetFeed resultFeed = myService.getFeed(metafeedUrl, SpreadsheetFeed.class);
List<SpreadsheetEntry> entries = resultFeed.getEntries();
for(int i=0; i<entries.size(); i++) {
SpreadsheetEntry entry = entries.get(i);
System.out.println("\t" + entry.getTitle().getPlainText());
}
System.out.println("\nTotal Entries: "+entries.size());
}
catch(AuthenticationException e) {
e.printStackTrace();
}
catch(MalformedURLException e) {
e.printStackTrace();
}
catch(ServiceException e) {
e.printStackTrace();
}
catch(IOException e) {
e.printStackTrace();
}
}
}

And this is the exact list of external JAR dependencies so that it works fine in Eclipse both as a normal application and with the JForex standalone API:
google-collect-1.0-rc1.jar, jsr305.jar, gdata-client-1.0.jar, gdata-client-meta-1.0.jar, gdata-core-1.0.jar, gdata-media-1.0.jar, gdata-spreadsheet-3.0.jar, gdata-spreadsheet-meta-3.0.jar, activation.jar (JAF), mail.jar (JavaMail)
You can download the Google GData jars from: https://code.google.com/p/gdata-java-cli ... p&can=2&q=
And you can easily create a Google GData application with 'most' of the dependencies using the GData Eclipse plugin: https://code.google.com/p/gdata-java-cli ... se-plugin/

Geoff.


 
 Post subject: Re: JForex classloader issue with Google GData jars Post rating: 0   New post Posted: Fri 24 Feb, 2012, 12:41 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We investigated on the matter. The exception gets raised on:
  private static final String SERVICE_VERSION =
      "GData-Java/" + Service.class.getPackage().getImplementationVersion()
          + "(gzip)"; // Necessary to get GZIP encoded responses
at https://code.google.com/p/gdata-java-client/source/browse/trunk/java/src/com/google/gdata/client/Service.java?r=189, because Service.class.getPackage()=null. This is due to a problem in JForex platform compiler and will get fixed with future releases.

As a temporary workaround consider downloading the source of the GData project, change the line to the jar's version (e.g., Service.class.getPackage().getImplementationVersion() to 1.0) and then export the project to a jar.


 
 Post subject: Re: JFOREX-3562 JForex classloader issue with Google GData jars Post rating: 0   New post Posted: Fri 24 Feb, 2012, 13:15 

User rating: 0
Joined: Thu 23 Jun, 2011, 07:26
Posts: 18
Location: United KingdomUnited Kingdom
Thanks for the quick update. Glad it wasn't something stupid I was doing.

I'll keep an eye out for the new release. Any idea which release will fix this?


 
 Post subject: external matlab generated jar gives java.lang.NullPointerException Post rating: 0   New post Posted: Mon 27 Feb, 2012, 17:06 

User rating: 0
Joined: Fri 17 Feb, 2012, 22:14
Posts: 7
I have compiled matlab code to jar using matlab jar builder
function [ lygu ] = lygu( a,b )
lygu=a+b;
end

Then i got class kaina and function lygu. Trying this on netbeans looks like
import com.mathworks.toolbox.javabuilder.MWException;
import kaina.kaina;

public class Simple {
   
    public static void main(String[] args) throws MWException {
        // TODO code application logic here
        Object[] result = null;
       // kaina x=null;
        kaina x = new kaina();
        result = x.lygu(1,5,5);
        System.out.print(result[0]);
    }
}

It works well and prints 10. In jforex the same code gives java.lang.NullPointerException @ hello.matlabo.onStart when creating class kaina object
kaina x = new kaina(); //ERROR
import com.mathworks.toolbox.javabuilder.MWException;
import kaina.kaina;


@Library("kaina.jar;javabuilder.jar")
@RequiresFullAccess
..........
 public void onStart(IContext context) throws JFException {
        this.console = context.getConsole();
         
       try{
        Object[] result = null;
       
        kaina x = new kaina();    // ERROR

        result = x.lygu(1,5,5);
        System.out.println(result[0]);
       }
       catch (MWException e){System.out.println(e);

        this.context = context;
        engine = context.getEngine();
        indicators = context.getIndicators();
    }


Might it be because java library of matlab functions loading and using external dlls? I do use java 1.7.0_03
but tried older as well.


 
 Post subject: Re: JFOREX-3562 JForex classloader issue with Google GData jars Post rating: 0   New post Posted: Wed 29 Feb, 2012, 15:17 

User rating: 0
Joined: Thu 23 Jun, 2011, 07:26
Posts: 18
Location: United KingdomUnited Kingdom
Ok. I've managed to hack the GData jars.

It's not just the file you mentioned which needs to be 'patched'. You have to make the same 'patch' in 3 different files.

1) gdata/client/Service.java - line 95
2) gdata/client/spreadsheet/SpreadsheetService.java - line 48
3) gdata/client/GoogleAuthTokenFactory.java - line 532

I can now query an online Google spreadsheet. Result!


 
 Post subject: Re: JFOREX-3562 JForex classloader issue with Google GData jars Post rating: 0   New post Posted: Wed 29 Feb, 2012, 16:28 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
qldvoipster wrote:
I'll keep an eye out for the new release. Any idea which release will fix this?
Keep an eye on the Standalone release notes. The fix will be made as soon as available.
qldvoipster wrote:
I can now query an online Google spreadsheet. Result!
You are welcome to share a sample version of your solution in Code Base.


 
 Post subject: Re: external matlab generated jar gives java.lang.NullPointerException Post rating: 0   New post Posted: Wed 29 Feb, 2012, 16:30 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
If it works in standalone than in case of properly added libraries it should also work in JForex client. Could you please provide full stack trace?


 
 Post subject: Re: external matlab generated jar gives java.lang.NullPointerException Post rating: 0   New post Posted: Wed 29 Feb, 2012, 20:10 

User rating: 0
Joined: Fri 17 Feb, 2012, 22:14
Posts: 7
java.lang.NullPointerException
   at com.mathworks.toolbox.javabuilder.internal.MWMCR.newRemoteInstance(MWMCR.java:546)
   at com.mathworks.toolbox.javabuilder.internal.MWMCR.newInstance(MWMCR.java:590)
   at kaina.KainaMCRFactory.newInstance(KainaMCRFactory.java:49)
   at kaina.KainaMCRFactory.newInstance(KainaMCRFactory.java:60)
   at kaina.kaina.<init>(kaina.java:63)
   at hello.matlabo.onStart(matlabo.java:45)
   at com.dukascopy.dds2.greed.agent.strategy.tester.r.run(Unknown Source)
   at com.dukascopy.dds2.greed.agent.strategy.tester.b.Bc(Unknown Source)
   at com.dukascopy.dds2.greed.actions.StrategyTesterAction.yX(Unknown Source)
   at com.dukascopy.dds2.greed.actions.StrategyTesterAction.yw(Unknown Source)
   at com.dukascopy.dds2.greed.actions.c.run(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)


EDIT: i've tried adding this line
MWApplication.initializeApplication(MWMCROption.NOJVM); 

in case matlab mcr starts one more jvm on the same process, but it doesnt help


 
 Post subject: Re: external matlab generated jar gives java.lang.NullPointerException Post rating: 0   New post Posted: Thu 01 Mar, 2012, 14:23 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Does it work in Standalone?
https://www.dukascopy.com/wiki/#Use_in_Eclipse


 
 Post subject: Re: external matlab generated jar gives java.lang.NullPointerException Post rating: 0   New post Posted: Thu 01 Mar, 2012, 15:54 

User rating: 0
Joined: Fri 17 Feb, 2012, 22:14
Posts: 7
Yes, it works. I'm using standalone in netbeans.

If smbdy ties to solve this, so this is matlabmcr for running jar https://www.sferic.com/Matlab/CompilerRunTime.htm
and i do add the jar library to import in jforex


Attachments:
files.rar [464.28 KiB]
Downloaded 333 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: JFOREX-3562 JForex classloader issue with Google GData jars Post rating: 0   New post Posted: Fri 02 Mar, 2012, 09:23 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The error you get is at the line:
String str = System.getProperty(new StringBuilder().append(paramClass.getPackage().getName()).append(".MCRRemoteURL").toString());
because paramClass.getPackage()=null. This is due to a problem in JForex platform compiler and will get fixed with future releases.


 

Jump to:  

cron
  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com