use of org.apache.http.entity.ByteArrayEntity in project android-volley by mcxiaoke.
the class HttpClientStack method setEntityIfNonEmptyBody.
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest, Request<?> request) throws AuthFailureError {
byte[] body = request.getBody();
if (body != null) {
HttpEntity entity = new ByteArrayEntity(body);
httpRequest.setEntity(entity);
}
}
use of org.apache.http.entity.ByteArrayEntity in project JamsMusicPlayer by psaravan.
the class GMusicClientCalls method getPlaylistEntriesMobileClient.
/******************************************************************************************
* Retrieves a JSONAray with all songs in <i><b>every</b></i> playlist. The JSONArray
* contains the fields of the songs such as "id", "clientId", "trackId", etc. (for a list
* of all fields, see MobileClientPlaylistEntriesSchema.java).
*
* @deprecated This method is fully functional. However, there are issues with retrieving
* the correct playlist entryIds. Specifically, the entryIds do not seem to work with
* reordering playlists via the MobileClient mutations protocol.
*
* @return A JSONArray object that contains all songs and their fields within every playlist.
* @param context The context to use while retrieving songs from the playlist.
******************************************************************************************/
public static final JSONArray getPlaylistEntriesMobileClient(Context context) throws JSONException, IllegalArgumentException {
JSONArray playlistEntriesJSONArray = new JSONArray();
JSONObject jsonRequestParams = new JSONObject();
jsonRequestParams.put("max-results", 10000);
jsonRequestParams.put("start-token", "0");
mHttpClient.setUserAgent(mMobileClientUserAgent);
String result = mHttpClient.post(context, "https://www.googleapis.com/sj/v1.1/plentryfeed?alt=json&hl=en_US&tier=basic", new ByteArrayEntity(jsonRequestParams.toString().getBytes()), "application/json");
JSONObject resultJSONObject = new JSONObject(result);
JSONObject dataJSONObject = new JSONObject();
if (resultJSONObject != null) {
dataJSONObject = resultJSONObject.optJSONObject("data");
}
if (dataJSONObject != null) {
playlistEntriesJSONArray = dataJSONObject.getJSONArray("items");
}
return playlistEntriesJSONArray;
}
use of org.apache.http.entity.ByteArrayEntity in project JamsMusicPlayer by psaravan.
the class GMusicClientCalls method createPlaylist.
/****************************************************************************
* Creates a new, user generated playlist. This method only creates the
* playlist; it does not add songs to the playlist.
*
* @param context The context to use while creating the new playlist.
* @param playlistName The name of the new playlist.
* @return Returns the playlistId of the newly created playlist.
* @throws JSONException
* @throws IllegalArgumentException
****************************************************************************/
public static final String createPlaylist(Context context, String playlistName) throws JSONException, IllegalArgumentException {
JSONObject jsonParam = new JSONObject();
JSONArray mutationsArray = new JSONArray();
JSONObject createObject = new JSONObject();
createObject.put("lastModifiedTimestamp", "0");
createObject.put("name", playlistName);
createObject.put("creationTimestamp", "-1");
createObject.put("type", "USER_GENERATED");
createObject.put("deleted", false);
mutationsArray.put(new JSONObject().put("create", createObject));
jsonParam.put("mutations", mutationsArray);
mHttpClient.setUserAgent(mMobileClientUserAgent);
String result = mHttpClient.post(context, "https://www.googleapis.com/sj/v1.1/playlistbatch?alt=json&hl=en_US", new ByteArrayEntity(jsonParam.toString().getBytes()), "application/json");
mHttpClient.setUserAgent(mWebClientUserAgent);
return new JSONObject(result).optJSONArray("mutate_response").getJSONObject(0).optString("id");
}
use of org.apache.http.entity.ByteArrayEntity in project JamsMusicPlayer by psaravan.
the class GMusicClientCalls method getUserPlaylistsMobileClient.
/*******************************************************************************************
* Sends a POST request to Google's servers and retrieves a JSONArray with all user
* playlists. The JSONArray contains the fields of the playlist such as "id", "name",
* "type", etc. (for a list of all response fields, see MobileClientPlaylistsSchema.java).
*
* @return A JSONArray object that contains all user playlists and their fields.
* @param context The context to use while retrieving user playlists.
*******************************************************************************************/
public static final JSONArray getUserPlaylistsMobileClient(Context context) throws JSONException, IllegalArgumentException {
JSONObject jsonRequestParams = new JSONObject();
JSONArray playlistsJSONArray = new JSONArray();
jsonRequestParams.put("max-results", 250);
jsonRequestParams.put("start-token", "0");
mHttpClient.setUserAgent(mMobileClientUserAgent);
String result = mHttpClient.post(context, "https://www.googleapis.com/sj/v1.1/playlistfeed?alt=json&hl=en_US&tier=basic", new ByteArrayEntity(jsonRequestParams.toString().getBytes()), "application/json");
JSONObject resultJSONObject = new JSONObject(result);
JSONObject dataJSONObject = new JSONObject();
if (resultJSONObject != null) {
dataJSONObject = resultJSONObject.optJSONObject("data");
}
if (dataJSONObject != null) {
playlistsJSONArray = dataJSONObject.getJSONArray("items");
}
return playlistsJSONArray;
}
use of org.apache.http.entity.ByteArrayEntity in project robovm by robovm.
the class HttpService method handleException.
protected void handleException(final HttpException ex, final HttpResponse response) {
if (ex instanceof MethodNotSupportedException) {
response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
} else if (ex instanceof UnsupportedHttpVersionException) {
response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
} else if (ex instanceof ProtocolException) {
response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
} else {
response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
byte[] msg = EncodingUtils.getAsciiBytes(ex.getMessage());
ByteArrayEntity entity = new ByteArrayEntity(msg);
entity.setContentType("text/plain; charset=US-ASCII");
response.setEntity(entity);
}
Aggregations