Monday, September 26, 2016

calling rest service

Hi friends, I need help please,
I´m trying  to call my rest service but I have problems when I try to use bufferedReader,  InputStreamReader or TypeI dont know what to do.
Please if you help me.

I´m trying this

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);

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

return usuario;

Gson gson = new Gson();
Type listType = new TypeToken<List<Comunidades>>() {}.getType();
List<Comunidades> comunidades = gson.fromJson(resJson, listType);
return comunidades;

You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment