Java Code Examples for com.nextgis.maplib.util.HttpResponse#isOk()
The following examples show how to use
com.nextgis.maplib.util.HttpResponse#isOk() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CreateFromQMSLayerDialog.java From android_maplibui with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected void onPostExecute(HttpResponse response) { super.onPostExecute(response); if (response.isOk()) { try { new JSONObject(response.getResponseBody()); createLayer(response.getResponseBody()); } catch (JSONException ignored) { Toast.makeText(mContext, R.string.qms_unavailable, Toast.LENGTH_SHORT).show(); } } else { Toast.makeText( mContext, NetworkUtil.getError(mContext, response.getResponseCode()), Toast.LENGTH_SHORT).show(); } mChecked.remove(mLayerId); if (mChecked.size() == 0) mGroupLayer.save(); }
Example 2
Source File: CreateFromQMSLayerDialog.java From android_maplibui with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected void onPostExecute(HttpResponse response) { super.onPostExecute(response); if (response.isOk()) { try { new JSONArray(response.getResponseBody()); createList(response.getResponseBody()); } catch (JSONException ignored) { Toast.makeText(mContext, R.string.qms_unavailable, Toast.LENGTH_SHORT).show(); showRetry(); } } else { Toast.makeText( mContext, NetworkUtil.getError(mContext, response.getResponseCode()), Toast.LENGTH_SHORT).show(); showRetry(); } }
Example 3
Source File: TrackerService.java From android_maplibui with GNU Lesser General Public License v3.0 | 6 votes |
private void post(String payload, Context context, List<String> ids) throws IOException { String url = String.format("%s/%s/packet", URL, getUid(context)); // Log.d(Constants.TAG, "Post to " + url); HttpResponse response = NetworkUtil.post(url, payload, null, null, false); // Log.d(Constants.TAG, "Response is " + response.getResponseCode()); if (!response.isOk()) return; ContentValues cv = new ContentValues(); cv.put(TrackLayer.FIELD_SENT, 1); String where = TrackLayer.FIELD_TIMESTAMP + " in (" + MapUtil.makePlaceholders(ids.size()) + ")"; String[] timestamps = ids.toArray(new String[0]); try { context.getContentResolver().update(mContentUriTrackPoints, cv, where, timestamps); } catch (SQLiteException ignored) { } }
Example 4
Source File: NGIDUtils.java From android_maplibui with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected HttpResponse doInBackground(String... args) { String url = args[0]; String method = args[1]; String token = args[2]; if (TextUtils.isEmpty(token)) { try { token = getToken(args); userCheck(token); } catch (IOError e) { return new HttpResponse(NetworkUtil.ERROR_CONNECT_FAILED); } } HttpResponse response = getResponse(url, method, token); if (!response.isOk()) { response = userCheck(token); if (!response.isOk()) return new HttpResponse(NetworkUtil.ERROR_CONNECT_FAILED); else response = getResponse(url, method, token); } return response; }
Example 5
Source File: NGIDUtils.java From android_maplibui with GNU Lesser General Public License v3.0 | 6 votes |
private static String getToken(String... args) throws IOError { String login = args.length > 3 ? args[3] : null; String password = args.length > 4 ? args[4] : null; if (login == null || password == null) throw new IOError(new Throwable("Login or Password is NULL")); try { login = URLEncoder.encode(login, "UTF-8").replaceAll("\\+", "%20"); password = URLEncoder.encode(password, "UTF-8").replaceAll("\\+", "%20"); } catch (UnsupportedEncodingException | NullPointerException ignored) {} String accessNew = String.format(OAUTH_NEW, login, password, BuildConfig.CLIENT_ID); HttpResponse response = getResponse(accessNew, POST, null); if (!response.isOk()) throw new IOError(new Throwable("Response is not OK")); String token = parseResponseBody(response.getResponseBody()); if (token == null) throw new IOError(new Throwable("Token is NULL")); return token; }
Example 6
Source File: LayerWithStyles.java From android_maplib with GNU Lesser General Public License v3.0 | 6 votes |
public void fillExtent() { try { mExtent = new GeoEnvelope(); String url = NGWUtil.getExtent(mConnection.getURL(), mRemoteId); HttpResponse response = NetworkUtil.get(url, mConnection.getLogin(), mConnection.getPassword(), false); if (!response.isOk()) return; JSONObject extent = new JSONObject(response.getResponseBody()).getJSONObject(JSON_EXTENT_KEY); double x = Geo.wgs84ToMercatorSphereX(extent.getDouble(JSON_MAX_LON_KEY)); double y = Geo.wgs84ToMercatorSphereY(extent.getDouble(JSON_MAX_LAT_KEY)); mExtent.setMax(x, y); x = Geo.wgs84ToMercatorSphereX(extent.getDouble(JSON_MIN_LON_KEY)); y = Geo.wgs84ToMercatorSphereY(extent.getDouble(JSON_MIN_LAT_KEY)); mExtent.setMin(x, y); } catch (IOException | JSONException ignored) { } }
Example 7
Source File: NGWLookupTable.java From android_maplib with GNU Lesser General Public License v3.0 | 6 votes |
protected void fillFromNGW(Map<String, String> dataMap, IProgressor progressor) throws IOException, NGException, JSONException { if (!mNet.isNetworkAvailable()) { //return tile from cache throw new NGException(getContext().getString(R.string.error_network_unavailable)); } if(null != progressor){ progressor.setMessage(getContext().getString(R.string.message_loading)); } Log.d(Constants.TAG, "download layer " + getName()); HttpResponse response = NetworkUtil.get(NGWUtil.getResourceUrl(mCacheUrl, mRemoteId), mCacheLogin, mCachePassword, false); if (!response.isOk()) { throw new NGException(NetworkUtil.getError(mContext, response.getResponseCode())); } JSONObject geoJSONObject = new JSONObject(response.getResponseBody()); JSONObject lookupTable = geoJSONObject.getJSONObject("lookup_table"); JSONObject itemsObject = lookupTable.getJSONObject("items"); for (Iterator<String> iter = itemsObject.keys(); iter.hasNext(); ) { String key = iter.next(); String value = itemsObject.getString(key); dataMap.put(key, value); } }
Example 8
Source File: NGWCreateNewResourceTask.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected void onPostExecute(HttpResponse result) { super.onPostExecute(result); String message; if (result.isOk()) { try { JSONObject obj = new JSONObject(result.getResponseBody()); Long id = obj.getLong(Constants.JSON_ID_KEY); if (mLayer != null) mLayer.toNGW(id, mConnection.getName(), Constants.SYNC_ALL, mVer); result.setResponseCode(-999); } catch (JSONException e) { result.setResponseCode(500); e.printStackTrace(); } } switch (result.getResponseCode()) { case -999: message = mContext.getString(mLayer == null ? R.string.message_group_created : R.string.message_layer_created); break; default: message = NetworkUtil.getError(mContext, result.getResponseCode()); break; } Toast.makeText(mContext, message, Toast.LENGTH_LONG).show(); }
Example 9
Source File: Connection.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
protected void fillCapabilities() { mSupportedTypes.clear(); try { String sURL = mURL + "/resource/schema"; HttpResponse response = NetworkUtil.get(sURL, getLogin(), getPassword(), false); if (!response.isOk()) return; JSONObject schema = new JSONObject(response.getResponseBody()); JSONObject resources = schema.getJSONObject("resources"); if (null != resources) { Iterator<String> keys = resources.keys(); while (keys.hasNext()) { int type = getType(keys.next()); if (type != NGWResourceTypeNone) { if (mSupportedTypes.isEmpty()) { mSupportedTypes.add(type); } else if (!isTypeSupported(type)) { mSupportedTypes.add(type); } } } } } catch (IOException | JSONException e) { e.printStackTrace(); } }
Example 10
Source File: Resource.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
public void fillPermissions() { try { String sURL = NGWUtil.getResourceUrl(mConnection.getURL(), mRemoteId) + "/permission"; HttpResponse response = NetworkUtil.get(sURL, mConnection.getLogin(), mConnection.getPassword(), false); if (!response.isOk()) return; mPermissions = new JSONObject(response.getResponseBody()); if (!mPermissions.has(Constants.JSON_RESOURCE_KEY)) mPermissions = null; } catch (IOException | JSONException e) { e.printStackTrace(); } }
Example 11
Source File: NGWRasterLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Bitmap getBitmap(TileItem tile) { if (!mExtentReceived) { HttpResponse result = null; try { AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, getAccountName()); result = NetworkUtil.get(NGWUtil.getExtent(accountData.url, mRemoteId), getLogin(), getPassword(), false); if (!result.isOk()) { throw new IllegalStateException(""); } JSONObject extent = new JSONObject(result.getResponseBody()).getJSONObject(JSON_EXTENT_KEY); double x = Geo.wgs84ToMercatorSphereX(extent.getDouble(JSON_MAX_LON_KEY)); double y = Geo.wgs84ToMercatorSphereY(extent.getDouble(JSON_MAX_LAT_KEY)); mExtents.setMax(x, y); x = Geo.wgs84ToMercatorSphereX(extent.getDouble(JSON_MIN_LON_KEY)); y = Geo.wgs84ToMercatorSphereY(extent.getDouble(JSON_MIN_LAT_KEY)); mExtents.setMin(x, y); mExtentReceived = true; } catch (IOException | JSONException | IllegalStateException ignored) { if (result != null && result.getResponseCode() == 404) mExtentReceived = true; } } if (mExtents.intersects(tile.getEnvelope())) return super.getBitmap(tile); return null; }