Search in sources :

Example 1 with HeaderParam

use of javax.ws.rs.HeaderParam in project presto by prestodb.

the class TaskResource method getResults.

@GET
@Path("{taskId}/results/{bufferId}/{token}")
@Produces(PRESTO_PAGES)
public void getResults(@PathParam("taskId") TaskId taskId, @PathParam("bufferId") OutputBufferId bufferId, @PathParam("token") final long token, @HeaderParam(PRESTO_MAX_SIZE) DataSize maxSize, @Suspended AsyncResponse asyncResponse) throws InterruptedException {
    requireNonNull(taskId, "taskId is null");
    requireNonNull(bufferId, "bufferId is null");
    long start = System.nanoTime();
    ListenableFuture<BufferResult> bufferResultFuture = taskManager.getTaskResults(taskId, bufferId, token, maxSize);
    Duration waitTime = randomizeWaitTime(DEFAULT_MAX_WAIT_TIME);
    bufferResultFuture = addTimeout(bufferResultFuture, () -> BufferResult.emptyResults(taskManager.getTaskInstanceId(taskId), token, false), waitTime, timeoutExecutor);
    ListenableFuture<Response> responseFuture = Futures.transform(bufferResultFuture, result -> {
        List<SerializedPage> serializedPages = result.getSerializedPages();
        GenericEntity<?> entity = null;
        Status status;
        if (serializedPages.isEmpty()) {
            status = Status.NO_CONTENT;
        } else {
            entity = new GenericEntity<>(serializedPages, new TypeToken<List<Page>>() {
            }.getType());
            status = Status.OK;
        }
        return Response.status(status).entity(entity).header(PRESTO_TASK_INSTANCE_ID, result.getTaskInstanceId()).header(PRESTO_PAGE_TOKEN, result.getToken()).header(PRESTO_PAGE_NEXT_TOKEN, result.getNextToken()).header(PRESTO_BUFFER_COMPLETE, result.isBufferComplete()).build();
    });
    // For hard timeout, add an additional 5 seconds to max wait for thread scheduling contention and GC
    Duration timeout = new Duration(waitTime.toMillis() + 5000, MILLISECONDS);
    bindAsyncResponse(asyncResponse, responseFuture, responseExecutor).withTimeout(timeout, Response.status(Status.NO_CONTENT).header(PRESTO_TASK_INSTANCE_ID, taskManager.getTaskInstanceId(taskId)).header(PRESTO_PAGE_TOKEN, token).header(PRESTO_PAGE_NEXT_TOKEN, token).header(PRESTO_BUFFER_COMPLETE, false).build());
    responseFuture.addListener(() -> readFromOutputBufferTime.add(Duration.nanosSince(start)), directExecutor());
    asyncResponse.register((CompletionCallback) throwable -> resultsRequestTime.add(Duration.nanosSince(start)));
}
Also used : TaskStatus(com.facebook.presto.execution.TaskStatus) Status(javax.ws.rs.core.Response.Status) Page(com.facebook.presto.spi.Page) Produces(javax.ws.rs.Produces) Iterables.transform(com.google.common.collect.Iterables.transform) TaskStatus(com.facebook.presto.execution.TaskStatus) Path(javax.ws.rs.Path) AsyncResponseHandler.bindAsyncResponse(io.airlift.http.server.AsyncResponseHandler.bindAsyncResponse) TaskState(com.facebook.presto.execution.TaskState) Duration(io.airlift.units.Duration) OutputBufferId(com.facebook.presto.OutputBuffers.OutputBufferId) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) BoundedExecutor(io.airlift.concurrent.BoundedExecutor) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) BufferResult(com.facebook.presto.execution.buffer.BufferResult) DELETE(javax.ws.rs.DELETE) PRESTO_PAGE_TOKEN(com.facebook.presto.client.PrestoHeaders.PRESTO_PAGE_TOKEN) Context(javax.ws.rs.core.Context) AsyncResponse(javax.ws.rs.container.AsyncResponse) GenericEntity(javax.ws.rs.core.GenericEntity) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Suspended(javax.ws.rs.container.Suspended) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) DataSize(io.airlift.units.DataSize) List(java.util.List) Response(javax.ws.rs.core.Response) CompletionCallback(javax.ws.rs.container.CompletionCallback) PRESTO_BUFFER_COMPLETE(com.facebook.presto.client.PrestoHeaders.PRESTO_BUFFER_COMPLETE) SerializedPage(com.facebook.presto.execution.buffer.SerializedPage) UriInfo(javax.ws.rs.core.UriInfo) PRESTO_CURRENT_STATE(com.facebook.presto.client.PrestoHeaders.PRESTO_CURRENT_STATE) Nested(org.weakref.jmx.Nested) PathParam(javax.ws.rs.PathParam) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) GET(javax.ws.rs.GET) TypeToken(com.google.common.reflect.TypeToken) Inject(javax.inject.Inject) PRESTO_TASK_INSTANCE_ID(com.facebook.presto.client.PrestoHeaders.PRESTO_TASK_INSTANCE_ID) ImmutableList(com.google.common.collect.ImmutableList) Managed(org.weakref.jmx.Managed) PRESTO_MAX_SIZE(com.facebook.presto.client.PrestoHeaders.PRESTO_MAX_SIZE) TaskManager(com.facebook.presto.execution.TaskManager) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MoreFutures.addTimeout(io.airlift.concurrent.MoreFutures.addTimeout) PRESTO_PAGE_NEXT_TOKEN(com.facebook.presto.client.PrestoHeaders.PRESTO_PAGE_NEXT_TOKEN) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) TimeStat(io.airlift.stats.TimeStat) Status(javax.ws.rs.core.Response.Status) POST(javax.ws.rs.POST) Executor(java.util.concurrent.Executor) Session(com.facebook.presto.Session) PRESTO_MAX_WAIT(com.facebook.presto.client.PrestoHeaders.PRESTO_MAX_WAIT) Futures(com.google.common.util.concurrent.Futures) PRESTO_PAGES(com.facebook.presto.PrestoMediaTypes.PRESTO_PAGES) TaskId(com.facebook.presto.execution.TaskId) TaskInfo(com.facebook.presto.execution.TaskInfo) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Duration(io.airlift.units.Duration) AsyncResponseHandler.bindAsyncResponse(io.airlift.http.server.AsyncResponseHandler.bindAsyncResponse) AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) BufferResult(com.facebook.presto.execution.buffer.BufferResult) SerializedPage(com.facebook.presto.execution.buffer.SerializedPage) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with HeaderParam

