use of org.opencastproject.feed.api.FeedGenerator in project opencast by opencast.
the class FeedRegistrationScanner method install.
/**
* {@inheritDoc}
*
* @see org.apache.felix.fileinstall.ArtifactInstaller#install(java.io.File)
*/
@Override
public void install(File artifact) throws Exception {
logger.info("Installing a feed from '{}'", artifact.getName());
Properties props = new Properties();
FileInputStream in = null;
try {
in = new FileInputStream(artifact);
props.load(in);
} finally {
IOUtils.closeQuietly(in);
}
// Always include the server URL obtained from the bundle context
props.put("org.opencastproject.server.url", bundleContext.getProperty("org.opencastproject.server.url"));
Class<?> clazz = getClass().getClassLoader().loadClass(props.getProperty(FEED_CLASS));
FeedGenerator generator = (FeedGenerator) clazz.newInstance();
generator.setSearchService(searchService);
generator.setSeriesService(seriesService);
generator.initialize(props);
ServiceRegistration<?> reg = bundleContext.registerService(FeedGenerator.class.getName(), generator, null);
generators.put(artifact, reg);
sumInstalledFiles++;
// Determine the number of available profiles
String[] filesInDirectory = artifact.getParentFile().list(new FilenameFilter() {
@Override
public boolean accept(File arg0, String name) {
return name.endsWith(".properties");
}
});
// Once all profiles have been loaded, announce readiness
if (filesInDirectory.length == sumInstalledFiles) {
Dictionary<String, String> properties = new Hashtable<>();
properties.put(ARTIFACT, "feed");
logger.debug("Indicating readiness of feed");
bundleContext.registerService(ReadinessIndicator.class.getName(), new ReadinessIndicator(), properties);
logger.info("All {} feeds installed", filesInDirectory.length);
} else {
logger.debug("{} of {} feeds installed", sumInstalledFiles, filesInDirectory.length);
}
}
use of org.opencastproject.feed.api.FeedGenerator in project opencast by opencast.
the class FeedServiceImpl method getFeed.
/*
* Note: We're using Regex matching for the path here, instead of normal JAX-RS paths. Previously this class was a servlet,
* which was fine except that it had auth issues. Removing the servlet fixed the auth issues, but then the paths (as written
* in the RestQuery docs) don't work because JAX-RS does not support having "/" characters as part of the variable's value.
*
* So, what we've done instead is match everything that comes in under the /feeds/ namespace, and then substring it out the way
* the old servlet code did. But without the servlet, or auth issues :)
*/
@GET
@Produces(MediaType.TEXT_XML)
@Path("{query: .*}")
// FIXME: These Opencast REST classes do not support this path style, and need to have that support added
@RestQuery(name = "getFeed", description = "Gets an Atom or RSS feed", pathParameters = { @RestParameter(description = "The feed type", name = "type", type = Type.STRING, isRequired = true), @RestParameter(description = "The feed version", name = "version", type = Type.STRING, isRequired = true), @RestParameter(description = "The feed query", name = "query", type = Type.STRING, isRequired = true) }, reponses = { @RestResponse(description = "Return the feed of the appropriate type", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "")
public Response getFeed(@Context HttpServletRequest request) {
String contentType = null;
logger.debug("Requesting RSS or Atom feed.");
FeedInfo feedInfo = null;
Organization organization = securityService.getOrganization();
// Try to extract requested feed type and content
try {
feedInfo = extractFeedInfo(request);
} catch (Exception e) {
return Response.status(Status.BAD_REQUEST).build();
}
// Set the content type
if (feedInfo.getType().equals(Feed.Type.Atom))
contentType = "application/atom+xml";
else if (feedInfo.getType().equals(Feed.Type.RSS))
contentType = "application/rss+xml";
// Have a feed generator create the requested feed
Feed feed = null;
for (FeedGenerator generator : feeds) {
if (generator.accept(feedInfo.getQuery())) {
feed = generator.createFeed(feedInfo.getType(), feedInfo.getQuery(), feedInfo.getSize(), organization);
if (feed == null) {
return Response.serverError().build();
}
break;
}
}
// Have we found a feed generator?
if (feed == null) {
logger.debug("RSS/Atom feed could not be generated");
return Response.status(Status.NOT_FOUND).build();
}
// Set character encoding
Variant v = new Variant(MediaType.valueOf(contentType), null, feed.getEncoding());
String outputString = null;
try {
if (feedInfo.getType().equals(Feed.Type.RSS)) {
logger.debug("Creating RSS feed output.");
SyndFeedOutput output = new SyndFeedOutput();
outputString = output.outputString(new RomeRssFeed(feed, feedInfo));
} else {
logger.debug("Creating Atom feed output.");
WireFeedOutput output = new WireFeedOutput();
outputString = output.outputString(new RomeAtomFeed(feed, feedInfo));
}
} catch (FeedException e) {
return Response.serverError().build();
}
return Response.ok(outputString, v).build();
}
Aggregations