Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Source Code is available for type : GWT Compilation Error

I am trying to make get requests by a servlet in my GWT application. On compiling the code I am getting these errors.

[ERROR] Line 16: No source code is available for type org.apache.http.client.ClientProtocolException; did you forget to inherit a required module?
[ERROR] Line 16: No source code is available for type org.apache.http.ParseException; did you forget to inherit a required module?
[ERROR] Line 16: No source code is available for type org.json.simple.parser.ParseException; did you forget to inherit a required module?

What should I do to remove these errors? Are these classes are not supported by GWT?

Following is the code I am using

public String getJSON() throws ClientProtocolException, IOException, ParseException{
    HttpClient httpclient = new DefaultHttpClient(); 
    JSONParser parser = new JSONParser();
    String url = "some - url - can't disclose";
    HttpResponse response = httpclient.execute(new HttpGet(url));
    JSONObject json_data = (JSONObject)parser.parse(EntityUtils.toString(response.getEntity()));
    JSONArray results = (JSONArray)json_data.get("result");
}

This code is working fine If I use this on a usual java project/ console application.

like image 754
Saurabh Saxena Avatar asked Mar 03 '12 19:03

Saurabh Saxena


1 Answers

Java code running in GWT is translated to Javascript, so some classes that work on a JVM won't work with GWT. The HttpClient and related classes are written to work on a JVM with full support for opening sockets, something that isn't allowed in a web browser, so these classes cannot be used.

To open a connection to the server you are using (subject to the browser Same Origin Policy), consider the RequestBuilder class, which allows you to provide a url and an HTTP method, and optionally headers, parameters, data, etc. This class is an abstraction over the XmlHttpRequest object in JavaScript, commonly used for AJAX requests in plain JS.

like image 97
Colin Alworth Avatar answered Sep 22 '22 13:09

Colin Alworth