use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class Contexts method getJsonResponse.
static JSONObject getJsonResponse(CloseableHttpClient httpClient, HttpRequestBase request) throws IOException, ClientProtocolException {
request.addHeader("accept", ContentType.APPLICATION_JSON.getMimeType());
CloseableHttpResponse response = httpClient.execute(request);
JSONObject jsonResponse;
try {
HttpEntity entity = response.getEntity();
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
final String errorInfo;
if (entity != null)
errorInfo = " -- " + EntityUtils.toString(entity);
else
errorInfo = "";
throw new IllegalStateException("Unexpected HTTP resource from service:" + response.getStatusLine().getStatusCode() + ":" + response.getStatusLine().getReasonPhrase() + errorInfo);
}
if (entity == null)
throw new IllegalStateException("No HTTP resource from service");
jsonResponse = JSONObject.parse(new BufferedInputStream(entity.getContent()));
EntityUtils.consume(entity);
} finally {
response.close();
}
return jsonResponse;
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class ToolkitStreamsContext method addConfigToJSON.
protected void addConfigToJSON(JSONObject graphConfig, Map<String, Object> config) {
for (String key : config.keySet()) {
Object value = config.get(key);
if (key.equals(ContextProperties.SUBMISSION_PARAMS)) {
// value causes issues below and no need to add this to json
continue;
}
if (JSONObject.isValidObject(value)) {
graphConfig.put(key, value);
continue;
}
if (value instanceof Collection) {
JSONArray ja = new JSONArray();
@SuppressWarnings("unchecked") Collection<Object> coll = (Collection<Object>) value;
ja.addAll(coll);
graphConfig.put(key, ja);
}
}
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class RestServer method viewerJSONable.
private String viewerJSONable(TWindow<? extends JSONAble, ?> window, String context, String name) {
TStream<JSONObject> jsonStream = JSONStreams.toJSON(window.getStream());
SPLStream splStream = JSONStreams.toSPL(jsonStream);
return viewerSpl(splStream.window(window), context, name);
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class SubmissionParameter method toJSON.
@Override
public JSONObject toJSON() {
// meet the requirements of BOperatorInvocation.setParameter()
// and OperatorGenerator.parameterValue()
/*
* The SubmissionParameter parameter value json is:
* <pre><code>
* object {
* type : "submissionParameter"
* value : object {
* name : string. submission parameter name
* metaType : operator.Type.MetaType.name() string
* defaultValue : any. may be null. type appropriate for metaType.
* }
* }
* </code></pre>
*/
JSONObject jo = new JSONObject();
JSONObject jv = new JSONObject();
jo.put("type", TYPE_SUBMISSION_PARAMETER);
jo.put("value", jv);
jv.put("name", name);
jv.put("metaType", metaType.name());
if (defaultValue != null)
jv.put("defaultValue", defaultValue);
return jo;
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class StreamImpl method publish.
@Override
public void publish(String topic, boolean allowFilter) {
checkTopicName(topic);
Type tupleType = getTupleType();
if (JSONObject.class.equals(tupleType)) {
filtersNotAllowed(allowFilter);
@SuppressWarnings("unchecked") TStream<JSONObject> json = (TStream<JSONObject>) this;
JSONStreams.toSPL(json).publish(topic, allowFilter);
return;
}
BOperatorInvocation op;
if (Schemas.usesDirectSchema(tupleType) || ((TStream<T>) this) instanceof SPLStream) {
// would not allow a filter against.
if (String.class != tupleType && !(((TStream<T>) this) instanceof SPLStream))
filtersNotAllowed(allowFilter);
// Publish as a stream consumable by SPL & Java/Scala
Map<String, Object> publishParms = new HashMap<>();
publishParms.put("topic", topic);
publishParms.put("allowFilter", allowFilter);
op = builder().addSPLOperator("Publish", "com.ibm.streamsx.topology.topic::Publish", publishParms);
} else if (getTupleClass() != null) {
filtersNotAllowed(allowFilter);
// Publish as a stream consumable only by Java/Scala
Map<String, Object> params = new HashMap<>();
params.put("topic", topic);
params.put("class", getTupleClass().getName());
op = builder().addSPLOperator("Publish", "com.ibm.streamsx.topology.topic::PublishJava", params);
} else {
throw new IllegalStateException("A TStream with a tuple type that contains a generic or unknown type cannot be published");
}
SourceInfo.setSourceInfo(op, SPL.class);
this.connectTo(op, false, null);
}
Aggregations