public Usuario login(Usuario usuario) throws UnsupportedEncodingException, IOException {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(URL_DSCPACE + "login");
Gson gson = new Gson();
String usuarioJson = gson.toJson(usuario);
StringEntity input = new StringEntity(usuarioJson);
input.setContentType(JSON_FORMAT);
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);
if (response.getStatusLine().getStatusCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
}
BufferedReader br = new BufferedReader(
new InputStreamReader((response.getEntity().getContent())));
String output, token = "";
while ((output = br.readLine()) != null) {
token += output;
}
usuario.setToken(token);
httpClient.getConnectionManager().shutdown();
return usuario;
}
Gson gson = new Gson();
Type listType = new TypeToken<List<Comunidades>>() {}.getType();
List<Comunidades> comunidades = gson.fromJson(resJson, listType);
return comunidades;