I have a unique scenario where I’m using a servlet to dynamically output to the browser with calls to a database. The content type is RSS-XML so that it can update an RSS feed xml from the database. This is working fine. However, I also have a an EJB that is accessable as a webservice @WebService. So that all of it’s public methods are accessible via SOAP transactions. I have successfully implemented this as well. So that I am updating the database through Java-WS/SOAP, my problem is that I am not simultaneously updating the doGet() of the servlet which means it’s not updating the Servlet call–even though the Database is successfully updated.
How do I force a doGet() call to my servlet from an EJB? The only way those HTML/XML tags will be updated is if the Servlet is called and therefore the doGet() method.
Thank you.
EDIT for clarity: My Servlet currently is accessed from a jsp page as a URL. It’s referenced as a link that people can click on. It updates fine once people click on it but since it is an RSS feed I would also like to be able to call/update the feed when I add data to the database. So far I can add data but the feed is not being updated because I don’t know how to call the doGet() in my business logic.
This is what the pertinent part of my servlet looks like:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Statuses = rssbean.arrayUpdates();
XMLOutputFactory factory = XMLOutputFactory.newInstance();
try {
XMLStreamWriter writer = factory.createXMLStreamWriter(response.getOutputStream());
response.setContentType("application/rss+xml; charset=UTF-8");
writer.writeStartDocument();
writer.writeStartElement("rss");
writer.writeAttribute("version", "2.0");
writer.writeStartElement("channel");
for(int i = 0; i < (Statuses.length); i++){
writer.writeStartElement("item");
writer.writeStartElement("title");
writer.writeCharacters(Statuses[i]);
writer.writeEndElement();
writer.writeStartElement("link");
writer.writeCharacters("http://www.link.com");
writer.writeEndElement();
writer.writeStartElement("description");
writer.writeEndElement();
writer.writeEndElement();
As you can see I’m creating this .rss file on the fly through doGet(). This works fine when you link to it but I’m not sure how to run these writer calls from my EJB (not the browser).
Your rssBean.arrayUpdates() need to query the database and return the result each time. If it is returning some pre-existing data, then that wont work.
Once you click on a link and access a servlet, the servlet pulls the information from the database and gives the result to the client.
When you update your data through the web service, there is no need to make a call to the servlet to make sure it is updated, as you seem to expect to do.
HTTP is request / response. Once a response has been given to the client, then they would have to refresh the page or click on the link to refresh the content.
see also HTTP headers for cache control http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html