use of javax.ws.rs.HeaderParam in project graylog2-server by Graylog2.

the class Generator method determineParameters.

private List<Parameter> determineParameters(Method method) {
    final List<Parameter> params = Lists.newArrayList();
    int i = 0;
    for (Annotation[] annotations : method.getParameterAnnotations()) {
        final Parameter param = new Parameter();
        Parameter.Kind paramKind = Parameter.Kind.BODY;
        for (Annotation annotation : annotations) {
            if (annotation instanceof ApiParam) {
                final ApiParam apiParam = (ApiParam) annotation;
                param.setName(apiParam.name());
                param.setDescription(apiParam.value());
                param.setIsRequired(apiParam.required());
                param.setType(method.getGenericParameterTypes()[i]);
                if (!isNullOrEmpty(apiParam.defaultValue())) {
                    param.setDefaultValue(apiParam.defaultValue());
                }
            }
            if (annotation instanceof DefaultValue) {
                final DefaultValue defaultValueAnnotation = (DefaultValue) annotation;
                // Only set if empty to make sure ApiParam's defaultValue has precedence!
                if (isNullOrEmpty(param.getDefaultValue()) && !isNullOrEmpty(defaultValueAnnotation.value())) {
                    param.setDefaultValue(defaultValueAnnotation.value());
                }
            }
            if (annotation instanceof QueryParam) {
                paramKind = Parameter.Kind.QUERY;
            } else if (annotation instanceof PathParam) {
                paramKind = Parameter.Kind.PATH;
            } else if (annotation instanceof HeaderParam) {
                paramKind = Parameter.Kind.HEADER;
            } else if (annotation instanceof FormParam) {
                paramKind = Parameter.Kind.FORM;
            }
        }
        param.setKind(paramKind);
        if (param.getType() != null) {
            params.add(param);
        }
        i++;
    }
    return params;
}
Also used : DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) QueryParam(javax.ws.rs.QueryParam) ApiParam(io.swagger.annotations.ApiParam) PathParam(javax.ws.rs.PathParam) FormParam(javax.ws.rs.FormParam) Annotation(java.lang.annotation.Annotation)

Example 3 with HeaderParam

use of javax.ws.rs.HeaderParam in project wildfly by wildfly.

the class DeploymentRestResourcesDefintion method addMethodParameters.

