setResponseHeaders(httpServletResponse);
try {
if (platformRequestWrapper.getOpenSocialConsumerKey() == null) {
log.warning("oauth_consumer_key is null");
throw new RequestException(ReqErrorTypes.UNSUPPORETED_PLATFORM);
}
if (platformRequestWrapper.getOpenSocialViewerId() == null) {
log.warning("opensocial_viewer_id is null");
throw new RequestException(ReqErrorTypes.USER_NOT_LOGGEDIN);
}
if (!UrlUtils.isOnDevPort8888(platformRequestWrapper)
&& !validateSignedRequestWithContainer(platformRequestWrapper)) {
throw new RequestException(ReqErrorTypes.USER_NOT_LOGGEDIN);
}
if (platformRequestWrapper.getCurrentUserProfile() != null){
// check if user changed in session the middle ?
userProfile = platformRequestWrapper.getCurrentUserProfile();
if(!userProfile.getOpenSocialViewerId().equals(platformRequestWrapper.getOpenSocialViewerId()))
platformRequestWrapper.getSession().setAttribute(
"userProfile", null);
}
if (platformRequestWrapper.getCurrentUserProfile() == null) {
userProfile = UserProfilesUtils
.getMyProfile(platformRequestWrapper);
if (userProfile != null){
platformRequestWrapper.getSession().setAttribute(
"userProfile", userProfile);
userIsValid = true;
}
else if (platformRequestWrapper.getGadgetActionType().equals(
ReqActionTypes.ADD_PROFILE))
userIsValid = true; // proceed to profile creation
else
throw new RequestException(
ReqErrorTypes.PROFILE_DOESNT_EXISTS);
}
else
userIsValid = true;
// load gadget
Gadget g = GadgetUtils.getGadget(platformRequestWrapper.getGadgetName());
if(g==null || g.getGadgletType()==null || !g.getGadgletType().equals(GadgetType.MINGLET.getGadgetType()))
throw new RequestException(
ReqErrorTypes.UNRECOGNIZED_GADGET);
else
platformRequestWrapper.setRequestedGadget(g);
} catch (RequestException e) {
userIsValid = false;
gadgetServerResponse.setError(e);
} catch (Exception e) {
userIsValid = false;
printStackTrace(e);
gadgetServerResponse.setError(new RequestException(
ReqErrorTypes.REQUEST_FAILED));
}
if (userIsValid)
performRequest(platformRequestWrapper, gadgetServerResponse,