1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 10:49:24 +02:00

auth info in body/json instead of WWW-Authenticate field

This commit is contained in:
Nikolay Pultsin 2014-07-20 06:48:41 +01:00
parent f7b4f08710
commit a2b16f350b
3 changed files with 11 additions and 29 deletions

View file

@ -125,13 +125,7 @@ public class SynchroniserService extends Service implements IBookCollection.List
@Override
public void handleStream(InputStream stream, int length) throws IOException, ZLNetworkException {
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
final StringBuilder buffer = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
processResponse(JSONValue.parse(buffer.toString()));
processResponse(JSONValue.parse(new InputStreamReader(stream)));
}
protected abstract void processResponse(Object response);
@ -144,13 +138,7 @@ public class SynchroniserService extends Service implements IBookCollection.List
@Override
public void handleStream(InputStream stream, int length) throws IOException, ZLNetworkException {
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
final StringBuilder buffer = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
final Object response = JSONValue.parse(buffer.toString());
final Object response = JSONValue.parse(new InputStreamReader(stream));
String id = null;
List<String> hashes = null;
String error = null;

View file

@ -19,27 +19,21 @@
package org.geometerplus.zlibrary.core.network;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.json.simple.JSONValue;
class BearerAuthenticationException extends RuntimeException {
public final Map<String,String> Params = new HashMap<String,String>();
BearerAuthenticationException(String challenge) {
BearerAuthenticationException(HttpEntity entity) {
super("Authentication failed");
if (challenge != null && "bearer".equalsIgnoreCase(challenge.substring(0, 6))) {
for (String param : challenge.substring(6).split(",")) {
final int index = param.indexOf("=");
if (index != -1) {
final String key = param.substring(0, index).trim();
String value = param.substring(index + 1).trim();
final int len = value.length();
if (len > 1 && value.charAt(0) == '"' && value.charAt(len - 1) == '"') {
value = value.substring(1, len - 1);
}
Params.put(key, value);
}
}
try {
Params.putAll((Map)JSONValue.parse(new InputStreamReader(entity.getContent())));
} catch (Exception e) {
}
}
}

View file

@ -315,7 +315,7 @@ public class ZLNetworkManager {
} catch (AuthenticationException e) {
final Header bearerHeader = challenges.get("bearer");
if (bearerHeader != null) {
throw new BearerAuthenticationException(bearerHeader.getValue());
throw new BearerAuthenticationException(response.getEntity());
}
throw e;
}