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

--
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 google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment