@ApiOperation(value="Retrieves given resource/file based on the type and file name",
response=String.class, code=200)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"),
@ApiResponse(code = 404, message = "resource/file not found") })
@GET
@Path(STATIC_BY_TYPE_GET_URI)
public Response getSharedContent(
@ApiParam(value = "Type of the resource e.g. js, css, etc", required = true) @PathParam("type") String type,
@ApiParam(value = "Name of the resource to look up", required = true) @PathParam("file") String file) {
InputStream resourceStream = formRendererBase.readResources("/" + type + "/" + file);
if (resourceStream == null) {
return Response.status(Status.NOT_FOUND).build();
}
StreamingOutput entity = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
IOUtils.copy(resourceStream, output);
}
};
ResponseBuilder builder = Response.ok().entity(entity);
setHeaders(builder);
return builder
.header("Content-Type", getContentType(file))
.build();
}