Java Code Examples for com.nextgis.maplib.util.HttpResponse#getResponseBody()

The following examples show how to use com.nextgis.maplib.util.HttpResponse#getResponseBody() . 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 vote down vote up
@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 vote down vote up
@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: NGWLookupTable.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
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: NGWCreateNewResourceTask.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 5
Source File: Connection.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 6
Source File: Resource.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 7
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
@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;
    }
}