rave-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gonzalo Aguilar (JIRA)" <j...@apache.org>
Subject [jira] [Issue Comment Deleted] (RAVE-1293) Rave crashes when shindig is not available
Date Sun, 25 Jan 2015 00:52:35 GMT

     [ https://issues.apache.org/jira/browse/RAVE-1293?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Gonzalo Aguilar updated RAVE-1293:
----------------------------------
    Comment: was deleted

(was: diff --git a/rave-providers/rave-opensocial-provider/rave-opensocial-client/src/main/java/org/apache/rave/provider/opensocial/repository/impl/ShindigGadgetMetadataRepository.java
b/rave-providers/rave-opensocial-provider/rave-opensocial-client/src/main/java/org/apache/rave/provider/opensocial/repository/impl/ShindigGadgetMetadataRepository.java
index 8e7aaf0..9ae8fb2 100644
--- a/rave-providers/rave-opensocial-provider/rave-opensocial-client/src/main/java/org/apache/rave/provider/opensocial/repository/impl/ShindigGadgetMetadataRepository.java
+++ b/rave-providers/rave-opensocial-provider/rave-opensocial-client/src/main/java/org/apache/rave/provider/opensocial/repository/impl/ShindigGadgetMetadataRepository.java
@@ -19,6 +19,7 @@
 
 package org.apache.rave.provider.opensocial.repository.impl;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.rave.provider.opensocial.repository.GadgetMetadataRepository;
 import org.json.JSONArray;
 import org.json.JSONException;
@@ -29,6 +30,7 @@
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Repository;
+import org.springframework.web.client.HttpClientErrorException;
 import org.springframework.web.client.RestOperations;
 
 import java.util.Iterator;
@@ -40,94 +42,103 @@
 
 @Repository
 public class ShindigGadgetMetadataRepository implements GadgetMetadataRepository {
-    private static Logger logger = LoggerFactory.getLogger(ShindigGadgetMetadataRepository.class);
+	private static Logger logger = LoggerFactory.getLogger(ShindigGadgetMetadataRepository.class);
 
-    private RestOperations restOperations;
-    private String shindigUrl;
+	private RestOperations restOperations;
+	private String shindigUrl;
 
-    @Autowired
-    public ShindigGadgetMetadataRepository(@Qualifier(value = "jsonStringCompatibleRestTemplate")
RestOperations restOperations,
-                                           @Value("${portal.opensocial_engine.protocol}")
String shindigProtocol,
-                                           @Value("${portal.opensocial_engine.root}") String
shindigRoot) {
-        this.restOperations = restOperations;
-        this.shindigUrl = shindigProtocol + "://" + shindigRoot + "/rpc";
-        logger.debug("Shindig render Url: " + shindigUrl);
-    }
+	@Autowired
+	public ShindigGadgetMetadataRepository(@Qualifier(value = "jsonStringCompatibleRestTemplate")
RestOperations restOperations,
+			@Value("${portal.opensocial_engine.protocol}") String shindigProtocol,
+			@Value("${portal.opensocial_engine.root}") String shindigRoot) {
+		this.restOperations = restOperations;
+		this.shindigUrl = shindigProtocol + "://" + shindigRoot + "/rpc";
+		logger.debug("Shindig render Url: " + shindigUrl);
+	}
 
-    @Override
-    public String getGadgetMetadata(String gadgetUrl) {
-        //generate the json request to be sent to the shindig RPC service
-        JSONArray rpcArray = new JSONArray();
-        try {
-            JSONObject fetchMetadataRpcOperation = new JSONObject()
-                    .put("method", "gadgets.metadata")
-                    .put("id", "gadgets.metadata")
-                    .put("params", new JSONObject()
-                            .put("container", "default")
-                            .append("ids", gadgetUrl)
-                            .append("fields", "iframeUrls")
-                            .append("fields", "modulePrefs.*")
-                            .append("fields", "needsTokenRefresh")
-                            .append("fields", "userPrefs.*")
-                            .append("fields", "views.preferredHeight")
-                            .append("fields", "views.preferredWidth")
-                            .append("fields", "expireTimeMs")
-                            .append("fields", "responseTimeMs")
-                            .put("userId", "@viewer")
-                            .put("groupId", "@self")
-                    );
+	@Override
+	public String getGadgetMetadata(String gadgetUrl) {
+		//generate the json request to be sent to the shindig RPC service
+		JSONArray rpcArray = new JSONArray();
+		try {
+			JSONObject fetchMetadataRpcOperation = new JSONObject()
+			.put("method", "gadgets.metadata")
+			.put("id", "gadgets.metadata")
+			.put("params", new JSONObject()
+			.put("container", "default")
+			.append("ids", gadgetUrl)
+			.append("fields", "iframeUrls")
+			.append("fields", "modulePrefs.*")
+			.append("fields", "needsTokenRefresh")
+			.append("fields", "userPrefs.*")
+			.append("fields", "views.preferredHeight")
+			.append("fields", "views.preferredWidth")
+			.append("fields", "expireTimeMs")
+			.append("fields", "responseTimeMs")
+			.put("userId", "@viewer")
+			.put("groupId", "@self")
+					);
 
-            rpcArray.put(fetchMetadataRpcOperation);
-        } catch (JSONException e) {
-            throw new IllegalArgumentException("Error occurred while generating data for
shindig metadata call", e);
-        }
+			rpcArray.put(fetchMetadataRpcOperation);
+		} catch (JSONException e) {
+			throw new IllegalArgumentException("Error occurred while generating data for shindig metadata
call", e);
+		}
 
-        //convert the json object to a string
-        String postData = rpcArray.toString();
-        if (logger.isDebugEnabled()) {
-            logger.debug("requestContent: {}", postData);
-        }
+		//convert the json object to a string
+		String postData = rpcArray.toString();
+		if (logger.isDebugEnabled()) {
+			logger.debug("requestContent: {}", postData);
+		}
 
-        //fire off the request and get the raw JSON back as a string
-        String responseString = restOperations.postForObject(shindigUrl, postData, String.class);
-        if (logger.isDebugEnabled()) {
-            logger.debug("shindig metadata raw response: {}", responseString);
-        }
+		//fire off the request and get the raw JSON back as a string
+		String responseString = null;
+		try {
+			restOperations.postForObject(shindigUrl, postData, String.class);
+		} catch (HttpClientErrorException ex) {
+			logger.warn("Cannot get shindig metadata for widget: {}", ex.getMessage());
+		}
+		if (logger.isDebugEnabled()) {
+			logger.debug("shindig metadata raw response: {}", responseString);
+		}
 
-        //now trim back the response to just the metadata for the single gadget
-        try {
-            JSONObject responseObject = new JSONArray(responseString).
-                    getJSONObject(0).
-                    getJSONObject("result").
-                    getJSONObject(gadgetUrl);
+		if(!StringUtils.isEmpty(responseString)){
+			//now trim back the response to just the metadata for the single gadget
+			try {
+				JSONObject responseObject = new JSONArray(responseString).
+						getJSONObject(0).
+						getJSONObject("result").
+						getJSONObject(gadgetUrl);
 
-            // check to see if this gadget has at least one non-hidden user pref
-            // to determine if we should display the edit prefs button
-            boolean hasPrefsToEdit = false;
-            if (responseObject.has(USER_PREFS)) {
-                JSONObject userPrefs = responseObject.getJSONObject(USER_PREFS);
-                Iterator keys = userPrefs.keys();
-                while(keys.hasNext()) {
-                    String userPrefName = (String) keys.next();
-                    JSONObject userPref = userPrefs.getJSONObject(userPrefName);
-                    if (!PrefDataTypes.HIDDEN.toString().equals(userPref.getString(DATA_TYPE)))
{
-                        hasPrefsToEdit = true;
-                        break;
-                    }
-                }
-            }
+				// check to see if this gadget has at least one non-hidden user pref
+				// to determine if we should display the edit prefs button
+				boolean hasPrefsToEdit = false;
+				if (responseObject.has(USER_PREFS)) {
+					JSONObject userPrefs = responseObject.getJSONObject(USER_PREFS);
+					Iterator keys = userPrefs.keys();
+					while(keys.hasNext()) {
+						String userPrefName = (String) keys.next();
+						JSONObject userPref = userPrefs.getJSONObject(userPrefName);
+						if (!PrefDataTypes.HIDDEN.toString().equals(userPref.getString(DATA_TYPE))) {
+							hasPrefsToEdit = true;
+							break;
+						}
+					}
+				}
 
-            responseObject.put(HAS_PREFS_TO_EDIT, hasPrefsToEdit);
-            responseString = responseObject.toString();
+				responseObject.put(HAS_PREFS_TO_EDIT, hasPrefsToEdit);
+				responseString = responseObject.toString();
 
-            if (logger.isDebugEnabled()) {
-                logger.debug("shindig metadata trimmed response: {}", responseString);
-            }
-        } catch (JSONException e) {
-            throw new IllegalArgumentException("Error occurred while processing response
from shindig metadata call", e);
-        }
+				if (logger.isDebugEnabled()) {
+					logger.debug("shindig metadata trimmed response: {}", responseString);
+				}
+			} catch (JSONException e) {
+				throw new IllegalArgumentException("Error occurred while processing response from shindig
metadata call", e);
+			}
+		} else {
+			responseString = "{}"; // Build valid JSON
+		}
 
-        //return the raw JSON
-        return responseString;
-    }
+		//return the raw JSON
+		return responseString;
+	}
 }
\ No newline at end of file)

> Rave crashes when shindig is not available
> ------------------------------------------
>
>                 Key: RAVE-1293
>                 URL: https://issues.apache.org/jira/browse/RAVE-1293
>             Project: Rave
>          Issue Type: Bug
>          Components: rave-opensocial-provider
>    Affects Versions: 0.23
>            Reporter: Gonzalo Aguilar
>             Fix For: 0.24
>
>         Attachments: level2-shindig-prefix.patch
>
>
> Rave fails when shindig is not available when trying to get metadata info for a widget.
This patch returns an empty metadata when it's not available so Rave can render an empty widget.




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message