1

I need to write a REST api which would send an XML file as response. I am confused with what MediaType should be defined as the response.

 @Produces(MediaType.APPLICATION_OCTET_STREAM)

or

 @Produces(MediaType.APPLICATION_XML)

The API will be served from a GET request and I want the file to be downloaded in the client side.

Mosam Mehta
  • 1,658
  • 6
  • 25
  • 34
DesirePRG
  • 6,122
  • 15
  • 69
  • 114
  • Possible duplicate of [Valid content-type for XML, HTML and XHTML documents](http://stackoverflow.com/questions/2965587/valid-content-type-for-xml-html-and-xhtml-documents) – Tim Oct 14 '15 at 09:55

2 Answers2

0

I will go with @Produces(MediaType.APPLICATION_XML), as the @Produces(MediaType.APPLICATION_OCTET_STREAM) is a constant for application/octet-stream which is usually used for binary type (such as video, music and stuff)

kucing_terbang
  • 4,991
  • 2
  • 22
  • 28
0

I suggest dont send file directly. read file at server end and send the file content as a response.

so it will look like

@GET
@Produce("application/xml")
    public Response sendData(){
      //code to read file and store in a string object

     return Response.built.ok(string object);
    }
Gaurav
  • 3,615
  • 2
  • 27
  • 50