My GWT frontend is on port 8888. REST backend is on 8080. By default cookies not work. Seems that cookies should be passed if I will call RequestBuilder.setIncludeCredentials() for the request. In this case I need to replace DefaultRequestBuilderFactory with my own implementation because I need to send cookies to server.
SecuredRequestBuilderFactory.java:
public class SecuredRequestBuilderFactory extends DefaultRequestBuilderFactory {
public SecuredRequestBuilderFactory(HttpRequestBuilderFactory httpRequestBuilderFactory, BodyFactory bodyFactory, HeaderFactory headerFactory, UriFactory uriFactory, @RequestTimeout Integer requestTimeoutMs) {
super(httpRequestBuilderFactory, bodyFactory, headerFactory, uriFactory, requestTimeoutMs);
}
@Override
public <A extends RestAction<?>> RequestBuilder build(A action, String securityToken) throws ActionException {
RequestBuilder builder = super.build(action, securityToken);
builder.setIncludeCredentials(true);
return builder;
}
}
I have added to my gwt.xml:
<replace-with class="com.example.rest.SecuredRequestBuilderFactory">
<any>
<when-type-is class="com.gwtplatform.dispatch.rest.client.core.RequestBuilderFactory"/>
<when-type-is class="com.gwtplatform.dispatch.rest.client.core.DefaultRequestBuilderFactory"/>
</any>
</replace-with>
I have discovered from debugger (Chrome with IDEA plugin) that there is no mapping for class SecuredRequestBuilderFactory and credentials was not included.
So, any ideas how to make it work?
I found solution to pass all cookies with REST request:
SecuredRequestBuilderFactory.java:
MyRestDispatchModule.java: