Start handling window closing event for ckan logout

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@129765 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-07-01 13:36:20 +00:00
parent f78e01c1e4
commit 30231815de
7 changed files with 78 additions and 60 deletions

View File

@ -1,6 +1,6 @@
eclipse.preferences.version=1
jarsExcludedFromWebInfLib=
lastWarOutDir=/home/francesco-mangiacrapa/wseclipseluna/gcube-ckan-datacatalog-TRUNK-1.0.0-SNAPSHOT/target/gcube-ckan-datacatalog-1.0.0-SNAPSHOT
lastWarOutDir=/home/costantino/workspace/gcube-ckan-datacatalog/target/gcube-ckan-datacatalog-1.0.0-SNAPSHOT
launchConfigExternalUrlPrefix=
warSrcDir=src/main/webapp
warSrcDirIsOutput=false

View File

@ -19,19 +19,23 @@ import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowUserGr
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowUserGroupsEventHandler;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowUserOrganizationsEvent;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowUserOrganizationsEventHandler;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view.CKanLeaveFrame;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view.GCubeCkanDataCatalogPanel;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.CreateDatasetForm;
import com.github.gwtbootstrap.client.ui.Modal;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
@ -162,35 +166,10 @@ public class CkanEventHandlerManager {
@Override
public void onLogout(NotifyLogoutEvent editMetadataEvent) {
RequestBuilder logutRequestBuilder = new RequestBuilder(RequestBuilder.GET, GCubeCkanDataCatalog.CKAN_LOGUT_SERVICE);
logutRequestBuilder.setCallback(new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
}
@Override
public void onError(Request request, Throwable exception) {
}
});
try {
logutRequestBuilder.send();
} catch ( RequestException e ) {
Window.alert("Error on logout");
}
// open("https://ckan-d-d4s.d4science.org:443/ckan-connector/gcube/service/disconnect?gcube-token=4620e6d0-2313-4f48-9d54-eb3efd01a810", "_blank", null);
// String url = GWT.getHostPageBaseURL()+"CkanLogoutCatalog.html?logout=https://ckan-d-d4s.d4science.org:443/ckan-connector/gcube/service/disconnect?gcube-token=4620e6d0-2313-4f48-9d54-eb3efd01a810";
// Window.open(url, "_blank", null);
// logutWindow("https://ckan-d-d4s.d4science.org:443/ckan-connector/gcube/service/disconnect?gcube-token=4620e6d0-2313-4f48-9d54-eb3efd01a810", false);
// logutWindow("https://ckan-d-d4s.d4science.org:443/ckan-connector/gcube/service/disconnect?gcube-token=4620e6d0-2313-4f48-9d54-eb3efd01a810", true);
// com.google.gwt.user.client.Window.open(GCubeCkanDataCatalog.CKAN_LOGUT_SERVICE, "_blank", "");
// com.google.gwt.user.client.Window.open("https://ckan-d-d4s.d4science.org:443/ckan-connector/gcube/service/disconnect?gcube-token=4620e6d0-2313-4f48-9d54-eb3efd01a810", "_blank", "");
CKanLeaveFrame frame = new CKanLeaveFrame(GCubeCkanDataCatalog.CKAN_LOGUT_SERVICE);
DOM.appendChild(RootPanel.getBodyElement(), frame.getElement());
}
});

View File

@ -2,10 +2,12 @@
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.NotifyLogoutEvent;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view.CKanLeaveFrame;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view.GCubeCkanDataCatalogPanel;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.Window.ClosingEvent;
import com.google.gwt.user.client.ui.RootPanel;
@ -37,7 +39,10 @@ public class GCubeCkanDataCatalog implements EntryPoint {
@Override
public void onWindowClosing(ClosingEvent closingEvent) {
eventManager.getEventBus().fireEvent(new NotifyLogoutEvent());
// eventManager.getEventBus().fireEvent(new NotifyLogoutEvent());
GCubeCkanDataCatalogPanel.print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
CKanLeaveFrame frame = new CKanLeaveFrame(GCubeCkanDataCatalog.CKAN_LOGUT_SERVICE);
DOM.appendChild(RootPanel.getBodyElement(), frame.getElement());
}
});

