- Code: Select all
package forexconnect;
import com.fxcore2.*;
public class Login {
public static class mySessionStatusListener implements IO2GSessionStatus {
O2GSession session;
public mySessionStatusListener(O2GSession session) {
System.out.println("creating mySessionStatusListener("+session.toString()+")");
this.session = session;
}
@Override
public void onSessionStatusChanged(O2GSessionStatusCode ogssc) {
System.out.println("status:"+ogssc.toString());
if(ogssc.equals(O2GSessionStatusCode.CONNECTED)) {
session.logout();
}
if(ogssc.equals(O2GSessionStatusCode.DISCONNECTED)) {
Runtime.getRuntime().exit(0);
}
}
@Override
public void onLoginFailed(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
public static class ResponseListener implements IO2GResponseListener {
@Override
public void onRequestCompleted(String string, O2GResponse ogr) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void onRequestFailed(String string, String string1) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void onTablesUpdates(O2GResponse ogr) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
public static void main(String[] args) {
O2GSession session = O2GTransport.createSession();
mySessionStatusListener statusListener = new mySessionStatusListener(session);
session.subscribeSessionStatus(statusListener);
ResponseListener responseListener = new ResponseListener();
session.subscribeResponse(responseListener);
session.login("[color=#FF0000]userID[/color]", "[color=#FF0000]password[/color]", "http://www.fxcorporate.com/Hosts.jsp", "Demo");
System.out.println("loging in");
try { //I've put this 10 min delay here just to keep the app from exiting before it had a...
Thread.sleep(600000); //...chance to log in and out.
} catch (InterruptedException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Running this, the output should be:
- Code: Select all
run:
creating mySessionStatusListener(com.fxcore2.O2GSession@1ccb029)
loging in
status:CONNECTING
status:CONNECTED
status:DISCONNECTING
status:DISCONNECTED
BUILD SUCCESSFUL (total time: 4 seconds)
The purpose is simply to test/demonstrate the ability to log in and out (saying "Hello" to the Fx server).
It's a bit clumsy so I am open to suggestions before I'll start it as a step-by-step article on the wiki. Those were ever so helpfull when I was learning scripting fx in lua. The API SDK doesn't seem to have any good example code.
Also if anybody can test the code to see if it's reliable.