com.nextgis.maplib.util.HttpResponse Java Examples
The following examples show how to use
com.nextgis.maplib.util.HttpResponse.
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: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 6 votes |
protected HttpResponse sendFeatureAttachOnServer(JSONObject result, long featureId, AttachItem attach) throws JSONException, IOException { // add attachment to row JSONObject postJsonData = new JSONObject(); JSONArray uploadMetaArray = result.getJSONArray("upload_meta"); postJsonData.put("file_upload", uploadMetaArray.get(0)); postJsonData.put("description", attach.getDescription()); String postload = postJsonData.toString(); if (Constants.DEBUG_MODE) { Log.d(Constants.TAG, "postload: " + postload); } // get account data AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName); // upload file String url = NGWUtil.getFeatureAttachmentUrl(accountData.url, mRemoteId, featureId); // update record in NGW return NetworkUtil.post(url, postload, accountData.login, accountData.password, false); }
Example #3
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 #4
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 #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: 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 #7
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 #8
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 #9
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 #10
Source File: NGIDUtils.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected void onPostExecute(HttpResponse result) { super.onPostExecute(result); if (mCallback != null) mCallback.onFinish(result); }
Example #11
Source File: NGIDLoginFragment.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void onClick(View v) { if (v.getId() == R.id.signin) { final Activity activity = getActivity(); if (activity == null) return; boolean loginPasswordFilled = checkEditText(mLogin) && checkEditText(mPassword); if (!loginPasswordFilled) { Toast.makeText(activity, R.string.field_not_filled, Toast.LENGTH_SHORT).show(); return; } IGISApplication application = (IGISApplication) activity.getApplication(); application.sendEvent(ConstantsUI.GA_NGID, ConstantsUI.GA_CONNECT, ConstantsUI.GA_USER); mSignInButton.setEnabled(false); String login = mLogin.getText().toString().trim(); String password = mPassword.getText().toString(); NGIDUtils.getToken(activity, login, password, new NGIDUtils.OnFinish() { @Override public void onFinish(HttpResponse response) { mSignInButton.setEnabled(true); if (response.isOk()) { activity.getIntent().putExtra(NGIDLoginActivity.EXTRA_SUCCESS, true); activity.finish(); } else { Toast.makeText( activity, NetworkUtil.getError(activity, response.getResponseCode()), Toast.LENGTH_SHORT).show(); } } }); } else if (v.getId() == R.id.signup) { Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(NGIDUtils.NGID_MY)); startActivity(browser); } }
Example #12
Source File: NGIDUtils.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
private static HttpResponse getResponse(String target, String method, String token) { try { URL url = new URL(target); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); if (!TextUtils.isEmpty(token)) conn.setRequestProperty("Authorization", token); conn.setRequestMethod(method); conn.connect(); BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line, data = ""; while ((line = in.readLine()) != null) data += line; in.close(); HttpResponse response = new HttpResponse(200); response.setResponseBody(data); response.setOk(true); return response; } catch (IOException ignored) { ignored.printStackTrace(); } return new HttpResponse(NetworkUtil.ERROR_CONNECT_FAILED); }
Example #13
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 #14
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 #15
Source File: CreateFromQMSLayerDialog.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected HttpResponse doInBackground(Void... params) { if (!mNet.isNetworkAvailable()) return new HttpResponse(NetworkUtil.ERROR_NETWORK_UNAVAILABLE); try { return NetworkUtil.get(QMS_GEOSERVICE_LIST_URL, null, null, false); } catch (IOException e) { e.printStackTrace(); } return new HttpResponse(NetworkUtil.ERROR_DOWNLOAD_DATA); }
Example #16
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; }
Example #17
Source File: SettingsFragment.java From android_gisapp with GNU General Public License v3.0 | 5 votes |
@Override protected Boolean doInBackground(Void... voids) { try { String url = String.format("%s/%s/registered", URL, getUid(mPreference.getContext())); HttpResponse response = NetworkUtil.get(url, null, null, false); String body = response.getResponseBody(); JSONObject json = new JSONObject(body == null ? "" : body); return json.optBoolean("registered"); } catch (IOException | JSONException e) { return null; } }
Example #18
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
protected HttpResponse changeFeatureOnServer(long featureId, String payload) throws IOException { AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName); // change on server String url = NGWUtil.getFeatureUrl(accountData.url, mRemoteId, featureId); return NetworkUtil.put(url, payload, accountData.login, accountData.password, false); }
Example #19
Source File: CreateFromQMSLayerDialog.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected HttpResponse doInBackground(Integer... params) { if (!mNet.isNetworkAvailable()) return new HttpResponse(NetworkUtil.ERROR_NETWORK_UNAVAILABLE); try { mLayerId = params[0]; return NetworkUtil.get(QMS_GEOSERVICE_URL + mLayerId + QMS_DETAIL_APPENDIX, null, null, false); } catch (IOException e) { e.printStackTrace(); } return new HttpResponse(NetworkUtil.ERROR_DOWNLOAD_DATA); }
Example #20
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
protected HttpResponse sendAttachOnServer(long featureId, AttachItem attach) throws IOException { // fill attach info String fileName = attach.getDisplayName(); File filePath = new File(mPath, featureId + File.separator + attach.getAttachId()); String fileMime = attach.getMimetype(); // get account data AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName); // upload file String url = NGWUtil.getFileUploadUrl(accountData.url); return NetworkUtil.postFile(url, fileName, filePath, fileMime, accountData.login, accountData.password, false); }
Example #21
Source File: ApkDownloader.java From android_gisapp with GNU General Public License v3.0 | 4 votes |
public static void check(final Activity activity, final boolean showToast) { final String token = PreferenceManager.getDefaultSharedPreferences(activity).getString(NGIDUtils.PREF_ACCESS_TOKEN, ""); if (showToast && TextUtils.isEmpty(token)) { Toast.makeText(activity, R.string.error_401, Toast.LENGTH_SHORT).show(); activity.finish(); return; } NGIDUtils.get(activity, AppSettingsConstants.APK_VERSION_UPDATE, new NGIDUtils.OnFinish() { @Override public void onFinish(HttpResponse response) { if (response.isOk()) { try { JSONObject json = new JSONObject(response.getResponseBody()); if (json.getInt("versionCode") <= BuildConfig.VERSION_CODE) { if (showToast) { Toast.makeText(activity, R.string.update_no, Toast.LENGTH_SHORT).show(); activity.finish(); } return; } // there is new version, create download dialog final String url = json.getString("path"); DialogInterface.OnClickListener dcl = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int button) { if (button == DialogInterface.BUTTON_POSITIVE) new ApkDownloader(activity, showToast).execute(url, token); else if (showToast) activity.finish(); } }; AlertDialog.Builder adb = new AlertDialog.Builder(activity); String update = String.format(activity.getString(R.string.update_new), json.getString("versionName")); adb.setMessage(update).setTitle(R.string.update_title) .setPositiveButton(R.string.yes, dcl).setNegativeButton(R.string.no, dcl).show(); } catch (JSONException e) { e.printStackTrace(); } } } }); }
Example #22
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
protected HttpResponse deleteFeatureOnServer(long featureId) throws IOException { AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName); return NetworkUtil.delete(NGWUtil.getFeatureUrl(accountData.url, mRemoteId, featureId), accountData.login, accountData.password, false); }
Example #23
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
protected HttpResponse addFeatureOnServer(String payload) throws IOException { AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName); return NetworkUtil.post(NGWUtil.getFeaturesUrl(accountData.url, mRemoteId), payload, accountData.login, accountData.password, false); }
Example #24
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
protected HttpResponse deleteAttachOnServer(long featureId, long attachId) throws IOException { AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName); return NetworkUtil.delete(NGWUtil.getFeatureAttachmentUrl(accountData.url, mRemoteId, featureId) + attachId, accountData.login, accountData.password, false); }
Example #25
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
protected HttpResponse changeAttachOnServer(long featureId, long attachId, String putData) throws IOException { AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName); String url = NGWUtil.getFeatureAttachmentUrl(accountData.url, mRemoteId, featureId) + attachId; return NetworkUtil.put(url, putData, accountData.login, accountData.password, false); }
Example #26
Source File: NGIDUtils.java From android_maplibui with GNU Lesser General Public License v3.0 | votes |
void onFinish(HttpResponse response);