public Collection<MessageTwitter> getMessages() throws ErreurReseau { try { URL myUrl = new URL("http://support-twitter.herokuapp.com/starbusmetro"); URLConnection connection = myUrl.openConnection(); connection.setConnectTimeout(20000); connection.setReadTimeout(20000); connection.addRequestProperty("Accept", "application/json"); Gson gson = new GsonBuilder().create(); Type listType = new TypeToken<List<MessageTwitter>>() { }.getType(); return gson.fromJson(new InputStreamReader(connection.getInputStream()), listType); } catch (SocketTimeoutException timeoutException) { throw new ErreurReseau(timeoutException); } catch (UnknownHostException erreurReseau) { throw new ErreurReseau(erreurReseau); } catch (IOException exception) { throw new ErreurReseau(exception); } catch (JsonParseException exception) { throw new ErreurReseau(exception); } } }
protected Result doInBackground(Params... params) { try { myDoBackground(); } catch (ErreurReseau erreurReseau) { erreurReseau.printStackTrace(); erreur = true; } return null; }
ByteArrayOutputStream ostream = new ByteArrayOutputStream(); if (reponse == null || reponse.getEntity() == null) { throw new ErreurReseau("Erreur lors de la récupération de la réponse http"); answer = handler.getObjets(); } catch (IOException socketException) { throw new ErreurReseau(socketException); } catch (SAXException saxException) { throw new ErreurReseau(saxException); } catch (ParserConfigurationException exception) { throw new KeolisException("Erreur lors de l'appel à l'API keolis", exception); throw new ErreurReseau("Erreur dans la réponse données par Keolis.");
@Override protected List<Departure> doInBackground(Void... params) { try { return Keolis.getInstance().getDepartues(favori); } catch (ErreurReseau e) { e.printStackTrace(); return null; } }
throw new ErreurReseau(socketException); } catch (JSONException jsonException) { throw new ErreurReseau(jsonException);