Skip to content

Commit 94f1417

Browse files
committed
Update android copy of client project
1 parent 44a87fe commit 94f1417

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/AndroidClient/android/src/main/java/net/servicestack/client/ApiMember.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,9 @@
5656
/// Gets or sets route to which applies attribute, matches using StartsWith. By default applies to all routes.
5757
/// </summary>
5858
public String Route() default "";
59+
60+
/// <summary>
61+
/// Whether to exclude this property from being included in the ModelSchema
62+
/// </summary>
63+
public boolean ExcludeInSchema() default false;
5964
}

src/AndroidClient/android/src/main/java/net/servicestack/client/JsonServiceClient.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import java.io.UnsupportedEncodingException;
1717
import java.lang.reflect.Field;
1818
import java.lang.reflect.Type;
19+
import java.net.CookieHandler;
20+
import java.net.CookieManager;
1921
import java.net.HttpURLConnection;
2022
import java.net.URL;
2123
import java.net.URLEncoder;
@@ -46,6 +48,11 @@ public class JsonServiceClient implements ServiceClient {
4648
public JsonServiceClient(String baseUrl) {
4749
this.baseUrl = baseUrl.endsWith("/") ? baseUrl : baseUrl + "/";
4850
this.replyUrl = this.baseUrl + "json/reply/";
51+
52+
//Automatically populate response cookies
53+
if (CookieHandler.getDefault() == null){
54+
CookieHandler.setDefault(new CookieManager());
55+
}
4956
}
5057

5158
public void setTimeout(int timeoutMs) {
@@ -172,11 +179,13 @@ public HttpURLConnection createRequest(String requestUrl, String httpMethod, byt
172179
private static void addBasicAuth(HttpURLConnection req, String userName, String password) {
173180
req.setRequestProperty(HttpHeaders.Authorization,
174181
"Basic " + Utils.toBase64String(userName + ":" + password));
182+
req.setRequestProperty("X-Auth", "Basic"); // HttpURLConnection doesn't allow re-reading Authorization Header
175183
}
176184

177185
private static boolean shouldAuthenticate(HttpURLConnection req, String userName, String password){
178186
try {
179187
return req.getResponseCode() == 401
188+
&& req.getRequestProperty("X-Auth") == null //only auth if auth never attempted
180189
&& userName != null
181190
&& password != null;
182191
} catch (IOException e) {
@@ -364,8 +373,8 @@ public <TResponse> TResponse send(String requestUrl, String httpMethod, byte[] r
364373
else {
365374
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
366375
TResponse response = resClass != null
367-
? (TResponse) getGson().fromJson(reader, resClass)
368-
: (TResponse) getGson().fromJson(reader, resType);
376+
? (TResponse) getGson().fromJson(reader, resClass)
377+
: (TResponse) getGson().fromJson(reader, resType);
369378

370379
reader.close();
371380
return response;

0 commit comments

Comments
 (0)