Search in sources :

Example 16 with JSONException

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);
}
Also used : Cookie(org.apache.apex.shaded.ning19.com.ning.http.client.cookie.Cookie) Response(org.apache.apex.shaded.ning19.com.ning.http.client.Response) BoundRequestBuilder(org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) JSONObject(org.codehaus.jettison.json.JSONObject) JSONException(org.codehaus.jettison.json.JSONException) WebSocketUpgradeHandler(org.apache.apex.shaded.ning19.com.ning.http.client.ws.WebSocketUpgradeHandler)

Example 17 with JSONException

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;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException) Map(java.util.Map) BeanMap(org.apache.commons.beanutils.BeanMap) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 18 with JSONException

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();
}
Also used : ModuleMeta(com.datatorrent.stram.plan.logical.LogicalPlan.ModuleMeta) OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) JSONObject(org.codehaus.jettison.json.JSONObject) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) JSONException(org.codehaus.jettison.json.JSONException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 19 with JSONException

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);
    }
}
Also used : GenericArrayType(java.lang.reflect.GenericArrayType) WildcardType(java.lang.reflect.WildcardType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) JSONException(org.codehaus.jettison.json.JSONException)

Example 20 with JSONException

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;
}
Also used : ClassNodeType(com.datatorrent.stram.webapp.asm.ClassNodeType) Type(com.datatorrent.stram.webapp.asm.Type) JSONObject(org.codehaus.jettison.json.JSONObject) ParameterizedTypeNode(com.datatorrent.stram.webapp.asm.Type.ParameterizedTypeNode) ArrayList(java.util.ArrayList) CompactFieldNode(com.datatorrent.stram.webapp.asm.CompactFieldNode) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException)

Aggregations

JSONException (org.codehaus.jettison.json.JSONException)281 JSONObject (org.codehaus.jettison.json.JSONObject)256 Response (javax.ws.rs.core.Response)183 Builder (javax.ws.rs.client.Invocation.Builder)179 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)179 Test (org.testng.annotations.Test)174 BaseTest (org.xdi.oxauth.BaseTest)174 Parameters (org.testng.annotations.Parameters)171 RegisterRequest (org.xdi.oxauth.client.RegisterRequest)78 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)68 JSONArray (org.codehaus.jettison.json.JSONArray)44 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)43 URISyntaxException (java.net.URISyntaxException)35 TokenRequest (org.xdi.oxauth.client.TokenRequest)35 ResponseType (org.xdi.oxauth.model.common.ResponseType)35 WebApplicationException (javax.ws.rs.WebApplicationException)18 IOException (java.io.IOException)17 OxAuthCryptoProvider (org.xdi.oxauth.model.crypto.OxAuthCryptoProvider)17 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)14