Java Code Examples for javax.ws.rs.core.MediaType.WILDCARD

The following are Jave code examples for showing how to use WILDCARD of the javax.ws.rs.core.MediaType class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: nifi-registry   File: AccessResource.java   Source Code and License Vote up 6 votes
/**
 * Gets the current client's identity and authorized permissions.
 *
 * @param httpServletRequest the servlet request
 * @return An object describing the current client identity, as determined by the server, and it's permissions.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
        value = "Returns the current client's authenticated identity and permissions to top-level resources",
        response = CurrentUser.class
)
@ApiResponses({
        @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409 + " The NiFi Registry might be running unsecured.") })
public Response getAccessStatus(@Context HttpServletRequest httpServletRequest) {

    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    if (user == null) {
        // Not expected to happen unless the nifi registry server has been seriously misconfigured.
        throw new WebApplicationException(new Throwable("Unable to access details for current user."));
    }

    final CurrentUser currentUser = authorizationService.getCurrentUser();

    return generateOkResponse(currentUser).build();
}
 
Example 2
Project: task-app   File: TaskAppIOResource.java   Source Code and License Vote up 6 votes
@POST
@RolesAllowed(value = "TASK_APP_CLIENT")
@Path("/upload")
@Consumes(MediaType.WILDCARD)
public void upload(
        @QueryParam("taskId") Long taskId,
        @QueryParam("code") String code,
        @QueryParam("mimeType") String mimeType,
        @QueryParam("name") String name,
        InputStream inputStream) {
    JmdTaskData jmdTaskData = new JmdTaskData();
    jmdTaskData.setTaskFk(taskId);
    jmdTaskData.setCode(code);
    jmdTaskData.setMimeType(mimeType);
    jmdTaskData.setName(name);
    taskDao.setData(jmdTaskData);
    File file = new TaskAppFile().getFile(taskAppService.getTmpDir(), jmdTaskData, true);
    try {
        FileUtil.streamToFile(inputStream, file);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        FileUtil.close(inputStream);
    }
}
 
Example 3
Project: nifi-registry   File: AccessPolicyResource.java   Source Code and License Vote up 6 votes
/**
 * Retrieves all access policies
 *
 * @return A list of access policies
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
        value = "Gets all access policies",
        response = AccessPolicy.class,
        responseContainer = "List"
)
@ApiResponses({
        @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401),
        @ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403),
        @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409) })
public Response getAccessPolicies() {

    verifyAuthorizerIsManaged();
    authorizeAccess(RequestAction.READ);

    List<AccessPolicy> accessPolicies = authorizationService.getAccessPolicies();
    if (accessPolicies == null) {
        accessPolicies = Collections.emptyList();
    }

    return generateOkResponse(accessPolicies).build();
}
 
Example 4
Project: Equella   File: FileResource.java   Source Code and License Vote up 5 votes
@PUT
@Path("/{uuid}/dir{parentFolder:(/.*)?}/{foldername}")
@Consumes(MediaType.WILDCARD)
public Response createFolderPut(
	//@formatter:off
	@PathParam("uuid") String stagingUuid,
	@PathParam("parentFolder") String parentFolder,
	@PathParam("foldername") String foldername
	//@formatter:on
);
 
Example 5
Project: Equella   File: FileResource.java   Source Code and License Vote up 5 votes
@GET
@Path("/{uuid}/content/{filepath:(.*)}")
@Produces(MediaType.WILDCARD)
@ApiOperation(value = "Download a file")
@Cache(maxAge = 86400, sMaxAge = 0, mustRevalidate = true)
public Response downloadFile(@Context HttpHeaders headers, @PathParam("uuid") String stagingUuid,
	@PathParam("filepath") String filepath) throws IOException;
 
Example 6
Project: nifi-registry   File: BucketFlowResource.java   Source Code and License Vote up 5 votes
@GET
@Path("{flowId}/versions/{versionNumber: \\d+}")
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
        value = "Gets the given version of a flow",
        response = VersionedFlowSnapshot.class
)
@ApiResponses({
        @ApiResponse(code = 400, message = HttpStatusMessages.MESSAGE_400),
        @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401),
        @ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403),
        @ApiResponse(code = 404, message = HttpStatusMessages.MESSAGE_404),
        @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409) })
public Response getFlowVersion(
        @PathParam("bucketId")
        @ApiParam("The bucket identifier")
            final String bucketId,
        @PathParam("flowId")
        @ApiParam("The flow identifier")
            final String flowId,
        @PathParam("versionNumber")
        @ApiParam("The version number")
            final Integer versionNumber) {
    authorizeBucketAccess(RequestAction.READ, bucketId);

    final VersionedFlowSnapshot snapshot = registryService.getFlowSnapshot(bucketId, flowId, versionNumber);
    populateLinksAndPermissions(snapshot);

    return Response.status(Response.Status.OK).entity(snapshot).build();
}
 
Example 7
Project: nifi-registry   File: BucketFlowResource.java   Source Code and License Vote up 5 votes
@GET
@Path("{flowId}")
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
        value = "Gets a flow",
        response = VersionedFlow.class
)
@ApiResponses({
        @ApiResponse(code = 400, message = HttpStatusMessages.MESSAGE_400),
        @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401),
        @ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403),
        @ApiResponse(code = 404, message = HttpStatusMessages.MESSAGE_404),
        @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409) })
public Response getFlow(
        @PathParam("bucketId")
        @ApiParam("The bucket identifier")
            final String bucketId,
        @PathParam("flowId")
        @ApiParam("The flow identifier")
            final String flowId) {

    authorizeBucketAccess(RequestAction.READ, bucketId);

    final VersionedFlow flow = registryService.getFlow(bucketId, flowId);
    permissionsService.populateItemPermissions(flow);
    linkService.populateFlowLinks(flow);

    return Response.status(Response.Status.OK).entity(flow).build();
}
 
Example 8
Project: nifi-registry   File: BucketFlowResource.java   Source Code and License Vote up 5 votes
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
        value = "Gets all flows in the given bucket",
        response = VersionedFlow.class,
        responseContainer = "List"
)
@ApiResponses({
        @ApiResponse(code = 400, message = HttpStatusMessages.MESSAGE_400),
        @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401),
        @ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403),
        @ApiResponse(code = 404, message = HttpStatusMessages.MESSAGE_404),
        @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409) })
public Response getFlows(
        @PathParam("bucketId")
        @ApiParam("The bucket identifier")
        final String bucketId) {

    authorizeBucketAccess(RequestAction.READ, bucketId);

    final List<VersionedFlow> flows = registryService.getFlows(bucketId);
    permissionsService.populateItemPermissions(flows);
    linkService.populateFlowLinks(flows);

    return Response.status(Response.Status.OK).entity(flows).build();
}
 
Example 9
Project: Equella   File: ScrapbookResource.java   Source Code and License Vote up 5 votes
@POST
@Path("/")
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create new scrapbook item")
public Response create(@ApiParam(value = "Scrapbook item") ScrapbookItemBean itemBean, @Context UriInfo info)
{
	return Response.status(Status.CREATED)
		.location(getScrapbookItemURI(createOrUpdateScrapbookItem(null, itemBean, info).getItemId())).build();
}
 
Example 10
Project: task-app   File: ClientApi.java   Source Code and License Vote up 5 votes
@POST
@Path("/upload")
@Consumes(MediaType.WILDCARD)
public void upload(
        @QueryParam("taskId") Long taskId,
        @QueryParam("code") String code,
        @QueryParam("mimeType") String mimeType,
        @QueryParam("name") String name,
        InputStream inputStream);
 
Example 11
Project: ontonethub   File: OntonethubOntologiesResource.java   Source Code and License Vote up 5 votes
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
public Response listOntologies(){
	JSONArray array = new JSONArray();
	
	OntologyInfo[] ontologyInfos = ontonetHub.getOntologiesInfo();
	for(OntologyInfo ontologyInfo : ontologyInfos){
		try {
			String jsonString = objectMapper.writeValueAsString(ontologyInfo);
			JSONObject json = new JSONObject(jsonString);
			String ontologyId = json.getString("ontologyID");
			
			if(ontologyId != null){
				String ontologySourceURI = uriInfo.getBaseUri() + "ontonethub/ontology/" + ontologyId + "/source";
				json.put("ontologySource", ontologySourceURI);
			}
			array.put(json);
			
		} catch (JsonProcessingException | JSONException e) {
			log.error(e.getMessage(), e);
		}	
	}
	
	
	return Response.ok(array.toString()).build();
}
 
Example 12
Project: ontonethub   File: OntonethubIndexingResource.java   Source Code and License Vote up 5 votes
@GET
@Consumes(MediaType.WILDCARD)
@Produces({
	KRFormat.RDF_XML,
	KRFormat.RDF_JSON,
	KRFormat.TURTLE,
	KRFormat.N_TRIPLE,
	KRFormat.N3,
	"application/json-ld"
	})
@Path("/{id}/source")
public Response getOntologySource(@PathParam("id") String id){
	
	ResponseBuilder responseBuilder = null;
	Model model;
	try {
		model = ontonetHub.getOntologySource(id);
		responseBuilder = Response.ok(model);
	} catch (NoSuchOntologyException e1) {
		JSONObject json = new JSONObject();
		try {
			json.put("error", "No ontology exists with the ID provided.");
		} catch (JSONException e) {
			log.error(e.getMessage(), e);
		}
		responseBuilder = Response.status(Status.NOT_FOUND).entity(json);
	}
	
	return responseBuilder.build();
}
 
Example 13
Project: nifi-registry   File: BucketFlowResource.java   Source Code and License Vote up 5 votes
@GET
@Path("{flowId}/versions/latest/metadata")
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
        value = "Get the metadata for the latest version of a flow",
        response = VersionedFlowSnapshotMetadata.class
)
@ApiResponses({
        @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401),
        @ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403),
        @ApiResponse(code = 404, message = HttpStatusMessages.MESSAGE_404),
        @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409) })
public Response getLatestFlowVersionMetadata(
        @PathParam("bucketId")
        @ApiParam("The bucket identifier")
        final String bucketId,
        @PathParam("flowId")
        @ApiParam("The flow identifier")
        final String flowId) {

    authorizeBucketAccess(RequestAction.READ, bucketId);

    final VersionedFlowSnapshotMetadata latest = registryService.getLatestFlowSnapshotMetadata(bucketId, flowId);
    if (latest == null) {
        throw new ResourceNotFoundException("No flow versions found for flow with id " + flowId);
    }

    linkService.populateSnapshotLinks(latest);

    return Response.status(Response.Status.OK).entity(latest).build();
}
 
Example 14
Project: oryx2   File: ErrorResource.java   Source Code and License Vote up 5 votes
@GET
@Produces(MediaType.WILDCARD)
public Response errorEmpty(@Context HttpServletRequest request) {
  Number statusCode = (Number) request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
  Response.Status finalStatus = statusCode == null ?
      Response.Status.OK : Response.Status.fromStatusCode(statusCode.intValue());
  return Response.status(finalStatus).build();
}
 
Example 15
Project: nifi-registry   File: TenantResource.java   Source Code and License Vote up 5 votes
/**
 * Retrieves all the of users in this NiFi.
 *
 * @return a list of users
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("users")
@ApiOperation(
        value = "Gets all users",
        notes = NON_GUARANTEED_ENDPOINT,
        response = User.class,
        responseContainer = "List"
)
@ApiResponses({
        @ApiResponse(code = 400, message = HttpStatusMessages.MESSAGE_400),
        @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401),
        @ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403),
        @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409) })
public Response getUsers() {
    verifyAuthorizerIsManaged();

    authorizeAccess(RequestAction.READ);

    // get all the users
    final List<User> users = authorizationService.getUsers();

    // generate the response
    return generateOkResponse(users).build();
}
 
Example 16
Project: nifi-registry   File: AccessResource.java   Source Code and License Vote up 4 votes
/**
 * Creates a token for accessing the REST API using a custom identity provider configured using NiFi Registry extensions.
 *
 * @param httpServletRequest the servlet request
 * @return A JWT (string)
 */
