List of usage examples for android.accounts NetworkErrorException NetworkErrorException
public NetworkErrorException(String message, Throwable cause)
From source file:org.smilec.smile.bu.AbstractBaseManager.java
protected static void checkServer(String ip) throws NetworkErrorException { InputStream is = null;/*from ww w.j ava 2 s .c o m*/ String url = SmilePlugUtil.createUrl(ip); try { is = HttpUtil.executeGet(url); } catch (NetworkErrorException e) { throw new NetworkErrorException("Connection errror: " + e.getMessage(), e); } finally { IOUtil.silentClose(is); } if (is == null) { throw new NetworkErrorException("Server unavailable"); } }
From source file:org.smilec.smile.util.HttpUtil.java
private static final InputStream executeMethod(HttpUriRequest request) throws NetworkErrorException { HttpClient client = new DefaultHttpClient(); // Execute// w w w .j a va2 s . com HttpResponse response = null; try { response = client.execute(request); } catch (ClientProtocolException e) { throw new NetworkErrorException("Unexpected error executing request: " + e.getMessage(), e); } catch (IOException e) { throw new NetworkErrorException("Unexpected error request: " + e.getMessage(), e); } // Check the status code StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); try { // Returning the content HttpEntity entity = response.getEntity(); if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR || statusCode == HttpStatus.SC_NOT_FOUND) { JSONObject json = new JSONObject(EntityUtils.toString(entity)); String message = json.getString("message"); throw new NetworkErrorException(message); } if (statusCode != HttpStatus.SC_OK) { throw new NetworkErrorException("Unexpected HTTP Status Code: " + statusCode); } return entity.getContent(); } catch (IllegalStateException e) { throw new NetworkErrorException("Unexpected error returnig the request content: " + e.getMessage(), e); } catch (IOException e) { throw new NetworkErrorException("Unexpected error returnig the request content: " + e.getMessage(), e); } catch (ParseException e) { throw new NetworkErrorException(e.getMessage()); } catch (JSONException e) { throw new NetworkErrorException(e.getMessage()); } }
From source file:org.smilec.smile.bu.AbstractBaseManager.java
protected InputStream get(String ip, Context context, String url) throws NetworkErrorException { connect(ip, context);/*from w w w .j av a 2 s . co m*/ try { return HttpUtil.executeGet(url); } catch (NetworkErrorException e) { throw new NetworkErrorException("Connection error: " + e.getMessage(), e); } }
From source file:org.smilec.smile.bu.AbstractBaseManager.java
protected void put(String ip, Context context, String url, String json) throws NetworkErrorException { connect(ip, context);//from w w w . j ava 2 s . c o m InputStream is = null; try { is = HttpUtil.executePut(url, json); } catch (NetworkErrorException e) { throw new NetworkErrorException("Connection error: " + e.getMessage(), e); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } catch (JSONException e) { throw new RuntimeException(e); } finally { IOUtil.silentClose(is); } if (is == null) { throw new NetworkErrorException("Service unavailable"); } }