Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting response header with JAX-RS does not work. #739

Closed
MarkKharitonov opened this issue Mar 8, 2013 · 4 comments
Closed

Setting response header with JAX-RS does not work. #739

MarkKharitonov opened this issue Mar 8, 2013 · 4 comments
Assignees

Comments

@MarkKharitonov
Copy link

Hello.
The bug is already described here - http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2725278

In short, it is impossible to set a response header in the current implementation of JAX-RS - the headers are simply ignored.

@thboileau
Copy link
Contributor

Hello Mark,

I notice that the fix consist in providing extra headers using a specific attribute of the jax-rs response builder.

    @GET
    @Produces("text/html")
    public Response getHtml() {
        Series<Header> xheaders = new Series<Header>(Header.class);
        xheaders.add("x-my-header", "myvalue");
        ResponseBuilder builder = Response
                .ok("<html><head></head><body>\nThis is a resource (as html text).\n</body></html>");
        builder.header(HeaderConstants.ATTRIBUTE_HEADERS, xheaders);
        return builder.build();
    }

I guess this is not your preferred way to add headers. You would like to use the JAX-RS API :

    @GET
    @Produces("text/html")
    public Response getHtml() {
        return Response
                .ok("<html><head></head><body>\nThis is a resource (as html text).\n</body></html>")
                .header("x-my-header", "myvalue").build();
    }

Am I wrong?

Best regards,
Thierry Boileau

@MarkKharitonov
Copy link
Author

You are absolutely correct. I expect it to work the JAX-RS way.

@ghost ghost assigned thboileau Mar 14, 2013
thboileau pushed a commit that referenced this issue Mar 14, 2013
thboileau pushed a commit that referenced this issue Mar 14, 2013
@thboileau
Copy link
Contributor

Hello Mark,
I've fixed this issue in the git repository (2.2 and 2.1). The fix will be part of next 2.2m4, 2.2 snapshot and 2.1.3 releases.
As a workaround, you can use the response's attribute (builder.header(HeaderConstants.ATTRIBUTE_HEADERS, xheaders);).

Best regards,
Thierry Boileau

@MarkKharitonov
Copy link
Author

Excellent. Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants