@Override
 public void onResponse(String response) {
   try {
     onResponse(new JSONObject(response));
   } catch (JSONException e) {
     errorListener.onErrorResponse(new ParseError(e.getCause()));
     e.printStackTrace();
   }
 }
Ejemplo n.º 2
0
  @Override
  protected Response<ResponseDTO> parseNetworkResponse(NetworkResponse response) {
    ResponseDTO dto = new ResponseDTO();
    try {
      Gson gson = new Gson();
      String resp = new String(response.data);
      Log.i(LOG, "response string length returned: " + getSize(resp.length()));
      try {
        dto = gson.fromJson(resp, ResponseDTO.class);
        if (dto != null) {
          return Response.success(dto, HttpHeaderParser.parseCacheHeaders(response));
        }
      } catch (Exception e) {
        // ignore, it's a zipped response
      }

      InputStream is = new ByteArrayInputStream(response.data);
      ZipInputStream zis = new ZipInputStream(is);
      @SuppressWarnings("unused")
      ZipEntry entry;
      ByteArrayBuffer bab = new ByteArrayBuffer(2048);

      while ((entry = zis.getNextEntry()) != null) {
        int size = 0;
        byte[] buffer = new byte[2048];
        while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
          bab.append(buffer, 0, size);
        }
        resp = new String(bab.toByteArray());
        dto = gson.fromJson(resp, ResponseDTO.class);
      }
    } catch (Exception e) {
      VolleyError ve = new VolleyError("Exception parsing server data", e);
      errorListener.onErrorResponse(ve);
      Log.e(LOG, "Unable to complete request: " + dto.getMessage(), e);
      return Response.error(new VolleyError(dto.getMessage()));
    }
    end = System.currentTimeMillis();
    Log.e(LOG, "#### comms elapsed time in seconds: " + getElapsed(start, end));
    return Response.success(dto, HttpHeaderParser.parseCacheHeaders(response));
  }
Ejemplo n.º 3
0
 @Override
 public void deliverError(VolleyError error) {
   if (mDialog != null) mDialog.dismiss();
   mErrorListener.onErrorResponse(error);
 }