final MediaType mt = getResponseType(type); if (eq(FMT_SYS, format)) { return ok(mt, new JaxbIncidentTree(tree)); } else if (eq(FMT_DIGEST, format)) { return ok(mt, new JaxbIncidentFullTree(svc, request.getLocale(), tree)); } else if (eq(FMT_FULL, format)) { return ok(mt, new JaxbIncidentFullTree(svc, request.getLocale(), tree)); } else { return unknownFormat();
@POST @Path("{uuid}/persist") @RestQuery(name = "persistFile", description = "Persists a recently uploaded file to the permanent storage", pathParameters = { @RestParameter(description = "File UUID", isRequired = true, name = "uuid", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "The file has been persisted", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No file by the given UUID found", responseCode = HttpServletResponse.SC_NOT_FOUND) }, returnDescription = "") public Response persistFile(@PathParam("uuid") String uuid) throws NotFoundException { try { staticFileService.persistFile(uuid); return R.ok(); } catch (IOException e) { logger.error("Unable to persist file '{}': {}", uuid, getStackTrace(e)); return R.serverError(); } }
return ok(get(mediaPackageID, mediaPackageElementID), contentType, some(file.length()), none("")); } catch (IOException e) { throw new NotFoundException();
final MediaType mt = getResponseType(type); if (eq(FMT_SYS, format)) { return ok(mt, new JaxbIncidentList(incidents)); } else if (eq(FMT_DIGEST, format)) { return ok(mt, new JaxbIncidentDigestList(svc, request.getLocale(), incidents)); } else if (eq(FMT_FULL, format)) { return ok(mt, new JaxbIncidentFullList(svc, request.getLocale(), incidents)); } else { return unknownFormat();
@GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Path("{id}.{type:xml|json}") @RestQuery(name = "incidentjson", description = "Returns the job incident by it's incident identifier.", returnDescription = "Returns the job incident.", pathParameters = { @RestParameter(name = "id", isRequired = true, description = "The incident identifier.", type = Type.INTEGER), @RestParameter(name = "type", isRequired = true, description = "The media type of the response [xml|json]", defaultValue = "xml", type = Type.STRING)}, reponses = { @RestResponse(responseCode = SC_OK, description = "The job incident."), @RestResponse(responseCode = SC_NOT_FOUND, description = "No job incident with this identifier was found.")}) public Response getIncident(@PathParam("id") final long incidentId, @PathParam("type") final String type) throws NotFoundException { try { Incident incident = svc.getIncident(incidentId); return ok(getResponseType(type), new JaxbIncident(incident)); } catch (IncidentServiceException e) { logger.warn("Unable to get job incident for incident id {}: {}", incidentId, e); throw new WebApplicationException(INTERNAL_SERVER_ERROR); } }
@Override public Response apply(List<BundleInfo> infos) { final Set<BundleVersion> versions = set(); for (BundleInfo bundle : infos) { versions.add(bundle.getVersion()); } final BundleInfo example = infos.get(0); switch (versions.size()) { case 0: // no versions... throw new Error("bug"); case 1: // all versions align return ok(obj(p("consistent", true)).append(fullVersionJson.apply(example.getVersion()))); default: // multiple versions found return ok(obj(p("consistent", false), p("versions", arr(mlist(versions.iterator()) .map(Functions.<BundleVersion, Jsons.Val> co(fullVersionJson)))))); } } });
@GET @Path("{uuid}") @RestQuery(name = "getStaticFile", description = "Returns a static file resource", pathParameters = { @RestParameter(description = "Static File Universal Unique Id", isRequired = true, name = "uuid", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns a static file resource", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No file by the given uuid found", responseCode = HttpServletResponse.SC_NOT_FOUND) }, returnDescription = "") public Response getStaticFile(@PathParam("uuid") String uuid) throws NotFoundException { try { final InputStream file = staticFileService.getFile(uuid); final String filename = staticFileService.getFileName(uuid); final Long length = staticFileService.getContentLength(uuid); // It is safe to pass the InputStream without closing it, JAX-RS takes care of that return RestUtil.R.ok(file, getMimeType(filename), Option.some(length), Option.some(filename)); } catch (NotFoundException e) { throw e; } catch (Exception e) { logger.warn("Unable to retrieve file with uuid {}", uuid, e); return Response.serverError().build(); } }
@GET // path prefix "bundles" is contained here and not in the path annotation of the class // See https://opencast.jira.com/browse/MH-9768 @Path("bundles/list") @Produces(APPLICATION_JSON) @RestQuery( name = "list", description = "Return a list of all running bundles on the whole cluster.", reponses = { @RestResponse(description = "A list of bundles.", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "The search results, expressed as xml or json.") public Response getVersions() { final Monadics.ListMonadic<Jsons.Val> bundleInfos = mlist(getDb().getBundles()).map( Functions.<BundleInfo, Jsons.Val> co(bundleInfo)); return ok(obj(p("bundleInfos", arr(bundleInfos)), p("count", bundleInfos.value().size()))); }
/** * Create a response with status OK from a stream. * * @param in * the input stream to read from * @param contentType * the content type to set the Content-Type response header to * @param streamLength * an optional value for the Content-Length response header * @param fileName * an optional file name for the Content-Disposition response header */ public static Response ok(InputStream in, String contentType, Option<Long> streamLength, Option<String> fileName) { return ok(in, option(contentType), streamLength, fileName); }
private Response unknownFormat() { return badRequest("Unknown format"); } }
@Override public Response apply(List<BundleInfo> infos) { final String bundleVersion = infos.get(0).getBundleVersion(); final Option<String> buildNumber = infos.get(0).getBuildNumber(); for (BundleInfo a : infos) { if (ne(a.getBundleVersion(), bundleVersion) || ne(a.getBuildNumber(), buildNumber)) return ok(TEXT_PLAIN_TYPE, "false"); } return ok(TEXT_PLAIN_TYPE, "true"); } });
/** Run <code>f</code> if there is at least one bundle matching the given prefixes. */ private Response withBundles(List<String> prefixes, Function<List<BundleInfo>, Response> f) { final List<BundleInfo> info = getDb().getBundles(toArray(String.class, prefixes)); if (info.size() > 0) { return f.apply(info); } else { return notFound("No bundles match one of the given prefixes"); } } }
@GET @Path("nop") @RestQuery( name = "nop", description = "Create an empty job for testing purposes.", returnDescription = "The service statistics.", reponses = { @RestResponse(responseCode = SC_OK, description = "OK") }) public Response nop() { return RestUtil.R.ok(getSvc().nop()); } }