下面列出了javax.ws.rs.core.MediaType#TEXT_PLAIN 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Maps the data in an uploaded delimited document into RDF in the requested format
* using a JSON-LD mapping string. The file must be present in the data/tmp/ directory.
*
* @param fileName the name of the delimited document in the data/tmp/ directory
* @param jsonld a mapping in JSON-LD
* @param format the RDF serialization to use if getting a preview
* @param containsHeaders whether the delimited file has headers
* @param separator the character the columns are separated by if it is a CSV
* @return a Response with a JSON object containing the mapping file name and a
* string containing the converted data in the requested format
*/
@POST
@javax.ws.rs.Path("{documentName}/map-preview")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
@RolesAllowed("user")
@ApiOperation("ETL an uploaded delimited document using mapping JSON-LD")
public Response etlFilePreview(@PathParam("documentName") String fileName,
@FormDataParam("jsonld") String jsonld,
@DefaultValue("jsonld") @QueryParam("format") String format,
@DefaultValue("true") @QueryParam("containsHeaders") boolean containsHeaders,
@DefaultValue(",") @QueryParam("separator") String separator) {
checkStringParam(jsonld, "Must provide a JSON-LD string");
// Convert the data
Model data = etlFile(fileName, () -> jsonldToModel(jsonld, transformer), containsHeaders, separator, true);
return Response.ok(groupedModelToString(data, format, transformer)).build();
}
@GET
@Path("/{id}")
@Produces({MediaType.TEXT_PLAIN})
public String getSpecs(@PathParam("id") String id) throws AppException {
if (!ready) {
throw new AppException(503, "API playground not ready");
}
File f = new File(dir, id);
if (!f.exists()) {
throw new AppException(404, "File not found");
}
return Utility.getInstance().file2str(f);
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public List<String> getIDs() {
ensureStart();
log.info("Retrieving all IDs");
return cache.keySet().stream().sorted().collect(Collectors.toList());
}
@POST
@Produces(MediaType.TEXT_PLAIN)
@Transactional
public String create() {
Group group = new Group();
group.setId(1L);
group.setName("group_name");
em.merge(group);
return "ok";
}
@GET
@Path("/oc")
@Produces(MediaType.TEXT_PLAIN)
public Response getNumberOfObjectClasses(
@CookieParam(AuthenticationService.SID) String sessionID,
@PathParam("contextid") String contextID) {
WebUtil.checkUserSession(sessionID);
Repository repository = RepositoryManager.getInstance().getRepository();
Context context = repository.getContext(contextID);
int size = context.getNumberOfObjectClasses();
return Response.ok(String.valueOf(size)).build();
}
@Path("/topologies")
@GET
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public String getConnectionPoolNames() {
return MonitorConsole.getInstance().getMonitorNames();
}
/**
* 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)
*/
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.TEXT_PLAIN)
@Path("/token/identity-provider/usage")
@ApiOperation(
value = "Get identity provider usage",
notes = "Provides a description of how the currently configured identity provider expects credentials to be passed to POST /access/token/identity-provider",
response = String.class
)
@ApiResponses({
@ApiResponse(code = 400, message = HttpStatusMessages.MESSAGE_400),
@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 getIdentityProviderUsageInstructions(@Context HttpServletRequest httpServletRequest) {
// if not configuration for login, don't consider credentials
if (identityProvider == null) {
throw new IllegalStateException("Custom login not supported by this NiFi Registry");
}
Class ipClazz = identityProvider.getClass();
String identityProviderName = StringUtils.isNotEmpty(ipClazz.getSimpleName()) ? ipClazz.getSimpleName() : ipClazz.getName();
try {
String usageInstructions = "Usage Instructions for '" + identityProviderName + "': ";
usageInstructions += identityProvider.getUsageInstructions().getText();
return generateOkResponse(usageInstructions).build();
} catch (Exception e) {
// If, for any reason, this identity provider does not support getUsageInstructions(), e.g., returns null or throws NotImplementedException.
return Response.status(Response.Status.NOT_IMPLEMENTED)
.entity("The currently configured identity provider, '" + identityProvider.getClass().getName() + "' does not provide usage instructions.")
.build();
}
}
@GET()
@Path("permit-all")
@PermitAll
@Produces(MediaType.TEXT_PLAIN)
public String hello(@Context SecurityContext ctx) {
Principal caller = ctx.getUserPrincipal();
String name = caller == null ? "anonymous" : caller.getName();
boolean hasJWT = jwt.getClaimNames() != null;
String helloReply = String.format("hello + %s, isSecure: %s, authScheme: %s, hasJWT: %s", name, ctx.isSecure(),
ctx.getAuthenticationScheme(), hasJWT);
return helloReply;
}
@GET
@Path("/count")
@Produces(MediaType.TEXT_PLAIN)
public String oneTimeEvnt() {
scheduler.startTimer(300, () -> event());
return "started!";
}
@Path("/html-transform")
@POST
@Consumes(MediaType.TEXT_HTML)
@Produces(MediaType.TEXT_PLAIN)
public String htmlTransform(String html) {
LOG.debugf("Parsing HTML %s", html);
return producerTemplate.requestBody(
XmlRouteBuilder.DIRECT_HTML_TRANSFORM,
html,
String.class);
}
@GET
@Path("/{environment}/{botId}/undo/{conversationId}")
@Produces(MediaType.TEXT_PLAIN)
@ApiOperation(value = "Is UNDO available?")
Boolean isUndoAvailable(@PathParam("environment") Deployment.Environment environment,
@PathParam("botId") String botId,
@PathParam("conversationId") String conversationId);
@Timed
@PUT
@Path("/flexdown")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_JSON)
public Response flexDown(FlexDownClusterRequest request) {
Preconditions.checkNotNull(request, "request object cannot be null or empty");
Integer instances = request.getInstances();
String profile = request.getProfile();
List<String> constraints = request.getConstraints();
LOGGER.info("Received flex down request. Profile: {}, Instances: {}, Constraints: {}", profile, instances, constraints);
Response.ResponseBuilder response = Response.status(Response.Status.ACCEPTED);
boolean isValidRequest = validateProfile(profile, response);
isValidRequest = isValidRequest && validateInstances(instances, response);
isValidRequest = isValidRequest && validateConstraints(constraints, response);
if (isValidRequest) {
Integer numFlexedUp = this.getNumFlexedupNMs(profile);
if (numFlexedUp < instances) {
String message = String.format("Number of requested instances for flexdown is greater than the number of " +
"Node Managers previously flexed up for profile '%s'. Requested: %d, Previously flexed Up: %d. " +
"Only %d Node Managers will be flexed down.", profile, instances, numFlexedUp, numFlexedUp);
response.entity(message);
LOGGER.warn(message);
}
}
Response returnResponse = response.build();
if (returnResponse.getStatus() == Response.Status.ACCEPTED.getStatusCode()) {
String constraint = constraints != null && !constraints.isEmpty() ? constraints.get(0) : null;
this.myriadOperations.flexDownCluster(profileManager.get(profile), ConstraintFactory.createConstraint(constraint), instances);
}
return returnResponse;
}
@Path("/templateUriFromHeader")
@POST
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public String templateUriFromHeader(String message) {
LOG.infof("Calling templateUriFromHeader with %s", message);
return template.requestBodyAndHeader("mustache://template/simple.mustache?allowTemplateFromHeader=true", message,
MustacheConstants.MUSTACHE_RESOURCE_URI,
"/template/another.mustache", String.class);
}
@GET
@Path("/greeting")
@Produces(MediaType.TEXT_PLAIN)
public String greeting() {
return greeting;
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getApplicationName() {
return outputMessage;
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getCount() {
return "count:" + counter.get();
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}
@GET
@Path("/nameAndVersion")
@Produces(MediaType.TEXT_PLAIN)
public String nameAndVersion() {
return applicationName + "/" + applicationVersion;
}
@POST
@Path( "{environmentId}/containers/{containerId}/export/{name}/{version}/{private}" )
@Produces( { MediaType.TEXT_PLAIN } )
Response createTemplate( @PathParam( "environmentId" ) String environmentId,
@PathParam( "containerId" ) String containerId, @PathParam( "name" ) String templateName,
@PathParam( "version" ) String version, @PathParam( "private" ) boolean privateTemplate );