Search in sources :

Example 76 with WebApplicationException

use of javax.ws.rs.WebApplicationException in project incubator-atlas by apache.

the class TypesResource method submit.

/**
     * Submits a type definition corresponding to a given type representing a meta model of a
     * domain. Could represent things like Hive Database, Hive Table, etc.
     */
@POST
@Consumes({ Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON })
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response submit(@Context HttpServletRequest request) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> TypesResource.submit()");
    }
    AtlasPerfTracer perf = null;
    if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
        perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.submit()");
    }
    JSONArray typesResponse = new JSONArray();
    try {
        final String typeDefinition = Servlets.getRequestPayload(request);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Creating type with definition {} ", typeDefinition);
        }
        AtlasTypesDef createTypesDef = TypeConverterUtil.toAtlasTypesDef(typeDefinition, typeRegistry);
        AtlasTypesDef createdTypesDef = typesREST.createAtlasTypeDefs(createTypesDef);
        List<String> typeNames = TypeConverterUtil.getTypeNames(createdTypesDef);
        for (int i = 0; i < typeNames.size(); i++) {
            final String name = typeNames.get(i);
            typesResponse.put(new JSONObject() {

                {
                    put(AtlasClient.NAME, name);
                }
            });
        }
        JSONObject response = new JSONObject();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(AtlasClient.TYPES, typesResponse);
        return Response.status(ClientResponse.Status.CREATED).entity(response).build();
    } catch (AtlasBaseException e) {
        LOG.error("Type creation failed", e);
        throw new WebApplicationException(Servlets.getErrorResponse(e));
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to persist types", e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to persist types", e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to persist types", e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== TypesResource.submit()");
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) JSONObject(org.codehaus.jettison.json.JSONObject) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) JSONArray(org.codehaus.jettison.json.JSONArray) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 77 with WebApplicationException

use of javax.ws.rs.WebApplicationException 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 78 with WebApplicationException

use of javax.ws.rs.WebApplicationException 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 79 with WebApplicationException

use of javax.ws.rs.WebApplicationException in project incubator-atlas by apache.

the class MetadataDiscoveryResource method searchUsingGremlinQuery.

/**
     * Search using raw gremlin query format.
     *
     * @param gremlinQuery search query in raw gremlin format.
     * @return JSON representing the type and results.
     */
@GET
@Path("search/gremlin")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
@InterfaceAudience.Private
public Response searchUsingGremlinQuery(@QueryParam("query") String gremlinQuery) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> MetadataDiscoveryResource.searchUsingGremlinQuery({})", gremlinQuery);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingGremlinQuery(" + gremlinQuery + ")");
        }
        gremlinQuery = ParamChecker.notEmpty(gremlinQuery, "gremlinQuery cannot be null or empty");
        final List<Map<String, String>> results = discoveryService.searchByGremlin(gremlinQuery);
        JSONObject response = new JSONObject();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(AtlasClient.QUERY, gremlinQuery);
        response.put(AtlasClient.QUERY_TYPE, QUERY_TYPE_GREMLIN);
        JSONArray list = new JSONArray();
        for (Map<String, String> result : results) {
            list.put(new JSONObject(result));
        }
        response.put(AtlasClient.RESULTS, list);
        response.put(AtlasClient.COUNT, list.length());
        return Response.ok(response).build();
    } catch (DiscoveryException | IllegalArgumentException e) {
        LOG.error("Unable to get entity list for gremlinQuery {}", gremlinQuery, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get entity list for gremlinQuery {}", gremlinQuery, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get entity list for gremlinQuery {}", gremlinQuery, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== MetadataDiscoveryResource.searchUsingGremlinQuery({})", gremlinQuery);
        }
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) JSONArray(org.codehaus.jettison.json.JSONArray) Map(java.util.Map) DiscoveryException(org.apache.atlas.discovery.DiscoveryException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 80 with WebApplicationException

use of javax.ws.rs.WebApplicationException in project oxAuth by GluuFederation.

the class CreateRptWS method authorizeGat.

private void authorizeGat(GatRequest request, UmaRPT rpt, String authorization, HttpServletRequest httpRequest) {
    if (request.getScopes().isEmpty()) {
        // nothing to authorize
        return;
    }
    AuthorizationGrant grant = tokenService.getAuthorizationGrant(authorization);
    if (umaAuthorizationService.allowToAddPermissionForGat(grant, rpt, request.getScopes(), httpRequest, request.getClaims())) {
        final List<String> scopes = new ArrayList<String>();
        if (rpt.getPermissions() != null) {
            scopes.addAll(rpt.getPermissions());
        }
        scopes.addAll(request.getScopes());
        rpt.setPermissions(scopes);
        try {
            ldapEntryManager.merge(rpt);
            return;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    // throw not authorized exception
    throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).entity(errorResponseFactory.getUmaJsonErrorResponse(UmaErrorResponseType.NOT_AUTHORIZED_PERMISSION)).build());
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) AuthorizationGrant(org.xdi.oxauth.model.common.AuthorizationGrant) WebApplicationException(javax.ws.rs.WebApplicationException)

Aggregations

WebApplicationException (javax.ws.rs.WebApplicationException)276 Produces (javax.ws.rs.Produces)77 GET (javax.ws.rs.GET)71 Path (javax.ws.rs.Path)69 IOException (java.io.IOException)47 POST (javax.ws.rs.POST)47 Consumes (javax.ws.rs.Consumes)44 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)43 Response (javax.ws.rs.core.Response)30 MediaType (javax.ws.rs.core.MediaType)26 URI (java.net.URI)25 HashMap (java.util.HashMap)20 JSONObject (org.codehaus.jettison.json.JSONObject)20 Test (org.junit.Test)19 JSONException (org.codehaus.jettison.json.JSONException)18 ApiOperation (io.swagger.annotations.ApiOperation)17 ArrayList (java.util.ArrayList)17 ByteArrayInputStream (java.io.ByteArrayInputStream)15 Viewable (org.apache.stanbol.commons.web.viewable.Viewable)15 List (java.util.List)14