am using two nested volley requests at the same server but the second one returns with error :
StringRequest strReqUpdate = new StringRequest(Request.Method.GET, versionCheckURL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
initJson = response;
try {
JSONObject root = new JSONObject(initJson);
final long version = root.getLong("latest_update");
long localVersion = prefs.getLong("version", 0);
boolean flag = false;
if(version != localVersion){
flag = true;
}
if(flag == true){
StringRequest strReq = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
SharedPreferences.Editor editor = prefs.edit();
editor.putString("json", response);
editor.putLong("version", version);
editor.commit();
parseData(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
String cachedResponse = prefs.getString("json", "");
if (!cachedResponse.equals("")) {
parseData(cachedResponse);
} else {
Toast.makeText(MainActivity.this, getString(R.string.network_error), Toast.LENGTH_LONG).show();
finish();
}
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("key", getResources().getString(R.string.api_key));
return headers;
}
};
strReq.setShouldCache(false);
AppController.getInstance().addToRequestQueue(strReq, Constants.TAG_STRING_REQ);
}
else{
String cachedResponse = prefs.getString("json", "");
if (!cachedResponse.equals("")) {
parseData(cachedResponse);
} else {
Toast.makeText(MainActivity.this, getString(R.string.network_error), Toast.LENGTH_LONG).show();
finish();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
String cachedResponse = prefs.getString("json", "");
if (!cachedResponse.equals("")) {
parseData(cachedResponse);
} else {
Toast.makeText(MainActivity.this, getString(R.string.network_error), Toast.LENGTH_LONG).show();
finish();
}
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("key",getResources().getString(R.string.api_key));
return headers;
}
};
strReqUpdate.setShouldCache(false);
AppController.getInstance().addToRequestQueue(strReqUpdate, Constants.TAG_STRING_REQ);
what am doing here is making a request to see if there is an update to my JSON and if there is start a request to fetch it(if not get cashed JSON). Both requests are to a heroku server with ssl but only second request throws an error. I think am getting an ssl error, I even tried to over-wright the ssl handshake as seen from various posts but nothing works.
The second request isolated is :
StringRequest strReq = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
SharedPreferences.Editor editor = prefs.edit();
editor.putString("json", response);
editor.putLong("version", version);
editor.commit();
parseData(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
String cachedResponse = prefs.getString("json", "");
if (!cachedResponse.equals("")) {
parseData(cachedResponse);
} else {
Toast.makeText(MainActivity.this, getString(R.string.network_error), Toast.LENGTH_LONG).show();
finish();
}
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("key", getResources().getString(R.string.api_key));
return headers;
}
};
strReq.setShouldCache(false);
AppController.getInstance().addToRequestQueue(strReq, Constants.TAG_STRING_REQ);
What am getting on log :
javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x61ff28f0: Failure in SSL library, usually a protocol error error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:744 0x5df0b6fd:0x00000000)