java - How to return RSS with REST service? -


i'm using rome rss feed generating , jersey rest service.

here rss feed generation.

public syndfeed generate() {     syndfeed feed = new syndfeedimpl();     feed.setfeedtype( "rss_2.0" );     feed.settitle( "my site" );     feed.setlink("http://example.com");     feed.setdescription("test site.");      list<syndentry> entries = new arraylist<syndentry>();     syndentry entry = null;     syndcontent description = null;      entry = new syndentryimpl();     entry.settitle( "entry1" );     entry.setlink( "http://example.com/entry1" );     entry.setpublisheddate( new date() );      description = new syndcontentimpl();     description.settype("text/html");     description.setvalue( "this content of entry 1." );     entry.setdescription( description );      entries.add( entry );     feed.setentries(entries);      return feed; } 

and method of getting feed

@get @path("/getfeed") @produces(mediatype.application_xml) public syndfeed getfeed() {     rssfeed rssfeed = new rssfeed ();     return rssfeed.generate(); } 

i'm getting error incompatible type body writer. how make service return xml feed?

jersey not know how map instance of syndfeed xml. works.

@path("stackoverflow") public class romeressource {      @get     @path("/feed")     @produces("application/rss+xml")     public response getfeed() throws ioexception, feedexception {         final syndfeed feed = generate();          // write syndfeed writer.         final syndfeedoutput output = new syndfeedoutput();         final writer writer = new stringwriter();         output.output(feed, writer);          // return jax-rs response writer body.         return response.ok(writer.tostring()).build();     }      private syndfeed generate() {         final syndfeed feed = new syndfeedimpl();         feed.setfeedtype("rss_2.0");         feed.settitle("my site");         feed.setlink("http://example.com");         feed.setdescription("test site.");          final list<syndentry> entries = new arraylist<>();          final syndentry entry = new syndentryimpl();         entry.settitle("entry1");         entry.setlink("http://example.com/entry1");         entry.setpublisheddate(new date());          final syndcontent description = new syndcontentimpl();         description.settype("text/html");         description.setvalue("this content of entry 1.");          entry.setdescription(description);          entries.add(entry);          feed.setentries(entries);          return feed;     } } 

get resource:

$ curl -v http://localhost:8080/stackoverflowweb/webresources/stackoverflow/feed *   trying ::1... * connected localhost (::1) port 8080 (#0) > /stackoverflowweb/webresources/stackoverflow/feed http/1.1 > host: localhost:8080 > user-agent: curl/7.42.1 > accept: */* > < http/1.1 200 ok < server: glassfish server open source edition  4.1 < x-powered-by: servlet/3.1 jsp/2.3 (glassfish server open source edition  4.1  java/oracle corporation/1.8) < content-type: application/rss+xml < date: sun, 14 jun 2015 13:15:54 gmt < content-length: 565 < <?xml version="1.0" encoding="utf-8"?> <rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">   <channel>     <title>my site</title>     <link>http://example.com</link>     <description>test site.</description>     <item>       <title>entry1</title>       <link>http://example.com/entry1</link>       <description>this content of entry 1.</description>       <pubdate>sun, 14 jun 2015 13:15:54 gmt</pubdate>       <guid>http://example.com/entry1</guid>       <dc:date>2015-06-14t13:15:54z</dc:date>     </item>   </channel> </rss>  * connection #0 host localhost left intact 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -