Search in sources :

Example 21 with JSONException

use of org.codehaus.jettison.json.JSONException in project apex-core by apache.

the class StramWebServices method setOperatorProperties.

// not supported by WebAppProxyServlet, can only be called directly
@POST
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/properties")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public JSONObject setOperatorProperties(JSONObject request, @PathParam("operatorName") String operatorName) {
    init();
    OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName);
    if (logicalOperator == null) {
        throw new NotFoundException();
    }
    JSONObject response = new JSONObject();
    try {
        @SuppressWarnings("unchecked") Iterator<String> keys = request.keys();
        while (keys.hasNext()) {
            String key = keys.next();
            String val = request.isNull(key) ? null : request.getString(key);
            LOG.debug("Setting property for {}: {}={}", operatorName, key, val);
            dagManager.setOperatorProperty(operatorName, key, val);
        }
    } catch (JSONException ex) {
        LOG.warn("Got JSON Exception: ", ex);
    } catch (Exception ex) {
        LOG.error("Caught exception: ", ex);
        throw new RuntimeException(ex);
    }
    return response;
}
Also used : 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) TimeoutException(java.util.concurrent.TimeoutException) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JSONException(org.codehaus.jettison.json.JSONException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 22 with JSONException

use of org.codehaus.jettison.json.JSONException in project incubator-atlas by apache.

the class TypesResource method getDefinition.

/**
     * Fetch the complete definition of a given type name which is unique.
     *
     * @param typeName name of a type which is unique.
     */
@GET
@Path("{typeName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getDefinition(@Context HttpServletRequest request, @PathParam("typeName") String typeName) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> TypesResource.getDefinition({})", typeName);
    }
    AtlasPerfTracer perf = null;
    if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
        perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getDefinition(" + typeName + ")");
    }
    JSONObject response = new JSONObject();
    try {
        TypesDef typesDef = TypeConverterUtil.toTypesDef(typeRegistry.getType(typeName), typeRegistry);
        ;
        String typeDefinition = TypesSerialization.toJson(typesDef);
        response.put(AtlasClient.TYPENAME, typeName);
        response.put(AtlasClient.DEFINITION, new JSONObject(typeDefinition));
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        return Response.ok(response).build();
    } catch (AtlasBaseException e) {
        LOG.error("Unable to get type definition for type {}", typeName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e));
    } catch (JSONException | IllegalArgumentException e) {
        LOG.error("Unable to get type definition for type {}", typeName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get type definition for type {}", typeName, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get type definition for type {}", typeName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== TypesResource.getDefinition({})", typeName);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) JSONObject(org.codehaus.jettison.json.JSONObject) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) TypesDef(org.apache.atlas.typesystem.TypesDef) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) JSONException(org.codehaus.jettison.json.JSONException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 23 with JSONException

use of org.codehaus.jettison.json.JSONException in project incubator-atlas by apache.

the class LineageResource method outputsGraph.

/**
     * Returns the outputs graph for a given entity id.
     *
     * @param guid dataset entity id
     */
@GET
@Path("{guid}/outputs/graph")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response outputsGraph(@PathParam("guid") String guid) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> LineageResource.outputsGraph({})", guid);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "LineageResource.outputsGraph(" + guid + ")");
        }
        AtlasLineageInfo lineageInfo = atlasLineageService.getAtlasLineageInfo(guid, LineageDirection.OUTPUT, -1);
        final String result = LineageUtils.toLineageStruct(lineageInfo, typeRegistry);
        JSONObject response = new JSONObject();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(AtlasClient.RESULTS, new JSONObject(result));
        return Response.ok(response).build();
    } catch (AtlasBaseException e) {
        LOG.error("Unable to get lineage outputs graph for entity guid={}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get lineage outputs graph for entity guid={}", guid, e);
        throw e;
    } catch (JSONException e) {
        LOG.error("Unable to get lineage outputs graph for entity guid={}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== LineageResource.outputsGraph({})", guid);
        }
    }
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) JSONObject(org.codehaus.jettison.json.JSONObject) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) JSONException(org.codehaus.jettison.json.JSONException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 24 with JSONException

use of org.codehaus.jettison.json.JSONException in project incubator-atlas by apache.

the class GraphBackedDiscoveryService method searchByFullText.

//For titan 0.5.4, refer to http://s3.thinkaurelius.com/docs/titan/0.5.4/index-backends.html for indexed query
//http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query
// .html#query-string-syntax for query syntax
@Override
@GraphTransaction
public String searchByFullText(String query, QueryParams queryParams) throws DiscoveryException {
    String graphQuery = String.format("v.\"%s\":(%s)", Constants.ENTITY_TEXT_PROPERTY_KEY, query);
    LOG.debug("Full text query: {}", graphQuery);
    Iterator<AtlasIndexQuery.Result<?, ?>> results = graph.indexQuery(Constants.FULLTEXT_INDEX, graphQuery).vertices();
    JSONArray response = new JSONArray();
    int index = 0;
    while (results.hasNext() && index < queryParams.offset()) {
        results.next();
        index++;
    }
    while (results.hasNext() && response.length() < queryParams.limit()) {
        AtlasIndexQuery.Result<?, ?> result = results.next();
        AtlasVertex<?, ?> vertex = result.getVertex();
        JSONObject row = new JSONObject();
        String guid = GraphHelper.getGuid(vertex);
        if (guid != null) {
            //Filter non-class entities
            try {
                row.put("guid", guid);
                row.put(AtlasClient.TYPENAME, GraphHelper.getTypeName(vertex));
                row.put(SCORE, result.getScore());
            } catch (JSONException e) {
                LOG.error("Unable to create response", e);
                throw new DiscoveryException("Unable to create response");
            }
            response.put(row);
        }
    }
    return response.toString();
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException) AtlasIndexQuery(org.apache.atlas.repository.graphdb.AtlasIndexQuery) DiscoveryException(org.apache.atlas.discovery.DiscoveryException) GremlinQueryResult(org.apache.atlas.query.GremlinQueryResult) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 25 with JSONException

use of org.codehaus.jettison.json.JSONException in project incubator-atlas by apache.

the class AtlasClient method createType.

/**
     * Register the given type(meta model)
     * @param typeAsJson type definition a jaon
     * @return result json object
     * @throws AtlasServiceException
     */
public List<String> createType(String typeAsJson) throws AtlasServiceException {
    LOG.debug("Creating type definition: {}", typeAsJson);
    JSONObject response = callAPIWithBody(API.CREATE_TYPE, typeAsJson);
    List<String> results = extractResults(response, AtlasClient.TYPES, new ExtractOperation<String, JSONObject>() {

        @Override
        String extractElement(JSONObject element) throws JSONException {
            return element.getString(AtlasClient.NAME);
        }
    });
    LOG.debug("Create type definition returned results: {}", results);
    return results;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) 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