@POST
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.TEXT_PLAIN)
@Path("/token/identity-provider")
@ApiOperation(
        value = "Creates a token for accessing the REST API via a custom identity provider.",
        notes = "The user credentials must be passed in a format understood by the custom identity provider, e.g., a third-party auth token in an HTTP header. " +
                "The exact format of the user credentials expected by the custom identity provider can be discovered by 'GET /access/token/identity-provider/usage'. " +
                "The token returned is formatted as a JSON Web Token (JWT). The token is base64 encoded and comprised of three parts. The header, " +
                "the body, and the signature. The expiration of the token is a contained within the body. The token can be used in the Authorization header " +
                "in the format 'Authorization: Bearer <token>'.",
        response = String.class
)
@ApiResponses({
        @ApiResponse(code = 400, message = HttpStatusMessages.MESSAGE_400),
        @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401),
        @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409 + " The NiFi Registry may not be configured to support login with customized credentials."),
        @ApiResponse(code = 500, message = HttpStatusMessages.MESSAGE_500) })
public Response createAccessTokenUsingIdentityProviderCredentials(@Context HttpServletRequest httpServletRequest) {

    // only support access tokens when communicating over HTTPS
    if (!httpServletRequest.isSecure()) {
        throw new IllegalStateException("Access tokens are only issued over HTTPS");
    }

    // if not configured with custom identity provider, don't consider credentials
    if (identityProvider == null) {
        throw new IllegalStateException("Custom login not supported by this NiFi Registry");
    }

    AuthenticationRequest authenticationRequest = identityProvider.extractCredentials(httpServletRequest);

    if (authenticationRequest == null) {
        throw new UnauthorizedException("The client credentials are missing from the request.")
                .withAuthenticateChallenge(identityProvider.getUsageInstructions().getAuthType());
    }

    final String token;
    try {
        token = createAccessToken(identityProvider, authenticationRequest);
    } catch (InvalidCredentialsException ice) {
        throw new UnauthorizedException("The supplied client credentials are not valid.", ice)
                .withAuthenticateChallenge(identityProvider.getUsageInstructions().getAuthType());
    }

    // build the response
    final URI uri = URI.create(generateResourceUri("access", "token"));
    return generateCreatedResponse(uri, token).build();

}
 
