I'm implementing a RESTful service using GAE Endpoints in Java. I'm trying to implement token-based authentication method and I wish to add a HTTP response header that contains the token string. However, I'm unable to find documentations on how to change the response header inside a @ApiMethod.
Anybody can shed some light on this? Any help very much appreciated.
From the looks of things, it isn't possible. There is another Stack Overflow Q&A on this question which answered the same way. You can make a Feature Request at the App Engine Public Issue Tracker, of course.
Note: Attempts to use javax.servlet.Filter
to intercept the ServletResponse
, cast it to an HttpServletResponse
and call .setHeader()
on it yielded no success, so it appears there are other layers which are intercepting the response and wrapping up one without any headers added which aren't "meant" to be there, according to Endpoints. I didn't experiment with subclassing SystemServiceServlet
, as the linked Q&A suggested, although that seems fraught with difficulties as well, and undocumented.
I've checked there is no way to change response header. More over @Nick has right that there is more layers - on the servlet container there is code which wraps response.
Some layers above - evidence is that error messages are packaged for endpoints. SystemServletService is putting into body this:
{
"error_message": "Some message"
}
Bu in practice response you get contains:
{
"error": {
"message": "Some messaged",
"code": 401,
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Some message"
}
]
}
}
For endpoints (SystemServiceServlet) only, for my custom servlets it's not. This is evidence that there is some layer above. ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With