Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Adding HTTP Response Header
Adding HTTP Response Header [message #728547] Fri, 23 September 2011 13:12 Go to next message
Franz-Stefan Mising name is currently offline Franz-Stefan Mising nameFriend
Messages: 12
Registered: December 2010
Junior Member
Hi, I would like to add some HTTP headers to the initial response that is sent by the servlet that renders my RAP application. In particular, I mean the servlet whose name is configured by the 'servletName' attribute of the org.eclipse.rap.ui.branding extension point.

I tried to call
RWT.getResponse().setHeader("xzy-header", "header-value");
before the 'Prepare UI Root' phase by registering a PhaseListener via the org.eclipse.rap.ui.phaselistener extension point.
However, my call comes too late: by then the servlet has already sent its response and the browser has received it accordingly (without the xzy-header).

Any idea on how to add the headers before the servlet sends its response?
Thank you!
Re: Adding HTTP Response Header [message #728585 is a reply to message #728547] Fri, 23 September 2011 13:42 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 335
Registered: July 2009
Senior Member
I am not quite sure which request you mean. However, for the very first
request (the one that delivers the index.html page) the request life
cycle isn't processed, hence no phase listeners are notified.

You can use servlet filters in order to manipulate any request that is
processed by the servlet.
If you are using server-side OSGi, this bug [1] and the
ExtendedHttpService JavaDoc might help you to register the filter.

HTH
Rüdiger

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=128068

On 23.09.2011 15:12, Franz-Stefan wrote:
> Hi, I would like to add some HTTP headers to the initial response that
> is sent by the servlet that renders my RAP application. In particular, I
> mean the servlet whose name is configured by the 'servletName' attribute
> of the org.eclipse.rap.ui.branding extension point.
>
> I tried to call
> RWT.getResponse().setHeader("xzy-header", "header-value"); before the
> 'Prepare UI Root' phase by registering a PhaseListener via the
> org.eclipse.rap.ui.phaselistener extension point.
> However, my call comes too late: by then the servlet has already sent
> its response and the browser has received it accordingly (without the
> xzy-header).
>
> Any idea on how to add the headers before the servlet sends its response?
> Thank you!

--
Rüdiger Herrmann

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Adding HTTP Response Header [message #728586 is a reply to message #728547] Fri, 23 September 2011 13:44 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 335
Registered: July 2009
Senior Member
Just out of curiosity, why do you need custom HTTP headers?

- Rüdiger

On 23.09.2011 15:12, Franz-Stefan wrote:
> Hi, I would like to add some HTTP headers to the initial response that
> is sent by the servlet that renders my RAP application. In particular, I
> mean the servlet whose name is configured by the 'servletName' attribute
> of the org.eclipse.rap.ui.branding extension point.
>
> I tried to call
> RWT.getResponse().setHeader("xzy-header", "header-value"); before the
> 'Prepare UI Root' phase by registering a PhaseListener via the
> org.eclipse.rap.ui.phaselistener extension point.
> However, my call comes too late: by then the servlet has already sent
> its response and the browser has received it accordingly (without the
> xzy-header).
>
> Any idea on how to add the headers before the servlet sends its response?
> Thank you!

--
Rüdiger Herrmann

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Adding HTTP Response Header [message #728673 is a reply to message #728586] Fri, 23 September 2011 16:14 Go to previous message
Franz-Stefan Mising name is currently offline Franz-Stefan Mising nameFriend
Messages: 12
Registered: December 2010
Junior Member
>> I am not quite sure which request you mean.
I mean the response that my browser receives for its HTTP request to
http://myhost.com:1234/myServletName?startup=myExtensionPoint
where "myServletName" is the one specified in the 'servletName' attribute of the org.eclipse.rap.ui.branding extension point.

>> You can use servlet filters in order to manipulate
>> any request that is processed by the servlet.
Great hint, thx! Now I solved my problem by using the org.eclipse.equinox.http.registry.filters extension point: I filter on the alias '/myServletName' and added the following code to the Filter#doFilter(ServletRequest, ServletResponse, FilterChain) method:
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setHeader("Xzy-header", "header-value");
chain.doFilter(request, response);

>> Just out of curiosity, why do you need custom HTTP headers?
For an internal demo application, we forward users from one web server to another web server. As such behavior is interpreted by state of the art browsers as cross site scripting attack violating the same origin policy, I needed to explicitly allow this behavior by using the 'Access-Control-Allow-Origin' header field.
Previous Topic:[GEF] "Drag-Job" on progress view
Next Topic:[ANN] RAP 1.4 SR1 is available
Goto Forum:
  


Current Time: Fri Apr 26 01:03:54 GMT 2024

Powered by FUDForum. Page generated in 0.03325 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top