Example 17
Project: nifi-registry   File: AccessPolicyResource.java   Source Code and License Vote up 4 votes
/**
 * Retrieve a specified access policy for a given (action, resource) pair.
 *
 * @param action the action, i.e. "read", "write"
 * @param rawResource the name of the resource as a raw string
 * @return An access policy.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{action}/{resource: .+}")
@ApiOperation(
        value = "Gets an access policy for the specified action and resource",
        notes = "Will return the effective policy if no specific policy exists for the specified action and resource. "
                + "Must have Read permissions to the policy with the desired action and resource. Permissions for the policy that is "
                + "returned will be indicated in the response. If the client does not have permissions to that policy, the response "
                + "will not include the policy and the permissions in the response will be marked accordingly. If the client does "
                + "not have permissions to the policy of the desired action and resource a 403 response will be returned.",
        response = AccessPolicy.class
)
@ApiResponses({
        @ApiResponse(code = 400, message = HttpStatusMessages.MESSAGE_400),
        @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401),
        @ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403),
        @ApiResponse(code = 404, message = HttpStatusMessages.MESSAGE_404),
        @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409) })
public Response getAccessPolicyForResource(
        @ApiParam(value = "The request action.", allowableValues = "read, write, delete", required = true)
        @PathParam("action")
        final String action,
        @ApiParam(value = "The resource of the policy.", required = true)
        @PathParam("resource")
        final String rawResource) {

    verifyAuthorizerIsManaged();
    authorizeAccess(RequestAction.READ);

    // parse the action and resource type
    final RequestAction requestAction = RequestAction.valueOfValue(action);
    final String resource = "/" + rawResource;

    AccessPolicy accessPolicy = authorizationService.getAccessPolicy(resource, requestAction);
    if (accessPolicy == null) {
        throw new ResourceNotFoundException("No policy found for action='" + action + "', resource='" + resource + "'");
    }
    return generateOkResponse(accessPolicy).build();
}
 
Example 18
Project: nifi-registry   File: AccessResource.java   Source Code and License Vote up 4 votes
@POST
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.TEXT_PLAIN)
@Path("/token/kerberos")
@ApiOperation(
        value = "Creates a token for accessing the REST API via Kerberos Service Tickets or SPNEGO Tokens (which includes Kerberos Service Tickets)",
        notes = "The token returned is formatted as a JSON Web Token (JWT). The token is base64 encoded and comprised of three parts. The header, " +
                "the body, and the signature. The expiration of the token is a contained within the body. The token can be used in the Authorization header " +
                "in the format 'Authorization: Bearer <token>'.",
        response = String.class
)
@ApiResponses({
        @ApiResponse(code = 400, message = HttpStatusMessages.MESSAGE_400),
        @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401),
        @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409 + " The NiFi Registry may not be configured to support login Kerberos credentials."),
        @ApiResponse(code = 500, message = HttpStatusMessages.MESSAGE_500) })
public Response createAccessTokenUsingKerberosTicket(@Context HttpServletRequest httpServletRequest) {

    // only support access tokens when communicating over HTTPS
    if (!httpServletRequest.isSecure()) {
        throw new IllegalStateException("Access tokens are only issued over HTTPS");
    }

    // if not configured with custom identity provider, don't consider credentials
    if (!properties.isKerberosSpnegoSupportEnabled() || kerberosSpnegoIdentityProvider == null) {
        throw new IllegalStateException("Kerberos service ticket login not supported by this NiFi Registry");
    }

    AuthenticationRequest authenticationRequest = kerberosSpnegoIdentityProvider.extractCredentials(httpServletRequest);

    if (authenticationRequest == null) {
        throw new UnauthorizedException("The client credentials are missing from the request.")
                .withAuthenticateChallenge(kerberosSpnegoIdentityProvider.getUsageInstructions().getAuthType());
    }

    final String token;
    try {
        token = createAccessToken(kerberosSpnegoIdentityProvider, authenticationRequest);
    } catch (final InvalidCredentialsException ice){
        throw new UnauthorizedException("The supplied client credentials are not valid.", ice)
                .withAuthenticateChallenge(kerberosSpnegoIdentityProvider.getUsageInstructions().getAuthType());
    }

    // build the response
    final URI uri = URI.create(generateResourceUri("access", "token"));
    return generateCreatedResponse(uri, token).build();

}
 
Example 19
Project: task-app   File: ClientApi.java   Source Code and License Vote up 4 votes
@POST
@Path("/download")
@Produces(MediaType.WILDCARD)
public InputStream download(
        @QueryParam("taskId") Long taskId,
        @QueryParam("code") String code);
 
Example 20
Project: ontonethub   File: OntonethubIndexingResource.java   Source Code and License Vote up 4 votes
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.TEXT_PLAIN)
public Response sayHello(){
	return Response.ok("Welcome to the new Home of OntoNetHub for Semantic DAF!").build();
}