calling rest service

70 views
Skip to first unread message

Dante Valencia

unread,
Sep 27, 2016, 2:10:34 AM9/27/16
to GWT Users
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;

Frank

unread,
Sep 27, 2016, 2:59:15 AM9/27/16
to GWT Users
Are you trying to do this code client side ?
That will not work since GWT has no support for BufferedReader, InputStreamReader...

In short. GWT only supports java.lang, and java.util (albeit not completely).

Look into RequestBuilder, or RestyGwt (not sure about the exact name as I don't use this library, but I know it is quite popular).
Reply all
Reply to author
Forward
0 new messages