1

I am trying to write a web application that uses REST webservices to handle post actions. The post pushes a message to the server then I need to start sending back periodic responses (occasional messages with a regular heartbeat message).

Please note I am fairly new to REST webservices so feel free to correct me if I'm barking up the wrong tree!

This is to interface with a system that I have no control over so I can't modify the HTTP POST.

e.g.

POST: Hello

Response: World
Response: Heartbeat
-- wait 60 secs --
Response: Heartbeat
-- wait 60 secs --
Response: Heartbeat
-- wait 60 secs --

My understanding is that this same mechanism is used for sending MJPEG video over HTTP.

I have found several examples of POST services consuming multipart form messages but nothing on how to response with multipart.

The stub code that I am starting from looks like this:

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.core.Context;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

--- ommitted code ---

@Context
private UriInfo context;

--- ommitted code ---

@POST
@Produces("multipart/mixed")
@Consumes(MediaType.TEXT_XML)
@Path("/{id}")
public Response doPost(String msg, @PathParam("id") String id) throws IOException
{
    // How do I do this as a multipart response?!
    return Response.status(Response.Status.OK).entity("").build();
}

Hopefully someone can help as I have found very little/nothing of use anywhere on the internet!

Ed Mackenzie
  • 679
  • 6
  • 16
  • This is technically possible, but IMO you are misusing HTTP which is a request-response protocol. My suggestion is to look into WebSockets or just plain TCP. – supertopi May 29 '14 at 11:51
  • 1
    I understand that it is not the conventional use of HTTP, but as I said in my post, I am not in control of the client side! You say it is technically possible... Are you able to point me in the right direction for HOW it's possible? – Ed Mackenzie May 29 '14 at 13:01
  • I was looking for a way to send a multipart document (see http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html). What you describe is just streaming. There are no "parts". Your question is already answered here: http://stackoverflow.com/questions/4831322/how-do-streaming-resources-fit-within-the-restful-paradigm – Claude Martin Jul 31 '15 at 07:51

0 Answers0