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 void addEventData(String keyname, Object keyval) { if (null != keyval) { logstashEvent.put(keyname, keyval); } } }
/** * Puts value to object and returns this. * Handy alternative to put(String key, Object value) method. * * @param fieldName key with which the specified value is to be associated * @param fieldValue value to be associated with the specified key * @return this */ public JSONObject appendField(String fieldName, Object fieldValue) { put(fieldName, fieldValue); return this; }
/** * Gets the underlying JSON object. * * @return The underlying JSON object. */ public JSONObject getObject() { if (null != this.propertyOrderArray) { this.object.put(PROPERTY_ORDER_ARRAY_NAME, this.propertyOrderArray); } return this.object; }
@Nonnull @Override public JwtJsonBuilder subject(@Nonnull String sub) { json.put("sub", sub); return this; }
@Nonnull @Override public JwtJsonBuilder queryHash(@Nonnull String qsh) { json.put("qsh", qsh); return this; }
@Override public void writeLong(final String label, final long l) { this.pushLabel(label); this.object.put(label, l); }
@Override public JSONObject visit(SuspendVM a) { JSONObject o = makeActionSkeleton(a); o.put(ACTION_ID_LABEL, "suspendVM"); o.put(VM_LABEL, elementToJSON(a.getVM())); o.put(VM_DESTINATION_LABEL, elementToJSON(a.getDestinationNode())); o.put(VM_LOCATION_LABEL, elementToJSON(a.getSourceNode())); return o; }
@Override public void writeObject(final String label, final SerializableEntity object) { this.pushLabel(label); this.object.put(label, this.serializeObject(object)); }
@Override public JSONObject toJSONObject() { JSONObject o = super.toJSONObject(); // Append key value o.put("k", k.toString()); return o; }
private void createStackTraceEvent(JSONObject logstashEvent, LoggingEvent loggingEvent, final ThrowableInformation throwableInformation) { if (throwableInformation.getThrowableStrRep() != null) { final String[] options = { "full" }; final ThrowableInformationPatternConverter converter = ThrowableInformationPatternConverter.newInstance(options); final StringBuffer sb = new StringBuffer(); converter.format(loggingEvent, sb); final String stackTrace = sb.toString(); logstashEvent.put(LayoutFields.STACK_TRACE, stackTrace); } }
@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; }
@Test public void deserializationFailsWhenModeIsInvalid() { // Assert: this.assertDeserializationFailure(jsonObject -> jsonObject.put("modificationType", 123), IllegalArgumentException.class); }
@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")); }
@Test public void getLatestVersionReturnsZeroOnHttpError() { // Arrange: final JSONObject jsonObject = new JSONObject(); jsonObject.put("stable", "1.2.3"); // Assert: assertLatestVersionFailure(new ErrorResponseDeserializerUnion(500, jsonObject, null)); }