From e74a74eb4f51de8dd6865cd9847285afa06b9315 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Tue, 2 Jul 2013 08:30:40 +0000 Subject: [PATCH] fixed url shortener request git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@77452 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../server/GWTWorkspaceServiceImpl.java | 2 +- .../HttpCallerUtil.java | 2 +- .../UrlEncoderUtil.java | 2 +- .../{shortner => shortener}/UrlShortener.java | 33 ++++++++++++++----- .../user/workspace/server/util/WsUtil.java | 2 +- 5 files changed, 29 insertions(+), 12 deletions(-) rename src/main/java/org/gcube/portlets/user/workspace/server/{shortner => shortener}/HttpCallerUtil.java (98%) rename src/main/java/org/gcube/portlets/user/workspace/server/{shortner => shortener}/UrlEncoderUtil.java (96%) rename src/main/java/org/gcube/portlets/user/workspace/server/{shortner => shortener}/UrlShortener.java (85%) diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java index 3f08e29..5daafb4 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java @@ -50,7 +50,7 @@ import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService; import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem; import org.gcube.portlets.user.workspace.server.notifications.NotificationsProducer; import org.gcube.portlets.user.workspace.server.notifications.NotificationsUtil; -import org.gcube.portlets.user.workspace.server.shortner.UrlShortener; +import org.gcube.portlets.user.workspace.server.shortener.UrlShortener; import org.gcube.portlets.user.workspace.server.util.UserUtil; import org.gcube.portlets.user.workspace.server.util.WsUtil; import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter; diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/shortner/HttpCallerUtil.java b/src/main/java/org/gcube/portlets/user/workspace/server/shortener/HttpCallerUtil.java similarity index 98% rename from src/main/java/org/gcube/portlets/user/workspace/server/shortner/HttpCallerUtil.java rename to src/main/java/org/gcube/portlets/user/workspace/server/shortener/HttpCallerUtil.java index d27d3bf..cb3da02 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/shortner/HttpCallerUtil.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/shortener/HttpCallerUtil.java @@ -1,7 +1,7 @@ /** * */ -package org.gcube.portlets.user.workspace.server.shortner; +package org.gcube.portlets.user.workspace.server.shortener; import java.io.IOException; import java.util.Map; diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/shortner/UrlEncoderUtil.java b/src/main/java/org/gcube/portlets/user/workspace/server/shortener/UrlEncoderUtil.java similarity index 96% rename from src/main/java/org/gcube/portlets/user/workspace/server/shortner/UrlEncoderUtil.java rename to src/main/java/org/gcube/portlets/user/workspace/server/shortener/UrlEncoderUtil.java index 80f7af0..c9a0ff8 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/shortner/UrlEncoderUtil.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/shortener/UrlEncoderUtil.java @@ -1,7 +1,7 @@ /** * */ -package org.gcube.portlets.user.workspace.server.shortner; +package org.gcube.portlets.user.workspace.server.shortener; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/shortner/UrlShortener.java b/src/main/java/org/gcube/portlets/user/workspace/server/shortener/UrlShortener.java similarity index 85% rename from src/main/java/org/gcube/portlets/user/workspace/server/shortner/UrlShortener.java rename to src/main/java/org/gcube/portlets/user/workspace/server/shortener/UrlShortener.java index 1c0f497..fee11b4 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/shortner/UrlShortener.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/shortener/UrlShortener.java @@ -1,7 +1,7 @@ /** * */ -package org.gcube.portlets.user.workspace.server.shortner; +package org.gcube.portlets.user.workspace.server.shortener; /** * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it @@ -89,10 +89,22 @@ public final class UrlShortener { paramKeyValue = endpoints.get(0).propertyMap()!=null?endpoints.get(0).propertyMap().get(KEY).value():""; } - uriRequest = shortnerServerUrl+"?"+KEY+"="+paramKeyValue; + String getParam = ""; + + //ACTIVE THIS AFTER RELEASE + if(paramKeyValue!=null && !paramKeyValue.isEmpty()){ +// getParam = "?"+KEY +"="+paramKeyValue; + getParam = "?"+KEY +"=AIzaSyDfMO0VY3o8GjRUqnTfqScjm_EsFEuBa3g"; + + } + + uriRequest = shortnerServerUrl+getParam; logger.trace("HTTP-URL-Shortener found, uriRequest: "+uriRequest); + //DEBUG + System.out.println("HTTP-URL-Shortener found, uriRequest: "+uriRequest); + isAvailable = true; }catch (Exception e) { @@ -119,8 +131,10 @@ public final class UrlShortener { try { - URL url = new URL(shortnerServerUrl); - + logger.trace("shorten longUrl: "+longUrl); + + URL url = new URL(uriRequest); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); @@ -130,9 +144,12 @@ public final class UrlShortener { jsonObj.put(LONG_URL, longUrl); - //ACTIVE THIS AFTER RELEASE - if(paramKeyValue!=null && !paramKeyValue.isEmpty()) - jsonObj.put(KEY, paramKeyValue); +// //ACTIVE THIS AFTER RELEASE +// if(paramKeyValue!=null && !paramKeyValue.isEmpty()){ +// jsonObj.put(KEY, paramKeyValue); +// } + + logger.trace("request json : "+jsonObj.toJSONString()); OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream()); wr.write(jsonObj.toJSONString()); @@ -185,7 +202,7 @@ public final class UrlShortener { UrlShortener urlSh = new UrlShortener(); System.out.println("UrlShortener: "+urlSh); - shorten = urlSh.shorten("https://dev.d4science.org/group/data-e-infrastructure-gateway/workspace?itemid=062c558c-c7ce-4de3-a4c7-e1411816cc12&operation=gotofolder"); + shorten = urlSh.shorten("https://dev.d4science.org/group/data-e-infrastructure-gateway/workspace?itemid=056648-c7ce-4de3-a4c7-e1411816cc12&operation=gotofolder"); System.out.println("Shorted: "+shorten); } catch (Exception e) { diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/util/WsUtil.java b/src/main/java/org/gcube/portlets/user/workspace/server/util/WsUtil.java index 98e781f..db0dc6a 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/util/WsUtil.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/util/WsUtil.java @@ -20,7 +20,7 @@ import org.gcube.portlets.user.homelibrary.home.workspace.Workspace; import org.gcube.portlets.user.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException; import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder; import org.gcube.portlets.user.workspace.server.notifications.NotificationsProducer; -import org.gcube.portlets.user.workspace.server.shortner.UrlShortener; +import org.gcube.portlets.user.workspace.server.shortener.UrlShortener; import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter;