Skip to content

Commit 8d2ed57

Browse files
author
Vahur Roosimaa
committed
Conflicts: src/com/loopj/android/http/JsonHttpResponseHandler.java
2 parents a80e408 + 32ae848 commit 8d2ed57

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

build.xml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
<exec executable="git" outputproperty="package.versionname">
1919
<arg value="describe"/>
20-
<arg value='--match=${package.name}-*'/>
2120
<arg value="--tags"/>
2221
<arg value="--dirty"/>
2322
<arg value="--always"/>
@@ -26,7 +25,19 @@
2625
</target>
2726

2827
<!-- Standard jar stuff -->
29-
<property name="lib.dir" value="${sdk.dir}/platforms/${target}" />
28+
<property environment="env"/>
29+
<condition property="android.base" value="${sdk.dir}" else="${env.ANDROID_HOME}">
30+
<isset property="sdk.dir" />
31+
</condition>
32+
<fail message="Please set either the sdk.dir property or the ANDROID_HOME environment variable to point to your Android SDK installation.">
33+
<condition>
34+
<not>
35+
<available file="${android.base}" type="dir"/>
36+
</not>
37+
</condition>
38+
</fail>
39+
40+
<property name="lib.dir" value="${android.base}/platforms/${target}" />
3041
<property name="build.dir" value="./build"/>
3142
<property name="classes.dir" value="${build.dir}/classes"/>
3243
<buildnumber file="build.num" />
@@ -43,7 +54,7 @@
4354
sourcepath="gen:src"
4455
destdir="doc"
4556
packagenames="${package.packagename}"
46-
linkoffline="http://d.android.com/reference ${sdk.dir}/docs/reference"
57+
linkoffline="http://d.android.com/reference ${android.base}/docs/reference"
4758
additionalparam="-author -version"
4859
/>
4960
</target>

examples/TwitterRestClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static void get(String url, RequestParams params, AsyncHttpResponseHandle
1212
}
1313

1414
public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
15-
client.get(getAbsoluteUrl(url), params, responseHandler);
15+
client.post(getAbsoluteUrl(url), params, responseHandler);
1616
}
1717

1818
private static String getAbsoluteUrl(String relativeUrl) {

src/com/loopj/android/http/JsonHttpResponseHandler.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,21 @@ protected void handleSuccessJsonMessage(int statusCode, Object jsonResponse) {
125125
} else if(jsonResponse instanceof JSONArray) {
126126
onSuccess(statusCode, (JSONArray)jsonResponse);
127127
} else {
128-
onFailure(new JSONException("Unexpected type " + jsonResponse.getClass().getName()));
128+
onFailure(new JSONException("Unexpected type " + jsonResponse.getClass().getName()), (JSONObject)null);
129129
}
130130
}
131131

132132
protected Object parseResponse(String responseBody) throws JSONException {
133133
Object result = null;
134134
//trim the string to prevent start with blank, and test if the string is valid JSON, because the parser don't do this :(. If Json is not valid this will return null
135-
responseBody = responseBody.trim();
136-
if(responseBody.startsWith("{") || responseBody.startsWith("[")) {
137-
result = new JSONTokener(responseBody).nextValue();
138-
}
139-
return result;
135+
responseBody = responseBody.trim();
136+
if(responseBody.startsWith("{") || responseBody.startsWith("[")) {
137+
result = new JSONTokener(responseBody).nextValue();
138+
}
139+
if (result == null) {
140+
result = responseBody;
141+
}
142+
return result;
140143
}
141144

142145
@Override

src/com/loopj/android/http/RetryHandler.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public RetryHandler(int maxRetries) {
6565
}
6666

6767
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
68-
boolean retry;
68+
boolean retry = true;
6969

7070
Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
7171
boolean sent = (b != null && b.booleanValue());
@@ -82,16 +82,13 @@ public boolean retryRequest(IOException exception, int executionCount, HttpConte
8282
} else if (!sent) {
8383
// for most other errors, retry only if request hasn't been fully sent yet
8484
retry = true;
85-
} else {
85+
}
86+
87+
if(retry) {
8688
// resend all idempotent requests
87-
HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
89+
HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute( ExecutionContext.HTTP_REQUEST );
8890
String requestType = currentReq.getMethod();
89-
if(!requestType.equals("POST")) {
90-
retry = true;
91-
} else {
92-
// otherwise do not retry
93-
retry = false;
94-
}
91+
retry = !requestType.equals("POST");
9592
}
9693

9794
if(retry) {

0 commit comments

Comments
 (0)