How to get HTTP Response headers?

1,250 views
Skip to first unread message

ussuri

unread,
Sep 8, 2010, 8:45:01 PM9/8/10
to Google Web Toolkit
Hello!

I can't figure out how I can get HTTP Response header. In
com.google.gwt.http.client.RequestCallback.onResponseReceived() method
(a callback from RequestBuilder) there is a Response parameter that
has getHeder() and getHeaders() methods, but these always return empty
strings or nulls.

FireBug shows that the headers are there, but I can't get them in
GWT...

THanks,
MG

ussuri

unread,
Sep 9, 2010, 7:07:43 PM9/9/10
to Google Web Toolkit
Does the silence mean this is impossible? Or just very difficult?

MG

lineman78

unread,
Sep 9, 2010, 7:46:31 PM9/9/10
to Google Web Toolkit
Works fine for me:

@Override
public void onResponseReceived(Request request, Response
response)
{
String toPop = "";
for (Header header:response.getHeaders())
toPop += header.getName() + ": " +
header.getValue() + "\n";
Window.alert(toPop);
}

pops up:

X-Powered-By: Servlet/3.0
Server: GlassFish Server Open Source Edition 3.0.1
Content-Type: application/json
Transfer-Encoding: chunked
Date: Thu, 09 Sep 2010 23:46:05 GMT

ussuri

unread,
Sep 12, 2010, 9:10:26 PM9/12/10
to Google Web Toolkit
I am getting an exception inside GWT:

code:

@Override
public void onResponseReceived( Request request,
Response response)
{
String toPop = "";
Header[] headers = response.getHeaders();
....

Exception:

java.lang.NullPointerException: null
at com.google.gwt.http.client.Request.getHeaders(Request.java:88)
at com.google.gwt.http.client.Request.access$0(Request.java:86)
at com.google.gwt.http.client.Request$1.getHeaders(Request.java:
53)
at com.***$2.onResponseReceived(***.java:153)

GWT version is 2.0.4

What is interesting, is that although I am calling
response.getHeaders(), the stack trace shows that Request.getHeaders()
is called. The exception is there in the compiled code as well. What
can be the cause? A broken GWT installation?

Thomas Broyer

unread,
Sep 13, 2010, 8:29:17 AM9/13/10
to Google Web Toolkit

On Sep 13, 3:10 am, ussuri <michael.glas...@gmail.com> wrote:
> I am getting an exception inside GWT:
>
> code:
>
> @Override
> public void onResponseReceived( Request request,
>                         Response response)
>  {
>         String toPop = "";
>         Header[] headers = response.getHeaders();
>         ....
>
> Exception:
>
> java.lang.NullPointerException: null
>     at com.google.gwt.http.client.Request.getHeaders(Request.java:88)
>     at com.google.gwt.http.client.Request.access$0(Request.java:86)
>     at com.google.gwt.http.client.Request$1.getHeaders(Request.java:
> 53)
>     at com.***$2.onResponseReceived(***.java:153)
>
> GWT version is 2.0.4
>
> What is interesting, is that although I am calling
> response.getHeaders(), the stack trace shows that Request.getHeaders()
> is called.

The stack-trace, shows that the Response object you've been passed is
an anonymous inner-class of Request (Request$1), whose getHeaders
method delegate to a method on the Request class (have a look at the
code the details)

> The exception is there in the compiled code as well. What
> can be the cause? A broken GWT installation?

Have you checked the status code? It appears (from the line number
given in the stack trace) that the XMLHttpRequest's
getAllResponseHeaders returned 'null', so I suspect some kind of error
(that wouldn't be flagged as an error by GWT, so there may be a bug
here; but maybe there's some kind of "bug" in your code too)
Can't you inspect the request in some devtool such as Firebug?
Reply all
Reply to author
Forward
0 new messages