Guest User

Untitled

a guest
Jul 10th, 2018
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. headers.put("Content-Type", "application/json; charset=utf-8");
  2.  
  3. headers.put("Content-Type", "application/x-www-form-urlencoded");
  4.  
  5. try {
  6.  
  7.  
  8.  
  9.  
  10. JSONObject js = new JSONObject();
  11. try {
  12.  
  13. js.put("client_id", "HKTPEMS");
  14. js.put("client_secret", "B83845-9AFDDD-46D7B487D62E13DD86");
  15. js.put("grant_type", "password");
  16. js.put("username", firstName);
  17. js.put("password", password);
  18.  
  19. }catch (JSONException e) {
  20. e.printStackTrace();
  21. }
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. JsonObjectRequest jsonObjReq = new JsonObjectRequest(
  29. Request.Method.POST, url, js, new Response.Listener<JSONObject>() {
  30.  
  31. @Override
  32. public void onResponse(JSONObject response) {
  33. Log.e(TAG, "response = " + response.toString());
  34.  
  35. iResult.notifySuccess(response);
  36.  
  37.  
  38. ContentValues cv = new ContentValues();
  39. String accessToken = null;
  40. String refreshToken = null;
  41.  
  42. try {
  43.  
  44.  
  45. //Get the accessToken
  46. accessToken = (String) response.get("access_token");
  47. Log.e(TAG, "accessToken = " + accessToken);
  48.  
  49. //Get the refreshToken
  50. refreshToken = (String) response.get("refresh_token");
  51. Log.e(TAG, "refreshToken = " + refreshToken);
  52.  
  53. }catch (Exception e){}
  54.  
  55.  
  56.  
  57.  
  58. cv.putNull(LoginValidate.C_ID_TOKENS);
  59. cv.put(LoginValidate.C_TOKENS_ACCESS_TOKEN, accessToken);
  60. cv.put(LoginValidate.C_TOKENS_REFRESH_TOKEN, refreshToken);
  61.  
  62. appObj.loginValidate.insertIntoTokens(cv);
  63.  
  64.  
  65.  
  66.  
  67. cvResult.put("resultcode", "OK");
  68.  
  69.  
  70.  
  71.  
  72. }
  73. }, new Response.ErrorListener() {
  74.  
  75. @Override
  76. public void onErrorResponse(VolleyError error) {
  77. Log.e(TAG, "Error: " + error.getMessage());
  78. Log.e(TAG, "Error stackTrace: " + error.getStackTrace().toString());
  79.  
  80. iResult.notifyError(error);
  81.  
  82. }
  83. }) {
  84.  
  85.  
  86. @Override
  87. public Map<String, String> getHeaders() throws AuthFailureError {
  88. HashMap<String, String> headers = new HashMap<String, String>();
  89. headers.put("Content-Type", "application/json; charset=utf-8");
  90. //headers.put("Content-Type", "application/x-www-form-urlencoded");
  91.  
  92. return headers;
  93. }
  94.  
  95.  
  96.  
  97. };
  98.  
  99.  
  100. RequestQueue queue = appObj.getRequestQueue();
  101. queue.add(jsonObjReq);
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. } catch (Exception e) {
  109. Log.e("json","e.getLocalizedMessage()"+ e.getLocalizedMessage());
  110. cvResult.put("resultcode", "ERROR: problem getting the tokens");
  111. }
  112.  
  113. /WebServicesForWebApi: inside WS getAuthenticationTokens()
  114. E/LoginValidate: url already exists in DB, so returning it
  115. E/WebServicesForWebApi: checking url for getting tokens. url = https://abc.xyz.co.uk/Token
  116. E/LoginValidate: password already exists in DB, so returning it
  117. E/LoginValidate: username already exists in DB, so returning it
  118. E/WebServicesForWebApi: username = de4bcbc0bac3@XXXX.com
  119. E/WebServicesForWebApi: password = 90661f6a-11c0-4bb3-b92a-cd9e38dfd229
  120. E/WebServicesForWebApi: tokenCountInDB = 0
  121. E/InstallationActivity: ContententsValues for tokens has size = 0
  122. I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
  123. I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
  124. E/Volley: [55345] BasicNetwork.performRequest: Unexpected response code 400 for https://abc.xyz.co.uk/Token
  125. E/WebServicesForWebApi: Error: null
  126. E/WebServicesForWebApi: Error stackTrace: [Ljava.lang.StackTraceElement;@33976bc
  127. E/InstallationActivity: ERROR for getAuthenticationTokens() = com.android.volley.ServerError
Add Comment
Please, Sign In to add comment