0

In Java, there is ThreadLocal, which can be used to carry some data from one object to another without explicit passing as method argument.

I need to intercept GWT request and extract custom HTTP header from it, then I need to store the header value somehow to be processed later.

The problem is that the place to extract the header belongs to RequestBuilder, and there is no way (?) to pass the variable from within RequestBuilder to the custom code actually handling the request/response from server. And it is not possible to pass some variable from client code to that request builder.

ThreadLocal could be the solution, however it is not available in GWT. Is there something I can use?

jdevelop
  • 12,176
  • 10
  • 56
  • 112

1 Answers1

0

You can use RequestBuilder.setHeader to set header values for your HTTP request.
On the backend you can use HttpServletRequest of your servlet to retrieve the header values from your HTTP request.

Update:

Some class with a static instance variable:

public class SomeClass {
    public static String myVar;
}

And in the RequestBuilder code you can do following:

RequestBuilder request = new RequestBuilder(url);
request.setCallback(new RequestCallback() {
    @Override
    public void onResponseReceived(Request request, Response response) {
        SomeClass.myVar = response.getHeader("someheader");
    }
});
Ümit
  • 17,379
  • 7
  • 55
  • 74
  • I need the ThreadLocal in GWT, having it being sent to server doesn't solve the problem – jdevelop May 30 '12 at 12:05
  • Can you post some code to make the question clearer. There are no threads in javascript code and thus there is no ThreadLocal in GWT. You can however use static instance variable to store values and then access it from somewhere else. – Ümit May 30 '12 at 12:10
  • I wanted to extract some header from HTTP response with RequestBuilder and put it into some variable, so the AsyncCallback (which will be executed by GWT code) will have access to the variable. – jdevelop May 30 '12 at 12:12