本文整理汇总了Java中org.mozilla.gecko.sync.ExtendedJSONObject类的典型用法代码示例。如果您正苦于以下问题:Java ExtendedJSONObject类的具体用法?Java ExtendedJSONObject怎么用?Java ExtendedJSONObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExtendedJSONObject类属于org.mozilla.gecko.sync包,在下文中一共展示了ExtendedJSONObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateResponse
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入依赖的package包/类
/**
* Intepret a response from the auth server.
* <p>
* Throw an appropriate exception on errors; otherwise, return the response's
* status code.
*
* @return response's HTTP status code.
* @throws FxAccountClientException
*/
public static int validateResponse(HttpResponse response) throws FxAccountClientRemoteException {
final int status = response.getStatusLine().getStatusCode();
if (status == 200) {
return status;
}
int code;
int errno;
String error;
String message;
String info;
ExtendedJSONObject body;
try {
body = new SyncStorageResponse(response).jsonObjectBody();
body.throwIfFieldsMissingOrMisTyped(requiredErrorStringFields, String.class);
body.throwIfFieldsMissingOrMisTyped(requiredErrorLongFields, Long.class);
code = body.getLong(JSON_KEY_CODE).intValue();
errno = body.getLong(JSON_KEY_ERRNO).intValue();
error = body.getString(JSON_KEY_ERROR);
message = body.getString(JSON_KEY_MESSAGE);
info = body.getString(JSON_KEY_INFO);
} catch (Exception e) {
throw new FxAccountClientMalformedResponseException(response);
}
throw new FxAccountClientRemoteException(response, code, errno, error, message, info, body);
}
示例2: unbundleBody
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入依赖的package包/类
protected void unbundleBody(ExtendedJSONObject body, byte[] requestKey, byte[] ctxInfo, byte[]... rest) throws Exception {
int length = 0;
for (byte[] array : rest) {
length += array.length;
}
if (body == null) {
throw new FxAccountClientException("body must be non-null");
}
String bundle = body.getString("bundle");
if (bundle == null) {
throw new FxAccountClientException("bundle must be a non-null string");
}
byte[] bundleBytes = Utils.hex2Byte(bundle);
final byte[] respHMACKey = new byte[32];
final byte[] respXORKey = new byte[length];
HKDF.deriveMany(requestKey, new byte[0], ctxInfo, respHMACKey, respXORKey);
unbundleBytes(bundleBytes, respHMACKey, respXORKey, rest);
}
示例3: parseCertificate
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入依赖的package包/类
/**
* For debugging only!
*
* @param input
* certificate to dump.
* @return non-null object with keys header, payload, signature if the
* certificate is well-formed.
*/
public static ExtendedJSONObject parseCertificate(String input) {
try {
String[] parts = input.split("\\.");
if (parts.length != 3) {
return null;
}
String cHeader = new String(Base64.decodeBase64(parts[0]),
org.mozilla.gecko.util.StringUtils.UTF_8);
String cPayload = new String(Base64.decodeBase64(parts[1]),
org.mozilla.gecko.util.StringUtils.UTF_8);
String cSignature = Utils.byte2Hex(Base64.decodeBase64(parts[2]));
ExtendedJSONObject o = new ExtendedJSONObject();
o.put("header", new ExtendedJSONObject(cHeader));
o.put("payload", new ExtendedJSONObject(cPayload));
o.put("signature", cSignature);
return o;
} catch (Exception e) {
return null;
}
}
示例4: dumpCertificate
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入依赖的package包/类
/**
* For debugging only!
*
* @param input certificate to dump.
* @return true if the certificate is well-formed.
*/
public static boolean dumpCertificate(String input) {
ExtendedJSONObject c = parseCertificate(input);
try {
if (c == null) {
System.out.println("Malformed certificate -- got exception trying to dump contents.");
return false;
}
System.out.println("certificate header: " + c.getObject("header").toJSONString());
System.out.println("certificate payload: " + c.getObject("payload").toJSONString());
System.out.println("certificate signature: " + c.getString("signature"));
return true;
} catch (Exception e) {
System.out.println("Malformed certificate -- got exception trying to dump contents.");
return false;
}
}
示例5: dumpAssertion
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入依赖的package包/类
/**
* For debugging only!
*
* @param input assertion to dump.
* @return true if the assertion is well-formed.
*/
public static boolean dumpAssertion(String input) {
ExtendedJSONObject a = parseAssertion(input);
try {
if (a == null) {
System.out.println("Malformed assertion -- got exception trying to dump contents.");
return false;
}
dumpCertificate(a.getString("certificate"));
System.out.println("assertion header: " + a.getObject("header").toJSONString());
System.out.println("assertion payload: " + a.getObject("payload").toJSONString());
System.out.println("assertion signature: " + a.getString("signature"));
return true;
} catch (Exception e) {
System.out.println("Malformed assertion -- got exception trying to dump contents.");
return false;
}
}
示例6: execute
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入依赖的package包/类
@Override
public void execute(final ExecuteDelegate delegate) {
delegate.getClient().sign(sessionToken, keyPair.getPublic().toJSONObject(), delegate.getCertificateDurationInMilliseconds(),
new BaseRequestDelegate<String>(this, delegate) {
@Override
public void handleSuccess(String certificate) {
if (FxAccountUtils.LOG_PERSONAL_INFORMATION) {
try {
FxAccountUtils.pii(LOG_TAG, "Fetched certificate: " + certificate);
ExtendedJSONObject c = JSONWebTokenUtils.parseCertificate(certificate);
if (c != null) {
FxAccountUtils.pii(LOG_TAG, "Header : " + c.getObject("header"));
FxAccountUtils.pii(LOG_TAG, "Payload : " + c.getObject("payload"));
FxAccountUtils.pii(LOG_TAG, "Signature: " + c.getString("signature"));
} else {
FxAccountUtils.pii(LOG_TAG, "Could not parse certificate!");
}
} catch (Exception e) {
FxAccountUtils.pii(LOG_TAG, "Could not parse certificate!");
}
}
delegate.handleTransition(new LogMessage("sign succeeded"), withCertificate(certificate));
}
});
}
示例7: fromJSONObject
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入依赖的package包/类
public static State fromJSONObject(StateLabel stateLabel, ExtendedJSONObject o) throws InvalidKeySpecException, NoSuchAlgorithmException, NonObjectJSONException {
Long version = o.getLong("version");
if (version == null) {
throw new IllegalStateException("version must not be null");
}
final int v = version.intValue();
if (v == 3) {
// The most common case is the most recent version.
return fromJSONObjectV3(stateLabel, o);
}
if (v == 2) {
return fromJSONObjectV2(stateLabel, o);
}
if (v == 1) {
final State state = fromJSONObjectV1(stateLabel, o);
return migrateV1toV2(stateLabel, state);
}
throw new IllegalStateException("version must be in {1, 2}");
}
示例8: fromJSONObjectV2
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入依赖的package包/类
/**
* Exactly the same as {@link fromJSONObjectV1}, except that all key pairs are DSA key pairs.
*/
protected static State fromJSONObjectV2(StateLabel stateLabel, ExtendedJSONObject o) throws InvalidKeySpecException, NoSuchAlgorithmException, NonObjectJSONException {
switch (stateLabel) {
case Cohabiting:
return new Cohabiting(
o.getString("email"),
o.getString("uid"),
Utils.hex2Byte(o.getString("sessionToken")),
Utils.hex2Byte(o.getString("kA")),
Utils.hex2Byte(o.getString("kB")),
keyPairFromJSONObjectV2(o.getObject("keyPair")));
case Married:
return new Married(
o.getString("email"),
o.getString("uid"),
Utils.hex2Byte(o.getString("sessionToken")),
Utils.hex2Byte(o.getString("kA")),
Utils.hex2Byte(o.getString("kB")),
keyPairFromJSONObjectV2(o.getObject("keyPair")),
o.getString("certificate"));
default:
return fromJSONObjectV1(stateLabel, o);
}
}
示例9: initFromEnvelope
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入依赖的package包/类
public void initFromEnvelope(CryptoRecord envelope) {
ExtendedJSONObject p = envelope.payload;
this.guid = envelope.guid;
checkGUIDs(p);
this.collection = envelope.collection;
this.lastModified = envelope.lastModified;
final Object del = p.get("deleted");
if (del instanceof Boolean) {
this.deleted = (Boolean) del;
} else {
this.initFromPayload(p);
}
}
示例10: jsonObjectBody
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入依赖的package包/类
/**
* Return the body as a <b>non-null</b> <code>ExtendedJSONObject</code>.
*
* @return A non-null <code>ExtendedJSONObject</code>.
*
* @throws IllegalStateException
* @throws IOException
* @throws NonObjectJSONException
*/
public ExtendedJSONObject jsonObjectBody() throws IllegalStateException, IOException, NonObjectJSONException {
if (body != null) {
// Do it from the cached String.
return new ExtendedJSONObject(body);
}
HttpEntity entity = this.response.getEntity();
if (entity == null) {
throw new IOException("no entity");
}
InputStream content = entity.getContent();
try {
Reader in = new BufferedReader(new InputStreamReader(content, "UTF-8"));
return new ExtendedJSONObject(in);
} finally {
content.close();
}
}
示例11: patch
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入依赖的package包/类
public void patch(final ClientReadingListRecord up, final ReadingListRecordUploadDelegate uploadDelegate) {
final String guid = up.getGUID();
if (guid == null) {
uploadDelegate.onFailure(up, new IllegalArgumentException("Supplied record must have a GUID."));
return;
}
final BaseResource r = getRelativeArticleResource(guid);
r.delegate = new DelegatingUploadResourceDelegate(r, auth, ReadingListRecordResponse.FACTORY, up,
uploadDelegate);
final ExtendedJSONObject body = up.toJSON();
if (ReadingListConstants.DEBUG) {
Logger.info(LOG_TAG, "Patching record " + guid + ": " + body.toJSONString());
}
r.patch(body);
}
示例12: unpickleV3
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入依赖的package包/类
private void unpickleV3(final ExtendedJSONObject json)
throws NonObjectJSONException, NoSuchAlgorithmException, InvalidKeySpecException {
// We'll overwrite the extracted sync automatically map.
unpickleV1(json);
// Extract the map of authorities to sync automatically.
authoritiesToSyncAutomaticallyMap.clear();
final ExtendedJSONObject o = json.getObject(KEY_AUTHORITIES_TO_SYNC_AUTOMATICALLY_MAP);
if (o == null) {
return;
}
for (String key : o.keySet()) {
final Boolean enabled = o.getBoolean(key);
if (enabled != null) {
authoritiesToSyncAutomaticallyMap.put(key, enabled);
}
}
}
示例13: unpickleV1
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入依赖的package包/类
private void unpickleV1(final ExtendedJSONObject json)
throws NonObjectJSONException, NoSuchAlgorithmException, InvalidKeySpecException {
this.accountVersion = json.getIntegerSafely(KEY_ACCOUNT_VERSION);
this.email = json.getString(KEY_EMAIL);
this.profile = json.getString(KEY_PROFILE);
this.authServerURI = json.getString(KEY_IDP_SERVER_URI);
this.tokenServerURI = json.getString(KEY_TOKEN_SERVER_URI);
this.profileServerURI = json.getString(KEY_PROFILE_SERVER_URI);
// Fallback to default value when profile server URI was not pickled.
if (this.profileServerURI == null) {
this.profileServerURI = FxAccountConstants.DEFAULT_AUTH_SERVER_ENDPOINT.equals(this.authServerURI)
? FxAccountConstants.DEFAULT_PROFILE_SERVER_ENDPOINT
: FxAccountConstants.STAGE_PROFILE_SERVER_ENDPOINT;
}
// We get the default value for everything except syncing browser data.
this.authoritiesToSyncAutomaticallyMap.put(BrowserContract.AUTHORITY, json.getBoolean(KEY_IS_SYNCING_ENABLED));
this.bundle = json.getObject(KEY_BUNDLE);
if (bundle == null) {
throw new IllegalStateException("Pickle bundle is null.");
}
this.state = getState(bundle);
}
示例14: validateResponse
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入依赖的package包/类
/**
* Intepret a response from the auth server.
* <p>
* Throw an appropriate exception on errors; otherwise, return the response's
* status code.
*
* @return response's HTTP status code.
* @throws FxAccountClientException
*/
public static int validateResponse(HttpResponse response) throws FxAccountAbstractClientRemoteException {
final int status = response.getStatusLine().getStatusCode();
if (status == 200) {
return status;
}
int code;
int errno;
String error;
String message;
ExtendedJSONObject body;
try {
body = new SyncStorageResponse(response).jsonObjectBody();
body.throwIfFieldsMissingOrMisTyped(requiredErrorStringFields, String.class);
body.throwIfFieldsMissingOrMisTyped(requiredErrorLongFields, Long.class);
code = body.getLong(JSON_KEY_CODE).intValue();
errno = body.getLong(JSON_KEY_ERRNO).intValue();
error = body.getString(JSON_KEY_ERROR);
message = body.getString(JSON_KEY_MESSAGE);
} catch (Exception e) {
throw new FxAccountAbstractClientMalformedResponseException(response);
}
throw new FxAccountAbstractClientRemoteException(response, code, errno, error, message, body);
}
示例15: getState
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入依赖的package包/类
private State getState(final ExtendedJSONObject bundle) throws InvalidKeySpecException,
NonObjectJSONException, NoSuchAlgorithmException {
// TODO: Should copy-pasta BUNDLE_KEY_STATE & LABEL to this file to ensure we maintain
// old versions?
final StateLabel stateLabelString = StateLabel.valueOf(
bundle.getString(AndroidFxAccount.BUNDLE_KEY_STATE_LABEL));
final String stateString = bundle.getString(AndroidFxAccount.BUNDLE_KEY_STATE);
if (stateLabelString == null || stateString == null) {
throw new IllegalStateException("stateLabel and stateString must not be null, but: " +
"(stateLabel == null) = " + (stateLabelString == null) +
" and (stateString == null) = " + (stateString == null));
}
try {
return StateFactory.fromJSONObject(stateLabelString, new ExtendedJSONObject(stateString));
} catch (Exception e) {
throw new IllegalStateException("could not get state", e);
}
}