working on #461 issue (login bug because of vocabulary time-out)

parent 409b1325
Showing with 52 additions and 18 deletions
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" /> <excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content> </content>
<orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" /> <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>
\ No newline at end of file
...@@ -41,12 +41,14 @@ import javax.net.ssl.HttpsURLConnection; ...@@ -41,12 +41,14 @@ import javax.net.ssl.HttpsURLConnection;
public class RestapiWrapper { public class RestapiWrapper {
String server; String server;
String token; String token;
public static final int TIME_OUT=10000;
// String constant for logs // String constant for logs
private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName() private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName()
public RestapiWrapper(String server, String token) { public RestapiWrapper(String server, String token) {
this.server=server; this.server=server;
this.token=token; this.token=token;
} }
public void setToken(String token) { public void setToken(String token) {
this.token=token; this.token=token;
...@@ -144,8 +146,8 @@ public class RestapiWrapper { ...@@ -144,8 +146,8 @@ public class RestapiWrapper {
url = new URL(surl); url = new URL(surl);
HttpURLConnection urlConnection = null; HttpURLConnection urlConnection = null;
urlConnection = (HttpsURLConnection) url.openConnection(); urlConnection = (HttpsURLConnection) url.openConnection();
urlConnection.setReadTimeout(60000); urlConnection.setReadTimeout(TIME_OUT);
urlConnection.setConnectTimeout(60000); urlConnection.setConnectTimeout(TIME_OUT);
urlConnection.setRequestMethod("GET"); urlConnection.setRequestMethod("GET");
urlConnection.setDoInput(true); urlConnection.setDoInput(true);
urlConnection.connect(); urlConnection.connect();
...@@ -171,8 +173,8 @@ public class RestapiWrapper { ...@@ -171,8 +173,8 @@ public class RestapiWrapper {
HttpURLConnection urlConnection = null; HttpURLConnection urlConnection = null;
urlConnection = (HttpsURLConnection) url.openConnection(); urlConnection = (HttpsURLConnection) url.openConnection();
urlConnection.setReadTimeout(60000); urlConnection.setReadTimeout(TIME_OUT);
urlConnection.setConnectTimeout(60000); urlConnection.setConnectTimeout(TIME_OUT);
urlConnection.setRequestMethod(request_method); urlConnection.setRequestMethod(request_method);
urlConnection.setDoInput(true); urlConnection.setDoInput(true);
urlConnection.setDoOutput(true); urlConnection.setDoOutput(true);
...@@ -254,7 +256,7 @@ public class RestapiWrapper { ...@@ -254,7 +256,7 @@ public class RestapiWrapper {
? GET(params[0].url, params[0].url_params) ? GET(params[0].url, params[0].url_params)
: POST(params[0].url, params[0].request_method, params[0].url_params, params[0].json_params); : POST(params[0].url, params[0].request_method, params[0].url_params, params[0].json_params);
} catch (IOException e) { } catch (IOException e) {
Log.e(com.yottacode.net.RestapiWrapper.class.getName(), "Error:" + e.getLocalizedMessage() + " when asking for " + params[0].url); Log.e(com.yottacode.net.RestapiWrapper.class.getName(), "Error: '" + e.getLocalizedMessage() + "' when asking for " + params[0].url);
params[0].result=null; params[0].result=null;
params[0].error=e; params[0].error=e;
} }
...@@ -288,4 +290,4 @@ public class RestapiWrapper { ...@@ -288,4 +290,4 @@ public class RestapiWrapper {
if (params.url_params!=null) params.url_params.clear(); if (params.url_params!=null) params.url_params.clear();
} }
} }
} }
\ No newline at end of file
...@@ -3,6 +3,7 @@ package com.yottacode.pictogram.grammar; ...@@ -3,6 +3,7 @@ package com.yottacode.pictogram.grammar;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.util.Log; import android.util.Log;
import com.yottacode.pictogram.R;
import com.yottacode.pictogram.action.VocabularyAction; import com.yottacode.pictogram.action.VocabularyAction;
import com.yottacode.pictogram.dao.PCBDBHelper; import com.yottacode.pictogram.dao.PCBDBHelper;
import com.yottacode.pictogram.dao.Picto; import com.yottacode.pictogram.dao.Picto;
...@@ -13,6 +14,7 @@ import com.yottacode.net.iRestapiListener; ...@@ -13,6 +14,7 @@ import com.yottacode.net.iRestapiListener;
import com.yottacode.pictogram.action.Room; import com.yottacode.pictogram.action.Room;
import com.yottacode.pictogram.net.iImgDownloaderListener; import com.yottacode.pictogram.net.iImgDownloaderListener;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.tools.GUITools;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
...@@ -37,7 +39,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -37,7 +39,7 @@ public class Vocabulary implements Iterable<Picto> {
Hashtable<Integer,LinkedList<Picto>> pictos; Hashtable<Integer,LinkedList<Picto>> pictos;
static int DEFAULT_VOCABULARY_SIZE=200; static int DEFAULT_VOCABULARY_SIZE=200;
VocabularyTalk talk; VocabularyTalk talk;
iImgDownloaderListener imgListener; iImgDownloaderListener imgListener;
/** /**
...@@ -56,6 +58,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -56,6 +58,7 @@ public class Vocabulary implements Iterable<Picto> {
listener.loadComplete(); listener.loadComplete();
} catch (JSONException e) { } catch (JSONException e) {
Log.e(this.getClass().getName(),"Local vocabulary recover failed: "+e.getMessage()); Log.e(this.getClass().getName(),"Local vocabulary recover failed: "+e.getMessage());
listener.error(e);
} }
} }
...@@ -157,6 +160,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -157,6 +160,7 @@ public class Vocabulary implements Iterable<Picto> {
JSONObject picto = null; JSONObject picto = null;
try { try {
for (int i = 0; i < result.length(); i++) { for (int i = 0; i < result.length(); i++) {
Log.e("VOCABULARY DEBUG",result.getJSONObject(i).toString());
picto = result.getJSONObject(i).getJSONObject(jpicto); picto = result.getJSONObject(i).getJSONObject(jpicto);
JSONObject expression = result.getJSONObject(i).getJSONObject(jexpression); JSONObject expression = result.getJSONObject(i).getJSONObject(jexpression);
JSONObject attributes = result.getJSONObject(i).getJSONObject(jattributes); JSONObject attributes = result.getJSONObject(i).getJSONObject(jattributes);
...@@ -181,7 +185,8 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -181,7 +185,8 @@ public class Vocabulary implements Iterable<Picto> {
@Override @Override
public void error(Exception e) { public void error(Exception e) {
Log.e(this.getClass().getName(), " Server restapi error: " + e.getLocalizedMessage()); Log.e(this.getClass().getName(), " Server RESTAPI error: " + e.getLocalizedMessage());
Vocabulary.this.imgListener.error(e);
} }
}); });
...@@ -361,6 +366,11 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -361,6 +366,11 @@ public class Vocabulary implements Iterable<Picto> {
public void loadImg(Img image) { public void loadImg(Img image) {
} }
@Override
public void error(Exception e) {
GUITools.show_alert(PCBcontext.getContext(), R.string.serverError, e.getMessage());
Log.e(this.getClass().getCanonicalName(), "Server error:"+ e.getLocalizedMessage());
}
}); });
} catch (Exception e) { } catch (Exception e) {
picto[0]=null; picto[0]=null;
...@@ -405,4 +415,4 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -405,4 +415,4 @@ public class Vocabulary implements Iterable<Picto> {
return vocabulary; return vocabulary;
} }
} }
\ No newline at end of file
...@@ -18,6 +18,7 @@ import com.yottacode.pictogram.net.ImgDownloader; ...@@ -18,6 +18,7 @@ import com.yottacode.pictogram.net.ImgDownloader;
import com.yottacode.pictogram.net.iImgDownloaderListener; import com.yottacode.pictogram.net.iImgDownloaderListener;
import com.yottacode.pictogram.tools.Img; import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.tools.GUITools;
import java.io.IOException; import java.io.IOException;
import java.util.Vector; import java.util.Vector;
...@@ -86,6 +87,11 @@ public class LoginActivity extends FragmentActivity { ...@@ -86,6 +87,11 @@ public class LoginActivity extends FragmentActivity {
@Override @Override
public void loadImg(Img image) {} public void loadImg(Img image) {}
@Override
public void error(Exception e) {
GUITools.show_alert(PCBcontext.getContext(), R.string.serverError, e.getMessage());
Log.e(this.getClass().getCanonicalName(), "Server error:"+ e.getLocalizedMessage());
}
}, ImgDownloader.tsource.remote); }, ImgDownloader.tsource.remote);
downloader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, imgs); downloader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, imgs);
} }
...@@ -95,4 +101,4 @@ public class LoginActivity extends FragmentActivity { ...@@ -95,4 +101,4 @@ public class LoginActivity extends FragmentActivity {
super.onResume(); super.onResume();
} }
} }
\ No newline at end of file
...@@ -253,6 +253,13 @@ public class SerialActivity extends Activity { ...@@ -253,6 +253,13 @@ public class SerialActivity extends Activity {
public void loadImg(Img image) { public void loadImg(Img image) {
} }
@Override
public void error(Exception e) {
progressDialog.dismiss();
GUITools.show_alert(PCBcontext.getContext(), R.string.serverError, e.getMessage());
Log.e(this.getClass().getCanonicalName(), "Server error:"+ e.getLocalizedMessage());
}
}); });
} }
private void login(String username, String password) { private void login(String username, String password) {
......
...@@ -130,6 +130,10 @@ public class StudentFragmentGrid extends Fragment{ ...@@ -130,6 +130,10 @@ public class StudentFragmentGrid extends Fragment{
public void loadImg(Img image) { public void loadImg(Img image) {
} }
public void error(Exception e) {
GUITools.show_alert(PCBcontext.getContext(), R.string.serverError, e.getMessage());
Log.e(this.getClass().getCanonicalName(), "Server error:"+ e.getLocalizedMessage());
}
}); });
} catch (JSONException e) { } catch (JSONException e) {
...@@ -186,6 +190,11 @@ public class StudentFragmentGrid extends Fragment{ ...@@ -186,6 +190,11 @@ public class StudentFragmentGrid extends Fragment{
public void loadImg(Img image) { public void loadImg(Img image) {
} }
public void error(Exception e) {
progressDialog.dismiss();
GUITools.show_alert(PCBcontext.getContext(), R.string.serverError, e.getMessage());
Log.e(this.getClass().getCanonicalName(), "Server error:"+ e.getLocalizedMessage());
}
}, ImgDownloader.tsource.remote); }, ImgDownloader.tsource.remote);
downloader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, imgs); downloader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, imgs);
} }
......
...@@ -70,7 +70,7 @@ public class PictoUploader { ...@@ -70,7 +70,7 @@ public class PictoUploader {
if (response != null && response.getHeaders().code() == 200) { if (response != null && response.getHeaders().code() == 200) {
Log.i(this.getClass().getCanonicalName(), "Uploaded image result: " + response.getHeaders() + ":" + response.getResult()); Log.i(this.getClass().getCanonicalName(), "Uploaded image result: " + response.getHeaders() + ":" + response.getResult());
img_id=response.getResult().getAsJsonObject("picto").get("id").getAsInt(); img_id=response.getResult().get("id").getAsInt();
} else { } else {
img_id=-1; img_id=-1;
Log.i(this.getClass().getCanonicalName(), "Uploaded image failed "); Log.i(this.getClass().getCanonicalName(), "Uploaded image failed ");
......
...@@ -7,8 +7,10 @@ import java.util.LinkedList; ...@@ -7,8 +7,10 @@ import java.util.LinkedList;
/** /**
* Created by emblanco on 24/09/15. * Created by emblanco on 24/09/15.
* MOdified by dofer on 27/06/16.
*/ */
public interface iImgDownloaderListener { public interface iImgDownloaderListener {
public void loadComplete(); // for loading the vocabulary public void loadComplete(); // for loading the vocabulary
public void loadImg(Img image); // for loading one image public void loadImg(Img image); // for loading one image
public void error(Exception err); //error happens
} }
...@@ -42,9 +42,9 @@ ...@@ -42,9 +42,9 @@
<!-- Login --> <!-- Login -->
<string name="systemMessage">Mensaje del sistema</string> <string name="systemMessage">Mensaje del sistema</string>
<string name="noInternetConnection">No hay conexión a internet. Inténtelo más tarde</string> <string name="noInternetConnection">No hay acceso al Servidor. Inténtelo más tarde</string>
<string name="exitingApp">Saliendo de la aplicación</string> <string name="exitingApp">Saliendo de la aplicación</string>
<string name="serverError">Error en el servidor de datos. Inténtelo más tarde</string> <string name="serverError">Fallo accediendo al Servidor. Inténtelo más tarde</string>
<!--Semantic grammar --> <!--Semantic grammar -->
<string name="loadingGrammar">Por favor espere, cargando vocabulario</string> <string name="loadingGrammar">Por favor espere, cargando vocabulario</string>
......
...@@ -74,6 +74,6 @@ ...@@ -74,6 +74,6 @@
completions." completions."
<!--online/offline status--> <!--online/offline status-->
<string name="pictogram_offline">Compruebe si tiene conexión a Internet. </string> <string name="pictogram_offline">Compruebe si tiene conexión a Internet. </string>
<string name="pictogram_online">Conexón con el servidor establecida. </string> <string name="pictogram_online">Conexión con el servidor establecida. </string>
</string> </string>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment