changed org.json classes so I updated url shortener and google shortener

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@96021 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2014-05-23 10:16:37 +00:00
parent b22a23d678
commit 79e46e0e7c
2 changed files with 27 additions and 17 deletions

View File

@ -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();

View File

@ -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