Added ckan logut read response
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@129467 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d04b8adc20
commit
01da3f0a93
|
@ -3,10 +3,12 @@ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server;
|
|||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
|
@ -34,6 +36,7 @@ import org.slf4j.LoggerFactory;
|
|||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
|
||||
import eu.trentorise.opendata.jackan.internal.org.apache.http.HttpStatus;
|
||||
import eu.trentorise.opendata.traceprov.internal.org.apache.commons.io.IOUtils;
|
||||
/**
|
||||
* The server side implementation of the RPC service.
|
||||
*
|
||||
|
@ -407,7 +410,16 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
httpCon.connect();
|
||||
|
||||
if(httpCon.getResponseCode()==HttpStatus.SC_OK){
|
||||
logger.debug("Logout Completed, response code: "+HttpStatus.SC_OK);
|
||||
Map<String, List<String>> map = httpCon.getHeaderFields();
|
||||
for (String key : map.keySet()) {
|
||||
logger.trace("key: "+key +", value: "+map.get(key));
|
||||
}
|
||||
InputStream in = httpCon.getInputStream();
|
||||
String encoding = httpCon.getContentEncoding();
|
||||
encoding = encoding == null ? "UTF-8" : encoding;
|
||||
String body = IOUtils.toString(in, encoding);
|
||||
logger.debug("response: "+body);
|
||||
logger.info("Logout Completed, response code: "+HttpStatus.SC_OK);
|
||||
}else{
|
||||
logger.warn("An error occurred during perfoming CKAN logout, Response status is: "+httpCon.getResponseCode());
|
||||
}
|
||||
|
@ -417,4 +429,39 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
URL url;
|
||||
try {
|
||||
String deleteURI = "https://ckan-d-d4s.d4science.org:443/ckan-connector/gcube/service/disconnect?gcube-token=4620e6d0-2313-4f48-9d54-eb3efd01a810";
|
||||
logger.debug("Perfoming HTTP delete to URI: "+deleteURI);
|
||||
url = new URL(deleteURI);
|
||||
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
|
||||
httpCon.setDoOutput(true);
|
||||
httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded" );
|
||||
httpCon.setRequestMethod("DELETE");
|
||||
httpCon.connect();
|
||||
|
||||
if(httpCon.getResponseCode()==HttpStatus.SC_OK){
|
||||
Map<String, List<String>> map = httpCon.getHeaderFields();
|
||||
for (String key : map.keySet()) {
|
||||
logger.trace("key: "+key +", value: "+map.get(key));
|
||||
}
|
||||
InputStream in = httpCon.getInputStream();
|
||||
String encoding = httpCon.getContentEncoding();
|
||||
encoding = encoding == null ? "UTF-8" : encoding;
|
||||
String body = IOUtils.toString(in, encoding);
|
||||
logger.debug("response: "+body);
|
||||
logger.info("Logout Completed, response code: "+HttpStatus.SC_OK);
|
||||
}else{
|
||||
logger.warn("An error occurred during perfoming CKAN logout, Response status is: "+httpCon.getResponseCode());
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
logger.error("An error occured during performing Logout from CKAN", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue