Skip to main content

Inserting Content-Length HTTP Header in Response

1 reply [Last post]
eojm4ever
Offline
Joined: 2008-11-25
Points: 0

Hi all,

I'm working with a legacy system, connecting to a Restful Web Service.
The legacy system requires that the response from the service contain the Content-Length HTTP Header. The legacy system only uses the GET method.

Does anyone have advice on how I could accomplish the injecting of the HTTP Header?
I am unable to edit the legacy code.

I am using Jersey 0.8 and Glassfish V2.

Thanks
Eugene

Message was edited by: eojm4ever

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
eojm4ever
Offline
Joined: 2008-11-25
Points: 0

Hi all,

I solved it all on my lonesome.
My Solution:
Made the GET method return a javax.ws.rs.core.Response,
@GET
@Path ( ..... )
@ConsumeMime ( ...... )
@ProduceMime ( "application/xml" )
public Response getXml ( @PathParam(...).... ) {
//make Response object
ResponseBuilder rb = Response.created ( context.getRequestUri () );
//some code
if ( obj.isGood () ) {
rb.status ( Response.Status.OK );
} else {
rb.status ( Response.Status.BAD_REQUEST );
}
rb.entity ( obj.getTheResponse () );
rb.header ( "Content-Length", obj.size () );
return rb.build ();
}

This works for me.
Can anybody tell me my approach is correct.
hope this helps someone else.

Thanks
Eugene