users@jersey.java.net

specify download location in response

From: alex hendry <al_hendry_at_yahoo.com.au>
Date: Tue, 7 Oct 2008 19:57:24 -0700 (PDT)

Hi all, I am fairly new to REST. I am in the process of building some web services supplying XML. @GET @ProduceMime("application/*") public Response getXml(@PathParam("dataPeriod")String dataPeriod) { File file = null; if (dataPeriod.equalsIgnoreCase("latest")) { file = new File("latest.xml"); } else if (dataPeriod.equalsIgnoreCase("last2hrs")) { file = new File("last2hrs.xml"); } else if (dataPeriod.equalsIgnoreCase("last48hrs")) { file = new File("last48hrs.xml"); } FileOutputStream out = null; try { out = new FileOutputStream(file); } catch (FileNotFoundException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } // CREATE MY XML FILE HERE return Response.ok(file).type("application/xml").build(); } This works fine and produces my xml file that is displayed in my browser. However I would like to give the option of downloading the file to a user chosen location. In the past I have always used servlets and added to the header as follows: OutputStream sendResponse(final HttpServletResponse response) throws IOException { response.addHeader("Content-Disposition", "attachment; filename=ws_xml.xml"); response.setContentType("text/xml"); final OutputStream out = response.getOutputStream(); return out; } Can anyone suggest a way to do this. I have looked at Response and ResponseBuilder and searched the mail archives but can not see how to do this. Cheers, Alex Make the switch to the world&#39;s best email. Get Yahoo!7 Mail! http://au.yahoo.com/y7mail