I have a login form which simple calls a get on a server and reads the JSON response. If the server is running, all is good.
If the server is not running, then you get an exception which throws a dialog to CANCEL or RETRY (not my dialog). This is odd as I can't catch this exception, so cant do anything about it.
If I then hit cancel, then the login button again, i was seeing a message on the console "Duplicate entry detected" then the app hangs with the spinning infnite dialog - there is no event I can use to stop it.
If I hit return, then login button again, I was seeing the message: Duplicate entry in the queue: userclasses.StateMachine$2: userclasses.StateMachine$2@31333a then the app hangs with the spinning infnite dialog - there is no event I can use to stop it.
I tried adding this:
con.setDuplicateSupported(true);
But now the app just hangs on the second send without the "Duplicate" message appearing in the console.
The code is simple, and goes like this:
@Override
protected void onLogin_ButtonLonginAction(Component c, ActionEvent event) {
// do some stuff.
ConnectionRequest con = new ConnectionRequest() {
@Override
protected void postResponse(){
// check the JSON data...
if (name != null && !"".equals(name)) {
Display.getInstance().callSerially(new Runnable() {
public void run() {
showForm("Main", null);
}
});
}
}
@Override
protected void readResponse(InputStream input) throws IOException {
// read the json data.
};
};
con.setPost(false);
con.setUrl(Settings.getUrl() + "/player/login");
con.addArgument("user", usreName);
con.addArgument("pass", password);
con.setTimeout(30*1000);
InfiniteProgress prog = new InfiniteProgress();
Dialog dlg = prog.showInifiniteBlocking();
con.setDisposeOnCompletion(dlg);
con.setDuplicateSupported(true);
try {
NetworkManager.getInstance().addToQueueAndWait(con);
} catch (Exception e) {
dlg.dispose();
Dialog.show("Connection Problem", "Sorry, there was an error connecting to the server", "ok", null);
}
}
In this case, no exception is being caught my my code above.
Full stack trace when DuplicateSupported not set:
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at com.codename1.impl.javase.JavaSEPort.getResponseCode(JavaSEPort.java:3964)
at com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:292)
at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:242)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at com.codename1.impl.javase.JavaSEPort.getResponseCode(JavaSEPort.java:3964)
at com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:292)
at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:242)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
Duplicate entry in the queue: userclasses.StateMachine$2: userclasses.StateMachine$2@31333a
Full stack trace when duplicateSupported set to true:
If I hit "retry", there is no stack trace. It just hangs the app.
If I hit cancel, there is stack trace, it also just hangs the app.