My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package org.synthful.gwt.http.client;


import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.Response;
import com.google.gwt.json.client.JSONException;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;

abstract public class JsonHttpResponseHandler
extends HttpResponseHandler
{
public JsonHttpResponseHandler(String url)
{
super(url);
}

public void onResponse(
Request request, Response response)
{
try
{
// parse the response text into JSON
JSONValue jsonValue = JSONParser.parse(response.getText());
JSONObject jsonObj = jsonValue.isObject();

if (jsonObj != null)
{
JsonData = jsonObj;
this.Status = HttpResponseStatus.Normal;
this.onJsonResponse(this);
}
else
{
this.Status = HttpResponseStatus.EmptyData;
throw new JSONException();
}
}
catch (JSONException e)
{
this.Status = HttpResponseStatus.DataParseFailure;
}
}

public JSONObject JsonData;
abstract protected void onJsonResponse(
JsonHttpResponseHandler jsonHttpResponseHandler);
}

Change log

r82 by BlessedGeek on Jun 30, 2010   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1421 bytes, 49 lines
Powered by Google Project Hosting