use of com.rometools.rome.io.WireFeedOutput in project tutorials by eugenp.
the class JsonChannelHttpMessageConverter method writeInternal.
@Override
protected void writeInternal(Channel wireFeed, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
WireFeedOutput feedOutput = new WireFeedOutput();
try {
String xmlStr = feedOutput.outputString(wireFeed, true);
JSONObject xmlJSONObj = XML.toJSONObject(xmlStr);
String jsonPrettyPrintString = xmlJSONObj.toString(4);
outputMessage.getBody().write(jsonPrettyPrintString.getBytes());
} catch (JSONException | FeedException e) {
e.printStackTrace();
}
}
use of com.rometools.rome.io.WireFeedOutput in project spring-framework by spring-projects.
the class AbstractWireFeedHttpMessageConverter method writeInternal.
@Override
protected void writeInternal(T wireFeed, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
Charset charset = (StringUtils.hasLength(wireFeed.getEncoding()) ? Charset.forName(wireFeed.getEncoding()) : DEFAULT_CHARSET);
MediaType contentType = outputMessage.getHeaders().getContentType();
if (contentType != null) {
contentType = new MediaType(contentType, charset);
outputMessage.getHeaders().setContentType(contentType);
}
WireFeedOutput feedOutput = new WireFeedOutput();
try {
Writer writer = new OutputStreamWriter(outputMessage.getBody(), charset);
feedOutput.output(wireFeed, writer);
} catch (FeedException ex) {
throw new HttpMessageNotWritableException("Could not write WireFeed: " + ex.getMessage(), ex);
}
}
use of com.rometools.rome.io.WireFeedOutput 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();
}
use of com.rometools.rome.io.WireFeedOutput in project spring-framework by spring-projects.
the class AbstractFeedView method renderMergedOutputModel.
@Override
protected final void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
T wireFeed = newFeed();
buildFeedMetadata(model, wireFeed, request);
buildFeedEntries(model, wireFeed, request, response);
setResponseContentType(request, response);
if (!StringUtils.hasText(wireFeed.getEncoding())) {
wireFeed.setEncoding("UTF-8");
}
WireFeedOutput feedOutput = new WireFeedOutput();
ServletOutputStream out = response.getOutputStream();
feedOutput.output(wireFeed, new OutputStreamWriter(out, wireFeed.getEncoding()));
out.flush();
}
Aggregations