View File

@ -0,0 +1,31 @@
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.SimplePanel;
/**
* This iframe handles the onLeave page event in order to call the logout servlet
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class CKanLeaveFrame extends SimplePanel{
private Frame frame;
public CKanLeaveFrame(String url){
try{
GCubeCkanDataCatalogPanel.print("Instancing new IFRAME with uri: "+ url);
frame = new Frame(url);
// make it smaller
frame.getElement().getStyle().setWidth(0, Unit.PX);
frame.getElement().getStyle().setHeight(1, Unit.PX);
}catch(Exception e){
GCubeCkanDataCatalogPanel.print("exception " + e);
}
}
}

View File

@ -10,11 +10,13 @@ import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.resource.CkanPor
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.Window.ClosingEvent;
import com.google.gwt.user.client.Window.ClosingHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.Image;
@ -136,7 +138,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate{
@Override
public void onFailure(Throwable caught) {
// the portlet is outside the portal and no user is logged in
// show only home and statistics
managementPanel.doNotUserRelatedInfo();
@ -157,9 +159,12 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate{
rootPanel.add(loading);
rootPanel.add(this);
updateSize();
}
public static native void print(String msg)/*-{
console.log(msg);
}-*/;
/**
* Gets the top panel height.
*

View File

@ -5,7 +5,6 @@ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
@ -65,9 +64,8 @@ public class CkanLogout extends HttpServlet {
ckan.addPathInfo(ckanConnectorLogut);
ckan.addGubeToken(ckanAP.getGcubeTokenValue());
URL url;
String deleteURI = ckan.buildURI();
// resp.sendRedirect(deleteURI);
// resp.sendRedirect(deleteURI);
CloseableHttpResponse httpResponse = null;
try {
@ -89,38 +87,38 @@ public class CkanLogout extends HttpServlet {
}
try {
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
resp.setHeader("Content-Length", String.valueOf(entity.getContentLength()));
// resp.setContentLength(entity.getContentLength());
Header encoding = entity.getContentEncoding();
logger.trace("Encoding: "+encoding.getName() + ", "+encoding.getValue());
// String encod = encoding == null ? GcubeCkanDataCatalogServiceImpl.UTF_8 : encoding.getName();
// resp.setCharacterEncoding(encoding);
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
resp.setHeader("Content-Length", String.valueOf(entity.getContentLength()));
// resp.setContentLength(entity.getContentLength());
Header encoding = entity.getContentEncoding();
logger.trace("Encoding: "+encoding.getName() + ", "+encoding.getValue());
// String encod = encoding == null ? GcubeCkanDataCatalogServiceImpl.UTF_8 : encoding.getName();
// resp.setCharacterEncoding(encoding);
resp.setStatus(HttpStatus.SC_OK);
resp.setContentType(resp.getContentType());
InputStream in = entity.getContent();
try {
ServletOutputStream out = resp.getOutputStream();
InputStream in = entity.getContent();
try {
ServletOutputStream out = resp.getOutputStream();
IOUtils.copy(in, out);
logger.info("Logout Completed, response code: "+HttpStatus.SC_OK);
} finally {
in.close();
}
}
} finally {
in.close();
}
}
}catch(Exception e){
logger.warn("An error occurred during copying CKAN logout response",e);
}
}else{
logger.warn("An error occurred during perfoming CKAN logout, Response status is: "+httpResponse.getStatusLine().getStatusCode());
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
InputStream in = entity.getContent();
if(in!=null){
logger.error("Response error: "+IOUtils.toString(in));
}
}
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
InputStream in = entity.getContent();
if(in!=null){
logger.error("Response error: "+IOUtils.toString(in));
}
}
}
}catch(Exception e){
logger.warn("An error occurred during perfoming CKAN logout", e);

View File

@ -238,7 +238,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
user = TEST_USER;
httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
ASLSession session = SessionManager.getInstance().getASLSession(sessionID, user);
//session.setScope(TEST_SCOPE);
session.setScope(TEST_SCOPE);
//session.setUserEmailAddress(TEST_MAIL);
return session;