private void addMethodParameters(JaxrsResourceMethodDescription jaxrsRes, Method method) {
    for (Parameter param : method.getParameters()) {
        ParamInfo paramInfo = new ParamInfo();
        paramInfo.cls = param.getType();
        paramInfo.defaultValue = null;
        paramInfo.name = null;
        paramInfo.type = null;
        Annotation annotation;
        if ((annotation = param.getAnnotation(PathParam.class)) != null) {
            PathParam pathParam = (PathParam) annotation;
            paramInfo.name = pathParam.value();
            paramInfo.type = "@" + PathParam.class.getSimpleName();
        } else if ((annotation = param.getAnnotation(QueryParam.class)) != null) {
            QueryParam queryParam = (QueryParam) annotation;
            paramInfo.name = queryParam.value();
            paramInfo.type = "@" + QueryParam.class.getSimpleName();
        } else if ((annotation = param.getAnnotation(HeaderParam.class)) != null) {
            HeaderParam headerParam = (HeaderParam) annotation;
            paramInfo.name = headerParam.value();
            paramInfo.type = "@" + HeaderParam.class.getSimpleName();
        } else if ((annotation = param.getAnnotation(CookieParam.class)) != null) {
            CookieParam cookieParam = (CookieParam) annotation;
            paramInfo.name = cookieParam.value();
            paramInfo.type = "@" + CookieParam.class.getSimpleName();
        } else if ((annotation = param.getAnnotation(MatrixParam.class)) != null) {
            MatrixParam matrixParam = (MatrixParam) annotation;
            paramInfo.name = matrixParam.value();
            paramInfo.type = "@" + MatrixParam.class.getSimpleName();
        } else if ((annotation = param.getAnnotation(FormParam.class)) != null) {
            FormParam formParam = (FormParam) annotation;
            paramInfo.name = formParam.value();
            paramInfo.type = "@" + FormParam.class.getSimpleName();
        }
        if (paramInfo.name == null) {
            paramInfo.name = param.getName();
        }
        if ((annotation = param.getAnnotation(DefaultValue.class)) != null) {
            DefaultValue defaultValue = (DefaultValue) annotation;
            paramInfo.defaultValue = defaultValue.value();
        }
        jaxrsRes.parameters.add(paramInfo);
    }
}
Also used : CookieParam(javax.ws.rs.CookieParam) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) MatrixParam(javax.ws.rs.MatrixParam) QueryParam(javax.ws.rs.QueryParam) Parameter(java.lang.reflect.Parameter) PathParam(javax.ws.rs.PathParam) FormParam(javax.ws.rs.FormParam) Annotation(java.lang.annotation.Annotation)

Example 4 with HeaderParam

use of javax.ws.rs.HeaderParam in project oxTrust by GluuFederation.

the class GroupWebService method searchGroupsPost.

@Path("/.search")
@POST
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Search group POST /.search", notes = "Returns a list of groups (https://tools.ietf.org/html/rfc7644#section-3.4.3)", response = ListResponse.class)
public Response searchGroupsPost(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @ApiParam(value = "SearchRequest", required = true) SearchRequest searchRequest) throws Exception {
    try {
        log.info("IN GroupWebService.searchGroupsPost()...");
        // Authorization check is done in searchGroups()
        Response response = searchGroups(authorization, token, searchRequest.getFilter(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getAttributesArray());
        URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Groups/.search");
        log.info("LEAVING GroupWebService.searchGroupsPost()...");
        return Response.fromResponse(response).location(location).build();
    } catch (EntryPersistenceException ex) {
        log.error("Error in searchGroupsPost", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource not found");
    } catch (Exception ex) {
        log.error("Error in searchGroupsPost", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 5 with HeaderParam

use of javax.ws.rs.HeaderParam in project oxTrust by GluuFederation.

the class ResourceTypeWS method getResourceTypeUser.

@Path("User")
@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response getResourceTypeUser(@HeaderParam("Authorization") String authorization) throws Exception {
    ResourceType userResourceType = new ResourceType();
    userResourceType.setDescription(Constants.USER_CORE_SCHEMA_DESCRIPTION);
    userResourceType.setEndpoint("/v2/Users");
    userResourceType.setName(Constants.USER_CORE_SCHEMA_NAME);
    userResourceType.setId(Constants.USER_CORE_SCHEMA_NAME);
    userResourceType.setSchema(Constants.USER_CORE_SCHEMA_ID);
    Meta userMeta = new Meta();
    userMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/User");
    userMeta.setResourceType("ResourceType");
    userResourceType.setMeta(userMeta);
    List<SchemaExtensionHolder> schemaExtensions = new ArrayList<SchemaExtensionHolder>();
    SchemaExtensionHolder userExtensionSchema = new SchemaExtensionHolder();
    userExtensionSchema.setSchema(Constants.USER_EXT_SCHEMA_ID);
    userExtensionSchema.setRequired(false);
    schemaExtensions.add(userExtensionSchema);
    userResourceType.setSchemaExtensions(schemaExtensions);
    // ResourceType[] resourceTypes = new ResourceType[]{userResourceType};
    URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/User");
    // return Response.ok(resourceTypes).location(location).build();
    return Response.ok(userResourceType).location(location).build();
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) SchemaExtensionHolder(org.gluu.oxtrust.model.scim2.schema.SchemaExtensionHolder) ArrayList(java.util.ArrayList) ResourceType(org.gluu.oxtrust.model.scim2.provider.ResourceType) URI(java.net.URI) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

HeaderParam (javax.ws.rs.HeaderParam)34 DefaultValue (javax.ws.rs.DefaultValue)32 Produces (javax.ws.rs.Produces)30 URI (java.net.URI)25 Response (javax.ws.rs.core.Response)23 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)21 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)21 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)21 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)21 Path (javax.ws.rs.Path)20 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)19 GET (javax.ws.rs.GET)16 ArrayList (java.util.ArrayList)11 Consumes (javax.ws.rs.Consumes)9 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)9 POST (javax.ws.rs.POST)7 GluuGroup (org.gluu.oxtrust.model.GluuGroup)5 Meta (org.gluu.oxtrust.model.scim2.Meta)5 ScimPatchUser (org.gluu.oxtrust.model.scim2.ScimPatchUser)5 User (org.gluu.oxtrust.model.scim2.User)5