how to commit or flush the rest response in the middle of process

leebell

New Member
I'm new to both java and jersey. Now I want to use the jersey to realize a REST services with extra processing after sending the response (specifically, sleep a fix amount of seconds and then fire a different REST request in the same servlet context, so it's unlike a REST proxy). I had googled for a while but all seems take it for granted that implicitly flushing the response at the end of method. Here are the current codes with JAXB enabled I'm struggling to work on.\[code\]@Path("/chat")public class LoadSimulator { @Context private UriInfo uriInfo; @Path("/outbound/{senderAddress}/requests") @POST @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response createOutboundSMSMessage(OutboundSMSMessageRequest inSmsReq, @PathParam("senderAddress") String senderAddress) throws JAXBException { String requestId = UUID.randomUUID().toString(); URI uri = uriInfo.getAbsolutePathBuilder().path(requestId).build(); ObjectFactory factory = new ObjectFactory(); ResourceReference resourceReference = new ResourceReference(); resourceReference.setResourceURL(uri.toString()); JAXBElement<ResourceReference> inSmsResponse = factory.createResourceReference(resourceReference); return Response.created(uri).entity(inSmsResponse).build(); //// want to flush or commit the response explicitly like: // out.flush(); // out.close(); //// Then sleep for a few second and fire a new REST request // sleep(5); // .... // ClientConfig config = new DefaultClientConfig(); // String response = r.path("translate").queryParams(params).get(String.class); }}\[/code\]
 
Top