StaticFileRestService { public void activate(ComponentContext cc) throws ConfigurationException { logger.info("Static File REST Service started."); serverUrl = OsgiUtil.getContextProperty(cc, OpencastConstants.SERVER_URL_PROPERTY); useWebserver = BooleanUtils.toBoolean(OsgiUtil.getOptCfg(cc.getProperties(), STATICFILES_WEBSERVER_ENABLED_KEY) .getOrElse("false")); webserverURL = OsgiUtil.getOptCfg(cc.getProperties(), STATICFILES_WEBSERVER_URL_KEY); Option<String> cfgMaxUploadSize = OsgiUtil.getOptContextProperty(cc, STATICFILES_UPLOAD_MAX_SIZE_KEY); if (cfgMaxUploadSize.isSome()) maxUploadSize = Long.parseLong(cfgMaxUploadSize.get()); }  void setStaticFileService(StaticFileService staticFileService); void setSecurityService(SecurityService securityService); void activate(ComponentContext cc); @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) }, responses = { @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 = "") Response getStaticFile(@PathParam("uuid") String uuid); @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.TEXT_PLAIN) @Path("") @RestQuery(name = "postStaticFile", description = "Post a new static resource", bodyParameter = @RestParameter(description = "The static resource file", isRequired = true, name = "BODY", type = RestParameter.Type.FILE), responses = { @RestResponse(description = "Returns the id of the uploaded static resource", responseCode = HttpServletResponse.SC_CREATED), @RestResponse(description = "No filename or file to upload found", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "The upload size is too big", responseCode = HttpServletResponse.SC_BAD_REQUEST) }, returnDescription = "") Response postStaticFile(@Context HttpServletRequest request); @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) }, responses = { @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 = "") Response persistFile(@PathParam("uuid") String uuid); @GET @Produces(MediaType.TEXT_PLAIN) @Path("{uuid}/url") @RestQuery(name = "getStaticFileUrl", description = "Returns a static file resource's URL", pathParameters = { @RestParameter(description = "Static File Universal Unique Id", isRequired = true, name = "uuid", type = RestParameter.Type.STRING) }, responses = { @RestResponse(description = "Returns a static file resource's URL", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No file by the given uuid found", responseCode = HttpServletResponse.SC_NOT_FOUND) }, returnDescription = "") Response getStaticFileUrl(@PathParam("uuid") String uuid); @DELETE @Path("{uuid}") @RestQuery(name = "deleteStaticFile", description = "Remove the static file", returnDescription = "No content", pathParameters = { @RestParameter(name = "uuid", description = "Static File Universal Unique Id", isRequired = true, type = STRING) }, responses = { @RestResponse(responseCode = SC_NO_CONTENT, description = "File deleted"), @RestResponse(responseCode = SC_NOT_FOUND, description = "No file by the given uuid found") }) Response deleteStaticFile(@PathParam("uuid") String uuid); URI getStaticFileURL(String uuid); static final String STATICFILES_URL_PATH; static final String STATICFILES_WEBSERVER_ENABLED_KEY; static final String STATICFILES_WEBSERVER_URL_KEY; static final String STATICFILES_UPLOAD_MAX_SIZE_KEY; }
@Test public void testUseWebserver() throws ConfigurationException { StaticFileRestService staticFileRestService = new StaticFileRestService(); staticFileRestService.activate(getComponentContext(null, 100000000L)); assertFalse(staticFileRestService.useWebserver); staticFileRestService.activate(getComponentContext("", 100000000L)); assertFalse(staticFileRestService.useWebserver); staticFileRestService.activate(getComponentContext("false", 100000000L)); assertFalse(staticFileRestService.useWebserver); staticFileRestService.activate(getComponentContext("other", 100000000L)); assertFalse(staticFileRestService.useWebserver); staticFileRestService.activate(getComponentContext("true", 100000000L)); assertTrue(staticFileRestService.useWebserver); }