users@jersey.java.net

Re: [Jersey] specify download location in response

From: alex hendry <al_hendry_at_yahoo.com.au>
Date: Tue, 7 Oct 2008 21:07:35 -0700 (PDT)

Thanks heaps Luke ----- Original Message ---- From: Luke Monahan <luke.monahan@remora.com.au> To: users@jersey.dev.java.net Sent: Wednesday, 8 October, 2008 1:36:21 PM Subject: Re: [Jersey] specify download location in response Hi Alex, You can add arbitrary headers with the header(String, Object) method on the response builder. return Response.ok(file).type("application/xml").header("Content-Disposition", "attachment; filename=ws_xml.xml").build(); Cheers, Luke. On Wednesday 08 October 2008 14:21:21 alex hendry wrote: > Hi all, > > I am fairly new to REST. I am in the process of building some web services > supplying XML as follows: > > > @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's best email. Get Yahoo!7 Mail! > http://au.yahoo.com/y7mail > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@jersey.dev.java.net > For additional commands, e-mail: users-help@jersey.dev.java.net --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@jersey.dev.java.net For additional commands, e-mail: users-help@jersey.dev.java.net Make the switch to the world&#39;s best email. Get Yahoo!7 Mail! http://au.yahoo.com/y7mail