gwt-dispatch and HTTP Basic Authentification

160 views
Skip to first unread message

Daniel Kurka

unread,
May 2, 2011, 2:23:15 PM5/2/11
to GWT Dispatch
I`m trying to use gwt-dispatch with HTTP Basic Authentification.
Therefore have the need that the DispatchServiceAsync Interface needs
to return RequestBuilder instead of void, so that i can manipulate the
header to include the basic auth and send the request myself.

The problem is if you choose to return RequestBuilder instead of void
you have to manually send the request. Thus just changing that would
break all current gwt-dispatch apps.

Maybe its possible to include a second method on DispatchServiceAsync,
something like that:

public RequestBuilder executeWithRequestBuilder(Action<?> action,
AsyncCallback<Result> callback);


What could be a good way to solve this?

- Daniel

David Peterson

unread,
May 2, 2011, 11:34:53 PM5/2/11
to gwt-di...@googlegroups.com
I guess one way would be to add a method that allows you to provide a Map<String, String> with any custom header values you want to send.

The other thing is, why not just create a custom implementation of the DispatchService that handles the header settings, rather than putting it into the Async API. Have the service handle it behind the scenes...

David

Daniel Kurka

unread,
May 3, 2011, 2:15:27 AM5/3/11
to GWT Dispatch
Tanks for the quick reply and the suggestions, but, I found a much
easier way to achieve what i want:

You can set the RPCRequestBuilder if you downcast the constructed
service:

service = GWT.create(Dispatch.class);
((ServiceDefTarget)
service).setRpcRequestBuilder(this.authenticatingRequestBuilder);

With and RPCRequestBuilder looking like this:

public class AuthenticatingRequestBuilder extends RpcRequestBuilder {

private final LoginProvider loginProvider;

@Inject
public AuthenticatingRequestBuilder(LoginProvider loginProvider) {
this.loginProvider = loginProvider;

}

@Override
protected RequestBuilder doCreate(String serviceEntryPoint) {
RequestBuilder requestBuilder = super.doCreate(serviceEntryPoint);
UserLogin userLogin = loginProvider.get();
if (userLogin != null) {
requestBuilder.setHeader("X-GWT-CRED", userLogin.getCredentials());
}
return requestBuilder;
}
}


- Daniel Kurka


On 3 Mai, 05:34, David Peterson <da...@randombits.org> wrote:
> I guess one way would be to add a method that allows you to provide a
> Map<String, String> with any custom header values you want to send.
>
> The other thing is, why not just create a custom implementation of the
> DispatchService that handles the header settings, rather than putting it
> into the Async API. Have the service handle it behind the scenes...
>
> David
>

Robert Munteanu

unread,
May 3, 2011, 3:31:48 AM5/3/11
to gwt-di...@googlegroups.com
On Tue, May 3, 2011 at 9:15 AM, Daniel Kurka
<kurka....@googlemail.com> wrote:
> Tanks for the quick reply and the suggestions, but, I found a much
> easier way to achieve what i want:


Thanks for following up.

I've added this information to our user guide at
http://code.google.com/docreader/#p=gwt-dispatch&s=gwt-dispatch&t=RequestBuilder
.

Robert

--
Sent from my (old) computer

Reply all
Reply to author
Forward
0 new messages