diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/shortener/UrlShortener.java b/src/main/java/org/gcube/portlets/user/workspace/server/shortener/UrlShortener.java index fb83e08..c42cfe9 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/shortener/UrlShortener.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/shortener/UrlShortener.java @@ -27,8 +27,10 @@ import org.gcube.common.scope.api.ScopeProvider; import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter; import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.queries.impl.XQuery; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; +import org.json.JSONObject; +import org.json.JSONTokener; + + public final class UrlShortener { @@ -142,7 +144,6 @@ public final class UrlShortener { connection.setRequestProperty("Content-Type", APPLICATION_JSON); JSONObject jsonObj = new JSONObject(); - jsonObj.put(LONG_URL, longUrl); // //ACTIVE THIS AFTER RELEASE @@ -150,16 +151,19 @@ public final class UrlShortener { // jsonObj.put(KEY, paramKeyValue); // } - logger.trace("request json : "+jsonObj.toJSONString()); + logger.trace("request json : "+jsonObj.toString()); OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream()); - wr.write(jsonObj.toJSONString()); + wr.write(jsonObj.toString()); wr.flush(); BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); - JSONParser parser = new JSONParser(); - JSONObject jsonObject = (JSONObject) parser.parse(rd); - + + JSONTokener tokener = new JSONTokener(rd); + JSONObject jsonObject = new JSONObject(tokener); +// JSONParser parser = new JSONParser(); +// JSONObject jsonObject = (JSONObject) parser.parse(rd); + logger.trace("response received json : "+jsonObject.toString()); wr.close(); rd.close(); diff --git a/src/test/java/org/gcube/portlets/user/workspace/GoogleUrlShortener.java b/src/test/java/org/gcube/portlets/user/workspace/GoogleUrlShortener.java index 52d895e..5caf977 100644 --- a/src/test/java/org/gcube/portlets/user/workspace/GoogleUrlShortener.java +++ b/src/test/java/org/gcube/portlets/user/workspace/GoogleUrlShortener.java @@ -16,8 +16,9 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; +import org.json.JSONObject; +import org.json.JSONTokener; + public final class GoogleUrlShortener { @@ -57,15 +58,18 @@ public final class GoogleUrlShortener { jsonObj.put(LONG_URL, longUrl); jsonObj.put(authenticationKeyParam, authenticationKeyValue); + System.out.println("sending request json : "+jsonObj.toString()); + OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream()); - wr.write(jsonObj.toJSONString()); + wr.write(jsonObj.toString()); wr.flush(); BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); - JSONParser parser = new JSONParser(); - JSONObject jsonObject = (JSONObject) parser.parse(rd); - + JSONTokener tokener = new JSONTokener(rd); + JSONObject jsonObject = new JSONObject(tokener); + + System.out.println("response received json : "+jsonObject.toString()); wr.close(); rd.close(); @@ -95,7 +99,7 @@ public final class GoogleUrlShortener { jsonObj.put(LONG_URL, longUrl); jsonObj.put(authenticationKeyParam, authenticationKeyValue); - String body = jsonObj.toJSONString(); + String body = jsonObj.toString(); HttpCallerUtil httpCaller = new HttpCallerUtil(shortnerServerUrl, "", ""); @@ -104,8 +108,10 @@ public final class GoogleUrlShortener { System.out.println("json: "+json); - JSONParser parser = new JSONParser(); - JSONObject jsonObject = (JSONObject) parser.parse(json); + JSONTokener tokener = new JSONTokener(json); + JSONObject jsonObject = new JSONObject(tokener); + + System.out.println("response received json : "+jsonObject.toString()); return (String) jsonObject.get("id"); //is shorted url