added request builder injection

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/client-context-library@134693 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-11-24 15:55:47 +00:00
parent cf4456a0cd
commit 0689fc24b0
1 changed files with 21 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package org.gcube.portal.clientcontext.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.http.client.RequestBuilder;
/**
*
@ -9,6 +10,7 @@ import com.google.gwt.core.client.EntryPoint;
*/
public class GCubeClientContext implements EntryPoint {
public static final String VRE_ID_ATTR_NAME = "gcube-vreid";
public static final String USER_ID_ATTR_NAME = "gcube-userId";
public void onModuleLoad() {}
@ -21,4 +23,22 @@ public class GCubeClientContext implements EntryPoint {
return groupId;
}-*/;
public static native String getCurrentUserId() /*-{
var userId;
if ($wnd.Liferay != null) {
userId = $wnd.Liferay.ThemeDisplay.getUserId();
console.log("current userid is = " + userId);
}
return userId;
}-*/;
/**
* to be used in standard servlets requests before the actual request
* @param request
* @return
*/
public static RequestBuilder injectContext(RequestBuilder request) {
request.setHeader(VRE_ID_ATTR_NAME, getCurrentContextId());
request.setHeader(USER_ID_ATTR_NAME, getCurrentUserId());
return request;
};
}