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)));
}
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;
}
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);
}
}
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);
}
}
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();
}
Aggregations