In order to set Custom Headers in GWT you need to get the RequestBuilder instance which will perform the request under the covers for you.
There are two ways to do this:
- Let your Async Interface return RequestBuilder instead of void
- You can provide an instance of RPCRequestBuilder to your service, which will construct the RequestBuilderInstance
Using option one has the disadvantages that you have to send your request manually, thus changing the DispachAsync interface would break a lot of current applications (and introduce a lot of redundant code). So I was looking for another options.
You can downcast your service to ServiceDefTarget and set an instance of RPCRequestBuilder like this:
service = GWT.create(Dispatch.class);
((ServiceDefTarget) service).setRpcRequestBuilder(this.authenticatingRequestBuilder);
With and RPCRequestBuilder looking like this:
public class ACustomRequestBuilder extends RpcRequestBuilder {
@Override
protected RequestBuilder doCreate(String serviceEntryPoint) {
RequestBuilder requestBuilder = super.doCreate(serviceEntryPoint);
requestBuilder.setHeader("your header", "your value");
return requestBuilder;
}
}
Now you can easily control all aspects of your request.
Thanks to Robert Muntenau this is now also in the gwt-dispatch docs: http://code.google.com/docreader/#p=gwt-dispatch&s=gwt-dispatch&t=RequestBuilder
Your work is very good and I appreciate you and hopping for some more informative posts. Thank you for sharing great information to us. Private Pflegeversicherung
ReplyDeletei love reading this article so beautiful!!great job! apartment kroatien
ReplyDeletesdsd
ReplyDeleteI needed acquired a windows check safeguard and in addition it broke every week afterwards as a result of my disregard contacted SOSav Ersatzteile iPhone and so they acquired questioned the actual way it give and shattered a i and snapshot also knowledgeable a new monitor protector within a few days cheers
ReplyDeleteGreat write-up, I am a big believer in commenting on blogs to inform the blog writers know that they’ve added something worthwhile to the world wide web!.. weblink
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI am very much pleased with the contents you have mentioned. I wanted to thank you for this great article. Our site
ReplyDeleteDanke für den schönen Bericht. In der Tat, es war ein unterhaltsamer Bericht. ich hoffe auf viele schöne Aggregate von Ihnen! Übrigens, wie könnten wir kommunizieren? Kaufen
ReplyDelete