private int query(String query) throws IOException { URL url = new URL("https://api.qubole.com/api/v1.2/commands"); JSONObject queryJson = new JSONObject(); queryJson.put("query", query); String body = queryJson.toString(); Map response = makeRequest(url, body); return (Integer) response.get("id"); }
private static Mono<UserInfoErrorResponse> parse(ClientResponse httpResponse) { String wwwAuth = httpResponse.headers().asHttpHeaders().getFirst(HttpHeaders.WWW_AUTHENTICATE); if (!StringUtils.isEmpty(wwwAuth)) { // Bearer token error? return Mono.fromCallable(() -> UserInfoErrorResponse.parse(wwwAuth)); } ParameterizedTypeReference<Map<String, String>> typeReference = new ParameterizedTypeReference<Map<String, String>>() {}; // Other error? return httpResponse .bodyToMono(typeReference) .map(body -> new UserInfoErrorResponse(ErrorObject.parse(new JSONObject(body)))); } }
private static TokenResponse parse(Map<String, Object> json) { try { return TokenResponse.parse(new JSONObject(json)); } catch (ParseException pe) { OAuth2Error oauth2Error = new OAuth2Error(INVALID_TOKEN_RESPONSE_ERROR_CODE, "An error occurred parsing the Access Token response: " + pe.getMessage(), null); throw new OAuth2AuthorizationException(oauth2Error, pe); } }
private JsonSerializer(final SerializationContext context, final boolean enforceReadWriteOrder) { super(context); this.object = new JSONObject(); this.propertyOrderArray = enforceReadWriteOrder ? new JSONArray() : null; }
public static JSONObject getSymptom(Symptom symptom) { Map<String, Object> map = new HashMap<>(); map.put(PHATObjectToJSON.KEYS.level.name(), symptom.getCurrentLevel()); map.put(PHATObjectToJSON.KEYS.type.name(), symptom.getSymptomType()); return new JSONObject(map); }
private JSONObject serializeObject(final SerializableEntity object) { if (null == object) { return new JSONObject(); } final JsonSerializer serializer = new JsonSerializer(this.getContext(), null != this.propertyOrderArray); object.serialize(serializer); return serializer.getObject(); }
@Override public JSONObject toJSON(Ban o) { JSONObject c = new JSONObject(); c.put("id", getJSONId()); c.put("vm", elementToJSON(o.getInvolvedVMs().iterator().next())); c.put("nodes", nodesToJSON(o.getInvolvedNodes())); c.put("continuous", o.isContinuous()); return c; } }
@Override public JSONObject toJSON(Fence o) { JSONObject c = new JSONObject(); c.put("id", getJSONId()); c.put("vm", elementToJSON(o.getInvolvedVMs().iterator().next())); c.put("nodes", nodesToJSON(o.getInvolvedNodes())); c.put("continuous", o.isContinuous()); return c; } }
@Test public void getLatestVersionReturnsZeroOnInvalidJsonResponse() { // Arrange: final JSONObject jsonObject = new JSONObject(); // Assert: assertLatestVersionFailure(new ErrorResponseDeserializerUnion(500, jsonObject, null)); }
@Override public JSONObject toJSON(Sync sync) { JSONObject c = new JSONObject(); c.put("id", getJSONId()); c.put("vms", vmsToJSON(sync.getInvolvedVMs())); c.put("continuous", sync.isContinuous()); return c; } }
@Test public void getLatestVersionReturnsZeroOnHttpError() { // Arrange: final JSONObject jsonObject = new JSONObject(); jsonObject.put("stable", "1.2.3"); // Assert: assertLatestVersionFailure(new ErrorResponseDeserializerUnion(500, jsonObject, null)); }
private AccountId createAccountIdFromJson(final String address) { final JSONObject jsonObject = new JSONObject(); jsonObject.put("account", address); return new AccountId(new JsonDeserializer(jsonObject, null)); } }
@Test(expected = IllegalArgumentException.class) public void cannotDeserializeUnknownBlock() { // Arrange: final JSONObject object = new JSONObject(); object.put("type", 7); final JsonDeserializer deserializer = new JsonDeserializer(object, null); // Act: BlockFactory.VERIFIABLE.deserialize(deserializer); }
private static SerializableAccountId createFromJson(final Address address) { final JSONObject jsonObject = new JSONObject(); jsonObject.put("account", address.toString()); // Act: return new SerializableAccountId(Utils.createDeserializer(jsonObject)); }
@Test(expected = IllegalArgumentException.class) public void cannotDeserializeUnknownTransaction() { // Arrange: final JSONObject object = new JSONObject(); object.put("type", 7); final JsonDeserializer deserializer = new JsonDeserializer(object, null); // Act: TransactionFactory.VERIFIABLE.deserialize(deserializer); }
@Test public void canReadFromDeserializer() { // Arrange: final JSONObject object = new JSONObject(); object.put("id", "foo.bar"); final Deserializer deserializer = Utils.createDeserializer(object); // Act: final NamespaceId namespaceId = NamespaceId.readFrom(deserializer, "id"); // Assert: Assert.assertThat(namespaceId, IsEqual.equalTo(new NamespaceId("foo.bar"))); }
@Test public void canDeserializeNemProperty() { // Arrange: final JSONObject jsonObject = new JSONObject(); jsonObject.put("name", "FoO"); jsonObject.put("value", "bAr"); // Act: final NemProperty property = new NemProperty(Utils.createDeserializer(jsonObject)); // Assert: Assert.assertThat(property.getName(), IsEqual.equalTo("FoO")); Assert.assertThat(property.getValue(), IsEqual.equalTo("bAr")); }
@Override public JSONObject toJSON(ResourceCapacity o) { JSONObject c = new JSONObject(); c.put("id", getJSONId()); c.put("nodes", nodesToJSON(o.getInvolvedNodes())); c.put("rc", o.getResource()); c.put("amount", o.getAmount()); c.put("continuous", o.isContinuous()); return c; } }
@Override public JSONObject toJSON(Network net) throws JSONConverterException { JSONObject container = new JSONObject(); container.put(ModelViewConverter.IDENTIFIER, getJSONId()); container.put("switches", switchesToJSON(net.getSwitches())); container.put("links", linksToJSON(net.getLinks())); container.put("routing", routingToJSON(net.getRouting())); return container; }
private static MosaicId deserialize(final String namespaceId, final String name) { final JSONObject jsonObject = new JSONObject(); if (null != namespaceId) { jsonObject.put("namespaceId", namespaceId); } if (null != name) { jsonObject.put("name", name); } return new MosaicId(new JsonDeserializer(jsonObject, null)); }