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:
parent
f7b4f08710
commit
a2b16f350b
3 changed files with 11 additions and 29 deletions
|
@ -125,13 +125,7 @@ public class SynchroniserService extends Service implements IBookCollection.List
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleStream(InputStream stream, int length) throws IOException, ZLNetworkException {
|
public void handleStream(InputStream stream, int length) throws IOException, ZLNetworkException {
|
||||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
|
processResponse(JSONValue.parse(new InputStreamReader(stream)));
|
||||||
final StringBuilder buffer = new StringBuilder();
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
buffer.append(line);
|
|
||||||
}
|
|
||||||
processResponse(JSONValue.parse(buffer.toString()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void processResponse(Object response);
|
protected abstract void processResponse(Object response);
|
||||||
|
@ -144,13 +138,7 @@ public class SynchroniserService extends Service implements IBookCollection.List
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleStream(InputStream stream, int length) throws IOException, ZLNetworkException {
|
public void handleStream(InputStream stream, int length) throws IOException, ZLNetworkException {
|
||||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
|
final Object response = JSONValue.parse(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());
|
|
||||||
String id = null;
|
String id = null;
|
||||||
List<String> hashes = null;
|
List<String> hashes = null;
|
||||||
String error = null;
|
String error = null;
|
||||||
|
|
|
@ -19,27 +19,21 @@
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.core.network;
|
package org.geometerplus.zlibrary.core.network;
|
||||||
|
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.http.HttpEntity;
|
||||||
|
import org.json.simple.JSONValue;
|
||||||
|
|
||||||
class BearerAuthenticationException extends RuntimeException {
|
class BearerAuthenticationException extends RuntimeException {
|
||||||
public final Map<String,String> Params = new HashMap<String,String>();
|
public final Map<String,String> Params = new HashMap<String,String>();
|
||||||
|
|
||||||
BearerAuthenticationException(String challenge) {
|
BearerAuthenticationException(HttpEntity entity) {
|
||||||
super("Authentication failed");
|
super("Authentication failed");
|
||||||
if (challenge != null && "bearer".equalsIgnoreCase(challenge.substring(0, 6))) {
|
try {
|
||||||
for (String param : challenge.substring(6).split(",")) {
|
Params.putAll((Map)JSONValue.parse(new InputStreamReader(entity.getContent())));
|
||||||
final int index = param.indexOf("=");
|
} catch (Exception e) {
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -315,7 +315,7 @@ public class ZLNetworkManager {
|
||||||
} catch (AuthenticationException e) {
|
} catch (AuthenticationException e) {
|
||||||
final Header bearerHeader = challenges.get("bearer");
|
final Header bearerHeader = challenges.get("bearer");
|
||||||
if (bearerHeader != null) {
|
if (bearerHeader != null) {
|
||||||
throw new BearerAuthenticationException(bearerHeader.getValue());
|
throw new BearerAuthenticationException(response.getEntity());
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue