Jersey: adding headers to a server response

java, jax-rs, jersey

Solution

You can return a `Response` object instead. Have a look at: https://jersey.java.net/nonav/documentation/latest/user-guide.html#d0e5169 and http://jersey.java.net/nonav/apidocs/1.17/jersey/javax/ws/rs/core/Response.ResponseBuilder.html

These should get you on the right track...

Problem

I'm using Jersey, I have the following method: ``` @POST @Path("hello") @Produces(MediaType.TEXT_HTML) public String hello(@FormParam("username") String username) { Gson gson = new Gson(); CommunicationResponseM result = new CommunicationResponseM(); String result = "hello"; return gson.toJson(result); } ``` So far all goes well, but now I need to add some headers. How can I do that? Thanks! PS: I start the Jersey server in this way: ``` final HttpServer server = HttpServerFactory.create(baseUrl); server.start(); ```

Original source