This can be done with a custom Engine Service:

public class WriteToFile implements IEngineService {

private void toFile(HttpServletRequest request, HttpServletResponse response) {
  try {

    ServletOutputStream out = response.getOutputStream();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    //do stuff with the response here


   } catch (Exception e) {
    //Exception handling
   }

    public String getName() {
        return "writeToFile";
    }

    private HttpServletResponse response;

    public void setResponse (HttpServletResponse response) {
        this.response = response;
    }

    private HttpServletRequest request;

    public void setRequest (HttpServletRequest request) {
        this.request = request;
    }


    public void service(IRequestCycle arg0) throws IOException {

            toFile(request, response);

    }

    public ILink getLink(boolean arg0, Object arg1) {
        return null;
    }
}


Later in your hivemodule.xml:

<contribution configuration-id="tapestry.services.ApplicationServices">
 <service name="writeToFile" object="service:WriteToFile" />
</contribution>

<service-point id="WriteToFile" interface="org.apache.tapestry.engine.IEngineService">
 <invoke-factory model="singleton">
  <construct class="yourpackage.WriteToFile" />
 </invoke-factory>
</service-point>


The classic way to invoke your service will be using a ServiceLink, once you are done processing in your service you can redirect yourself throwing a page redirection exception anywhere in your app. Notice that the response and the request gets autowired by hivemind into your service, because both are services too. Which menas that you can pretty much inject any service using setter based injection using the service Interface as parameter

best regards.

Raul Raja.



Eric Schneider wrote:
Hi,

I recently remember someone asking about writing out a Tapestry
response to a file, tho I can't find that thread.

I'll looking to add some functions to a CMS app to flatten content to
our web server's doc root.

Can someone share an ideal way of doing this?

Thanks,
Eric

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to