2 Replies Latest reply on Apr 29, 2009 5:34 AM by pgmjsd

    Emitting XML

      Is it possible to emit XML from a Seam application? We are using the Google Search Appliance and we would like to use a bean in our existing Seam application as an external provider for one of our GSA One Module's. Normally, we would write a servlet and create the XML in the doGet method. But I would like to use Seam, if possible, without having to write another servlet, since the EJB we need to access is in the EAR that makes up our Seam application.

        • 1. Re: Emitting XML
          Here's the way I ended up doing it - in case anybody's interested:

          FacesContext context = FacesContext.getCurrentInstance();
                          HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
                          String query = request.getParameter("query");
                          HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
                          response.setContentType("text/xml");   
                         
                          Document xmlout = new Document(new Element("OneBoxResults"));
             //  more JDOM code here...then...
                          try {
                                  PrintWriter out = response.getWriter();
                                  XMLOutputter outputter = new XMLOutputter();
                                  out.print(outputter.outputString(xmlout));
                                  out.flush();
                                  out.close();
                                  context.responseComplete();
                          } catch (IOException e) {
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
                          }

          and in pages.xml:

          <page view-id="/gsa.xhtml">
                  <action execute="#{groupsGSAHandler.gsaSearch()}"/>              
          </page>

          Note that the view-id "/gsa.xhtml" is only a place holder; there is no such file.
          • 2. Re: Emitting XML
            pgmjsd

            Have you tried using the contentType attribute of the f:view tag?


            <f:view xmlns:f="http://java.sun.com/jsf/core"
                    contentType="text/xml">
            blah blah... xml with EL markup
            </f:view>



            That would set the content type for you.   We use this to make JNLP files for Java Web Start, among other things.