use of org.codehaus.jettison.json.JSONException in project apex-core by apache.
the class PubSubWebSocketClient method openConnection.
/**
* <p>openConnection.</p>
*
* @param timeoutMillis
* @throws IOException
* @throws ExecutionException
* @throws InterruptedException
* @throws TimeoutException
*/
public void openConnection(long timeoutMillis) throws IOException, ExecutionException, InterruptedException, TimeoutException {
throwable.set(null);
List<Cookie> cookies = null;
if (loginUrl != null && userName != null && password != null) {
// get the session key first before attempting web socket
JSONObject json = new JSONObject();
try {
json.put("userName", userName);
json.put("password", password);
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
Response response = client.preparePost(loginUrl).setHeader("Content-Type", "application/json").setBody(json.toString()).execute().get();
cookies = response.getCookies();
}
BoundRequestBuilder brb = client.prepareGet(uri.toString());
if (cookies != null) {
for (Cookie cookie : cookies) {
brb.addCookie(cookie);
}
}
connection = brb.execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new PubSubWebSocket()).build()).get(timeoutMillis, TimeUnit.MILLISECONDS);
}
use of org.codehaus.jettison.json.JSONException in project apex-core by apache.
the class StramWebServices method searchLoggersLevel.
@GET
@Path(PATH_LOGGERS + "/search")
@Produces(MediaType.APPLICATION_JSON)
public JSONObject searchLoggersLevel(@QueryParam("pattern") String pattern) {
init();
JSONObject response = new JSONObject();
JSONArray loggersArray = new JSONArray();
try {
if (pattern != null) {
Map<String, String> matches = LoggerUtil.getClassesMatching(pattern);
for (Map.Entry<String, String> match : matches.entrySet()) {
JSONObject node = new JSONObject();
node.put("name", match.getKey());
node.put("level", match.getValue());
loggersArray.put(node);
}
}
response.put("loggers", loggersArray);
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
return response;
}
use of org.codehaus.jettison.json.JSONException in project apex-core by apache.
the class StramWebServices method getPort.
@GET
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/ports/{portName}")
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getPort(@PathParam("operatorName") String operatorName, @PathParam("portName") String portName) {
init();
OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName);
Set<LogicalPlan.InputPortMeta> inputPorts;
Set<LogicalPlan.OutputPortMeta> outputPorts;
if (logicalOperator == null) {
ModuleMeta logicalModule = dagManager.getModuleMeta(operatorName);
if (logicalModule == null) {
throw new NotFoundException();
}
inputPorts = logicalModule.getInputStreams().keySet();
outputPorts = logicalModule.getOutputStreams().keySet();
} else {
inputPorts = logicalOperator.getInputStreams().keySet();
outputPorts = logicalOperator.getOutputStreams().keySet();
}
try {
JSONObject resp = getPortObject(inputPorts, outputPorts, portName);
if (resp != null) {
return resp;
}
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
throw new NotFoundException();
}
use of org.codehaus.jettison.json.JSONException in project apex-core by apache.
the class TypeDiscoverer method setTypeArguments.
public void setTypeArguments(Class<?> clazz, Type type, JSONObject meta) {
// TODO: traverse hierarchy and resolve all type parameters
Type superClassType = clazz.getGenericSuperclass();
if (superClassType != null) {
getParameterizedTypeArguments(superClassType);
}
getParameterizedTypeArguments(type);
try {
resolveTypeParameters(type, meta);
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
use of org.codehaus.jettison.json.JSONException in project apex-core by apache.
the class TypeGraph method getPortTypeInfo.
private Collection<JSONObject> getPortTypeInfo(String clazzName, Map<Type, Type> typeReplacement, List<CompactFieldNode> ports) throws JSONException {
TypeGraphVertex tgv = typeGraph.get(clazzName);
if (tgv == null) {
return null;
}
Collection<JSONObject> portInfo = new ArrayList<>();
for (CompactFieldNode port : ports) {
Type fieldType = port.getFieldSignatureNode().getFieldType();
Type t = fieldType;
if (fieldType instanceof ParameterizedTypeNode) {
// TODO: Right now getPortInfo assumes a single parameterized type
t = ((ParameterizedTypeNode) fieldType).getActualTypeArguments()[0];
} else {
// TODO: Check behavior for Ports not using Default Input/output ports
TypeGraphVertex portVertex = typeGraph.get(port.getDescription());
t = findTypeArgument(portVertex, typeReplacement);
LOG.debug("Field is of type {}", fieldType.getClass());
}
JSONObject meta = new JSONObject();
try {
meta.put("name", port.getName());
setTypes(meta, t, typeReplacement);
portInfo.add(meta);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
return portInfo;
}
Aggregations