Forum Moderators: open

Message Too Old, No Replies

RSS with java/tomcat/mysql help!

Have RSS running needs tweeking and more...

         

BobOConnor

3:52 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



I am maintaining a site that uses java/tomcat/mysql and
want to do RSS feeds for BLOGS and more.

I have written two files that accomplish what i want:
(converted all tags to parenthesis so you can see 'em)
The main .htm file: www.example.com/blogfeed.htm

(c:set var="noShowFooterHTML" value="true" scope="request" /)
(rss version="0.91")
(channel)
(title)Powerful Intentions - Powerful Blogs(/title)
(link)http://www.example.com(/link)
(description)List of the Newest BLOG entries.(/description)

(app:blogfeed/)

(/channel)
(/rss)

The app: blogfeed is this tag file:

(%@ include file="/taglibs.inc" %)
(sql:query var="q")
SELECT s.userName,s.subscriberTypeCode,s.name,b.pKey,b.title
FROM Subscriber s, Blog b
WHERE s.pKey = b.memberKey
AND b.blogTypeCode = 'B'
AND b.publishFlag = 'Y'
ORDER BY b.createTimestamp DESC
LIMIT 9
(/sql:query)
(c:set var="hotBlogs" value="(%= new java.util.LinkedHashMap() %)"/)
(c:forEach var="r" items="${q.rows}" varStatus="i")
(c:set target="${hotBlogs}" property="${i.index}" value="${r}"/)
(/c:forEach)
(c:set target="${hotstuff}" property="BLOGS" value="${hotBlogs}"/)
(c:forEach var="r" items="${hotstuff['BLOGS']}" varStatus="i")
(item)
(title)${r.value.name} - ${r.value.title}(/title)
(link)http://${r.value.userName}.${qp:getApplicationBase(pageContext)}
/blog/article/${r.value.pKey}/?comments=Y(/link)
(description)${r.value.title}(/description)
(/item)
(/c:forEach)

OK so my questions:

This file works because the extension is .htm
I can more "properly" also use .xml as the extension
but then the app:blogfeed
is NOT called and just shows up statically.

***SO does anyone know the innards enough or have other
suggestions how to create a dynamic .xml file?

Otherwise I'm stuck with the .htm
Part of why I ask is that this shows up
fine with BlogLines but the new www.google.com/ig
home page will not accept the link as is and
says under "Create a Section"

Your search www.example.com/blogfeed.htm
did not match any feeds.

ALSO if you look at the source for the above link
or any page on the site for that matter there is a
***HUGE*** amount of whitespace at the top of the source...
around 500 blank lines!
Does anyone know how to eliminate these unnecessary blanks?

OR if you have a totally different approach that would
be useful... I am concerned about too much traffic
to these feeds and an alternative to all those
hits and trips to the database may be
automatically creating static files with
a process that uses a cron job that might run every
2 hours or so.

My first post here and Thanks in advance.
Bob OConnor

[edited by: jatar_k at 5:34 pm (utc) on Aug. 17, 2005]
[edit reason] no sigs, no urls thanks [/edit]

irnbru

4:29 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



When you use the .xml extension I would expect the whole page to be renedered static not just app:blogfeed bit.

At a guess ....

Your container is set to recognise htm as jsp and compile it. Thats why changing to .xml won't work.

I've no idea what BlogLines is but goto [feedvalidator.org...] and check the ouptut.

My guess for the blank lines is that its down to the JSP compiler.

Do you have any control over Tomcat?

I'd probably recommend writing a servlet and controlling the output directly from there rather than JSP.

BobOConnor

5:17 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



Thanks irnbru,

> When you use the .xml extension I would expect the whole page to be renedered static
> Your container is set to recognise htm as jsp and compile it. Thats why changing to .xml won't work.

Ok

> I've no idea what BlogLines is

just another RSS reader.

>goto [feedvalidator.org...] and check the ouptut.

Great and I did get this error:

"Feeds should not be served with the "text/html;charset=ISO-8859-1" media type
RSS feeds should be served as application/rss+xml"

Where do I set this as a media type... can I put it at the top
of the .htm file and have it override the text/html?
This may explain the google/ig problem.

> My guess for the blank lines is that its down to the JSP compiler.
> Do you have any control over Tomcat?

Sure, I have root access but I am not familiar with Tomcat (I took this
over even though my experience is NOT with java/tomcat etc.)

Easy suggestions here?

> I'd probably recommend writing a servlet and controlling the output
> directly from there rather than JSP.

Can you or others give me some samples and or references for writing
a servlet?

AND thanks!
-Bob OConnor

irnbru

6:01 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



For the mime type you need something like

<%@ page contentType="text/xml"%>

as the first line.

For the white spaces .... hmmmm .... which version of Tomcat? One of them's supposed to have a feature to do this.

BobOConnor

1:56 am on Aug 18, 2005 (gmt 0)

10+ Year Member



> For the mime type you need something like
> <%@ page contentType="text/xml"%>

Yes, that did it... Thanks!

> For the white spaces .... hmmmm ....
> which version of Tomcat? One of them's supposed
> to have a feature to do this.

jakarta-tomcat-5.0.28

-AHO Bob O

irnbru

11:49 am on Aug 18, 2005 (gmt 0)

10+ Year Member



You have to do something like the following in $CATALINA_BASE/conf/web.xml

Add


<init-param>
<param-name>trimSpaces</param-name>
<param-value>true</param-value>
</init-param>

to the jsp servlet


<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>

.......

</servlet>