Example usage for org.apache.commons.httpclient HttpStatus SC_INTERNAL_SERVER_ERROR

List of usage examples for org.apache.commons.httpclient HttpStatus SC_INTERNAL_SERVER_ERROR

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpStatus SC_INTERNAL_SERVER_ERROR.

Prototype

int SC_INTERNAL_SERVER_ERROR

To view the source code for org.apache.commons.httpclient HttpStatus SC_INTERNAL_SERVER_ERROR.

Click Source Link

Document

<tt>500 Server Error</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:org.alfresco.integrations.google.docs.webscripts.RemoveContent.java

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    getGoogleDocsServiceSubsystem();//  www  .  ja va 2s  .co m

    Map<String, Object> model = new HashMap<String, Object>();

    boolean success = false;

    /* The node we are working on */
    Map<String, Serializable> map = parseContent(req);
    final NodeRef nodeRef = (NodeRef) map.get(JSON_KEY_NODEREF);

    /* Make sure the node is currently "checked out" to Google */
    if (nodeService.hasAspect(nodeRef, GoogleDocsModel.ASPECT_EDITING_IN_GOOGLE)) {
        try {
            Credential credential = googledocsService.getCredential();

            /* Get the metadata for the file we are working on */
            File file = googledocsService.getDriveFile(credential, nodeRef);
            /* remove it from users Google account and free it in the repo */
            googledocsService.removeContent(credential, nodeRef, file, (Boolean) map.get(JSON_KEY_FORCE));

            /* if we reach this point all should be completed */
            success = true;

        } catch (GoogleDocsAuthenticationException gdae) {
            throw new WebScriptException(HttpStatus.SC_BAD_GATEWAY, gdae.getMessage());
        } catch (GoogleDocsServiceException gdse) {
            if (gdse.getPassedStatusCode() > -1) {
                throw new WebScriptException(gdse.getPassedStatusCode(), gdse.getMessage());
            } else {
                throw new WebScriptException(gdse.getMessage());
            }
        } catch (GoogleDocsRefreshTokenException gdrte) {
            throw new WebScriptException(HttpStatus.SC_BAD_GATEWAY, gdrte.getMessage());
        } catch (ConstraintException ce) {
            throw new WebScriptException(GoogleDocsConstants.STATUS_INTEGIRTY_VIOLATION, ce.getMessage(), ce);
        } catch (AccessDeniedException ade) {
            // This code will make changes after the rollback has occurred to clean up the node
            // (remove the lock and the Google Docs aspect
            AlfrescoTransactionSupport.bindListener(new TransactionListenerAdapter() {
                public void afterRollback() {
                    log.debug("Rollback Save to node: " + nodeRef);
                    transactionService.getRetryingTransactionHelper()
                            .doInTransaction(new RetryingTransactionCallback<Object>() {
                                public Object execute() throws Throwable {
                                    return AuthenticationUtil
                                            .runAsSystem(new AuthenticationUtil.RunAsWork<Object>() {
                                                public Object doWork() throws Exception {
                                                    googledocsService.unlockNode(nodeRef);
                                                    googledocsService.unDecorateNode(nodeRef);

                                                    // If the node was just created ('Create Content') it will
                                                    // have the temporary aspect and should be completely removed.
                                                    if (nodeService.hasAspect(nodeRef,
                                                            ContentModel.ASPECT_TEMPORARY)) {
                                                        nodeService.deleteNode(nodeRef);
                                                    }

                                                    return null;
                                                }
                                            });
                                }
                            }, false, true);
                }
            });

            throw new WebScriptException(HttpStatus.SC_FORBIDDEN, ade.getMessage(), ade);
        } catch (Exception e) {
            throw new WebScriptException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e);
        }
    }

    model.put(MODEL_SUCCESSFUL, success);

    return model;
}

From source file:org.alfresco.integrations.google.docs.webscripts.RemoveContent.java

private Map<String, Serializable> parseContent(final WebScriptRequest req) {
    final Map<String, Serializable> result = new HashMap<String, Serializable>();
    Content content = req.getContent();// ww w .j  ava 2 s.c o  m
    String jsonStr = null;
    JSONObject json = null;

    try {
        if (content == null || content.getSize() == 0) {
            throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "No content sent with request.");
        }

        jsonStr = content.getContent();

        if (jsonStr == null || jsonStr.trim().length() == 0) {
            throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "No content sent with request.");
        }
        log.debug("Parsed JSON: " + jsonStr);

        json = new JSONObject(jsonStr);

        if (!json.has(JSON_KEY_NODEREF)) {
            throw new WebScriptException(HttpStatus.SC_BAD_REQUEST,
                    "Key " + JSON_KEY_NODEREF + " is missing from JSON: " + jsonStr);
        } else {
            NodeRef nodeRef = new NodeRef(json.getString(JSON_KEY_NODEREF));
            result.put(JSON_KEY_NODEREF, nodeRef);
        }

        if (!json.has(JSON_KEY_FORCE)) {
            result.put(JSON_KEY_FORCE, false);
        } else {
            result.put(JSON_KEY_FORCE, json.getBoolean(JSON_KEY_FORCE));
        }

    } catch (final IOException ioe) {
        throw new WebScriptException(HttpStatus.SC_INTERNAL_SERVER_ERROR, ioe.getMessage(), ioe);
    } catch (final JSONException je) {
        throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Unable to parse JSON: " + jsonStr);
    } catch (final WebScriptException wse) {
        throw wse; // Ensure WebScriptExceptions get rethrown verbatim
    } catch (final Exception e) {
        throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Unable to parse JSON '" + jsonStr + "'.", e);
    }

    return result;
}

From source file:org.alfresco.integrations.google.docs.webscripts.SaveContent.java

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    getGoogleDocsServiceSubsystem();/*www.ja v a 2s  .  co m*/

    Map<String, Object> model = new HashMap<String, Object>();

    boolean success = false;

    Map<String, Serializable> map = parseContent(req);
    final NodeRef nodeRef = (NodeRef) map.get(JSON_KEY_NODEREF);
    log.debug("Saving Node to Alfresco from Google: " + nodeRef);

    try {
        SiteInfo siteInfo = siteService.getSite(nodeRef);
        if (siteInfo == null
                || siteService.isMember(siteInfo.getShortName(), AuthenticationUtil.getRunAsUser())) {

            if (!(Boolean) map.get(JSON_KEY_OVERRIDE)) {
                log.debug("Check for Concurent Users.");
                if (googledocsService.hasConcurrentEditors(nodeRef)) {
                    throw new WebScriptException(HttpStatus.SC_CONFLICT,
                            "Node: " + nodeRef.toString() + " has concurrent editors.");
                }
            }

            // Should the content be removed from the users Google Drive Account
            boolean removeFromDrive = (map.get(JSON_KEY_REMOVEFROMDRIVE) != null)
                    ? (Boolean) map.get(JSON_KEY_REMOVEFROMDRIVE)
                    : true;

            String contentType = googledocsService.getContentType(nodeRef);
            log.debug("NodeRef: " + nodeRef + "; ContentType: " + contentType);
            if (contentType.equals(GoogleDocsConstants.DOCUMENT_TYPE)) {
                if (googledocsService.isGoogleDocsLockOwner(nodeRef)) {
                    googledocsService.unlockNode(nodeRef);

                    if (removeFromDrive) {
                        googledocsService.getDocument(nodeRef);
                    } else {
                        googledocsService.getDocument(nodeRef, removeFromDrive);
                    }
                    success = true; // TODO Make getDocument return boolean
                } else {
                    throw new WebScriptException(HttpStatus.SC_FORBIDDEN,
                            "Document is locked by another user.");
                }
            } else if (contentType.equals(GoogleDocsConstants.SPREADSHEET_TYPE)) {
                if (googledocsService.isGoogleDocsLockOwner(nodeRef)) {
                    googledocsService.unlockNode(nodeRef);

                    if (removeFromDrive) {
                        googledocsService.getSpreadSheet(nodeRef);
                    } else {
                        googledocsService.getSpreadSheet(nodeRef, removeFromDrive);
                    }
                    success = true; // TODO Make getSpreadsheet return
                                    // boolean
                } else {
                    throw new WebScriptException(HttpStatus.SC_FORBIDDEN,
                            "Document is locked by another user.");
                }
            } else if (contentType.equals(GoogleDocsConstants.PRESENTATION_TYPE)) {
                if (googledocsService.isGoogleDocsLockOwner(nodeRef)) {
                    googledocsService.unlockNode(nodeRef);

                    if (removeFromDrive) {
                        googledocsService.getPresentation(nodeRef);
                    } else {
                        googledocsService.getPresentation(nodeRef, removeFromDrive);
                    }
                    success = true; // TODO Make getPresentation return
                                    // boolean
                } else {
                    throw new WebScriptException(HttpStatus.SC_FORBIDDEN,
                            "Document is locked by another user.");
                }
            } else {
                throw new WebScriptException(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE,
                        "Content Type: " + contentType + " unknown.");
            }

            // Finish this off with a version create or update
            Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
            if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE)) {
                versionProperties.put(Version2Model.PROP_VERSION_TYPE, map.get(JSON_KEY_MAJORVERSION));
                versionProperties.put(Version2Model.PROP_DESCRIPTION, map.get(JSON_KEY_DESCRIPTION));
            } else {
                versionProperties.put(Version2Model.PROP_VERSION_TYPE, VersionType.MAJOR);

                nodeService.setProperty(nodeRef, ContentModel.PROP_AUTO_VERSION, true);
                nodeService.setProperty(nodeRef, ContentModel.PROP_AUTO_VERSION_PROPS, true);
            }

            log.debug("Version Node:" + nodeRef + "; Version Properties: " + versionProperties);
            Version version = versionService.createVersion(nodeRef, versionProperties);

            model.put(MODEL_VERSION, version.getVersionLabel());

            if (!removeFromDrive) {
                googledocsService.lockNode(nodeRef);
            }

        } else {
            throw new AccessDeniedException(
                    "Access Denied.  You do not have the appropriate permissions to perform this operation.");
        }

    } catch (GoogleDocsAuthenticationException gdae) {
        throw new WebScriptException(HttpStatus.SC_BAD_GATEWAY, gdae.getMessage());
    } catch (GoogleDocsServiceException gdse) {
        if (gdse.getPassedStatusCode() > -1) {
            throw new WebScriptException(gdse.getPassedStatusCode(), gdse.getMessage());
        } else {
            throw new WebScriptException(gdse.getMessage());
        }
    } catch (GoogleDocsRefreshTokenException gdrte) {
        throw new WebScriptException(HttpStatus.SC_BAD_GATEWAY, gdrte.getMessage());
    } catch (ConstraintException ce) {
        throw new WebScriptException(GoogleDocsConstants.STATUS_INTEGIRTY_VIOLATION, ce.getMessage(), ce);
    } catch (AccessDeniedException ade) {
        // This code will make changes after the rollback has occurred to clean up the node (remove the lock and the Google Docs
        // aspect
        AlfrescoTransactionSupport.bindListener(new TransactionListenerAdapter() {
            public void afterRollback() {
                log.debug("Rollback Save to node: " + nodeRef);
                transactionService.getRetryingTransactionHelper()
                        .doInTransaction(new RetryingTransactionCallback<Object>() {
                            public Object execute() throws Throwable {
                                return AuthenticationUtil
                                        .runAsSystem(new AuthenticationUtil.RunAsWork<Object>() {
                                            public Object doWork() throws Exception {
                                                googledocsService.unlockNode(nodeRef);
                                                googledocsService.unDecorateNode(nodeRef);

                                                // If the node was just created ('Create Content') it will have the temporary aspect and should
                                                // be completely removed.
                                                if (nodeService.hasAspect(nodeRef,
                                                        ContentModel.ASPECT_TEMPORARY)) {
                                                    nodeService.deleteNode(nodeRef);
                                                }

                                                return null;
                                            }
                                        });
                            }
                        }, false, true);
            }
        });

        throw new WebScriptException(HttpStatus.SC_FORBIDDEN, ade.getMessage(), ade);
    } catch (Exception e) {
        throw new WebScriptException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e);
    }

    model.put(MODEL_SUCCESS, success);

    return model;
}

From source file:org.alfresco.integrations.google.docs.webscripts.SaveContent.java

private Map<String, Serializable> parseContent(final WebScriptRequest req) {
    final Map<String, Serializable> result = new HashMap<String, Serializable>();
    Content content = req.getContent();//  w  w w.  ja va  2 s .c  o m
    String jsonStr = null;
    JSONObject json = null;

    try {
        if (content == null || content.getSize() == 0) {
            throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "No content sent with request.");
        }

        jsonStr = content.getContent();

        if (jsonStr == null || jsonStr.trim().length() == 0) {
            throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "No content sent with request.");
        }
        log.debug("Parsed JSON: " + jsonStr);

        json = new JSONObject(jsonStr);

        if (!json.has(JSON_KEY_NODEREF)) {
            throw new WebScriptException(HttpStatus.SC_BAD_REQUEST,
                    "Key " + JSON_KEY_NODEREF + " is missing from JSON: " + jsonStr);
        } else {
            NodeRef nodeRef = new NodeRef(json.getString(JSON_KEY_NODEREF));
            result.put(JSON_KEY_NODEREF, nodeRef);

            if (json.has(JSON_KEY_OVERRIDE)) {
                result.put(JSON_KEY_OVERRIDE, json.getBoolean(JSON_KEY_OVERRIDE));
            } else {
                result.put(JSON_KEY_OVERRIDE, false);
            }

            if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE)) {
                result.put(JSON_KEY_MAJORVERSION,
                        json.getBoolean(JSON_KEY_MAJORVERSION) ? VersionType.MAJOR : VersionType.MINOR);
                result.put(JSON_KEY_DESCRIPTION, json.getString(JSON_KEY_DESCRIPTION));
            }

            if (json.has(JSON_KEY_REMOVEFROMDRIVE)) {
                result.put(JSON_KEY_REMOVEFROMDRIVE, json.getBoolean(JSON_KEY_REMOVEFROMDRIVE));
            }
        }
    } catch (final IOException ioe) {
        throw new WebScriptException(HttpStatus.SC_INTERNAL_SERVER_ERROR, ioe.getMessage(), ioe);
    } catch (final JSONException je) {
        throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Unable to parse JSON: " + jsonStr);
    } catch (final WebScriptException wse) {
        throw wse; // Ensure WebScriptExceptions get rethrown verbatim
    } catch (final Exception e) {
        throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Unable to parse JSON '" + jsonStr + "'.", e);
    }

    return result;
}

From source file:org.alfresco.integrations.google.docs.webscripts.UploadContent.java

@SuppressWarnings("unchecked")
@Override// w w  w  .j  ava2 s  .  c om
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    getGoogleDocsServiceSubsystem();

    Map<String, Object> model = new HashMap<String, Object>();

    if (googledocsService.isEnabled()) {

        String param_nodeRef = req.getParameter(PARAM_NODEREF);
        NodeRef nodeRef = new NodeRef(param_nodeRef);

        Map<String, Serializable> jsonParams = parseContent(req);

        DriveFile driveFile;
        try {
            if (nodeService.hasAspect(nodeRef, GoogleDocsModel.ASPECT_EDITING_IN_GOOGLE)) {
                // Check the doc exists in Google - it may have been removed accidentally
                try {
                    driveFile = googledocsService.getDriveFile(nodeRef);
                } catch (GoogleDocsServiceException gdse) {
                    driveFile = googledocsService.uploadFile(nodeRef);
                    if (log.isDebugEnabled()) {
                        log.debug(nodeRef + " Uploaded to Google.");
                    }
                    // Re-apply the previous permissions, if they exist
                    if (nodeService.getProperty(nodeRef, GoogleDocsModel.PROP_CURRENT_PERMISSIONS) != null) {
                        googledocsService.addRemotePermissions(driveFile, googledocsService
                                .getGooglePermissions(nodeRef, GoogleDocsModel.PROP_CURRENT_PERMISSIONS), true);
                    }
                }
            } else {
                driveFile = googledocsService.uploadFile(nodeRef);
                if (log.isDebugEnabled()) {
                    log.debug(nodeRef + " Uploaded to Google.");
                }
            }

            if (jsonParams.containsKey(PARAM_PERMISSIONS)) {
                if (log.isDebugEnabled()) {
                    log.debug("Adding permissions to remote object");
                }
                googledocsService.addRemotePermissions(driveFile,
                        (List<GooglePermission>) jsonParams.get(PARAM_PERMISSIONS),
                        ((Boolean) jsonParams.get(PARAM_SEND_EMAIL)).booleanValue());
            }

            // If this is a non-cloud instance of Alfresco, we need to make the
            // node versionable before we start working on it. We want the the
            // version component to be triggered on save. The versionable aspect
            // is only added if this is existing content, not if it was just
            // created where the document is the initial version when saved
            if (!nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TEMPORARY)
                    && !nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE)) {
                Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
                versionProperties.put(Version2Model.PROP_VERSION_TYPE, VersionType.MAJOR);

                nodeService.setProperty(nodeRef, ContentModel.PROP_AUTO_VERSION, true);
                // autoVersionOnUpdateProps now set to false to follow Share upload scripts (fixes GOOGLEDOCS-111)
                nodeService.setProperty(nodeRef, ContentModel.PROP_AUTO_VERSION_PROPS, false);

                log.debug("Version Node:" + nodeRef + "; Version Properties: " + versionProperties);
                versionService.createVersion(nodeRef, versionProperties);
            }

            if (googledocsService.isLockedByGoogleDocs(nodeRef)) {
                googledocsService.unlockNode(nodeRef);
            }

            googledocsService.decorateNode(nodeRef, driveFile, googledocsService.getLatestRevision(driveFile),
                    (List<GooglePermission>) jsonParams.get(PARAM_PERMISSIONS), false);
            googledocsService.lockNode(nodeRef);
        } catch (GoogleDocsAuthenticationException gdae) {
            throw new WebScriptException(HttpStatus.SC_BAD_GATEWAY, gdae.getMessage());
        } catch (GoogleDocsServiceException gdse) {
            if (gdse.getPassedStatusCode() > -1) {
                throw new WebScriptException(gdse.getPassedStatusCode(), gdse.getMessage());
            } else {
                throw new WebScriptException(gdse.getMessage());
            }
        } catch (GoogleDocsRefreshTokenException gdrte) {
            throw new WebScriptException(HttpStatus.SC_BAD_GATEWAY, gdrte.getMessage());
        } catch (IOException ioe) {
            throw new WebScriptException(HttpStatus.SC_INTERNAL_SERVER_ERROR, ioe.getMessage(), ioe);
        } catch (Exception e) {
            throw new WebScriptException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e);
        }

        model.put(MODEL_NODEREF, nodeRef.toString());

    } else {
        throw new WebScriptException(HttpStatus.SC_SERVICE_UNAVAILABLE, "Google Docs Disabled");
    }

    return model;
}

From source file:org.alfresco.integrations.google.docs.webscripts.UploadContent.java

private Map<String, Serializable> parseContent(final WebScriptRequest req) {
    final Map<String, Serializable> result = new HashMap<String, Serializable>();
    Content content = req.getContent();/*from w  w w.  j a v  a 2s. c  o m*/
    String jsonStr = null;
    JSONObject json = null;

    try {
        if (content == null || content.getSize() == 0) {
            return result;
        }

        jsonStr = content.getContent();

        if (jsonStr == null || jsonStr.trim().length() == 0) {
            throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "No content sent with request.");
        }
        log.debug("Parsed JSON: " + jsonStr);

        json = new JSONObject(jsonStr);

        if (json.has(JSON_KEY_PERMISSIONS)) {
            JSONObject permissionData = json.getJSONObject(JSON_KEY_PERMISSIONS);
            boolean sendEmail = permissionData.has(JSON_KEY_PERMISSIONS_SEND_EMAIL)
                    ? permissionData.getBoolean(JSON_KEY_PERMISSIONS_SEND_EMAIL)
                    : true;
            if (!permissionData.has(JSON_KEY_PERMISSIONS_ITEMS)) {
                throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Key " + JSON_KEY_PERMISSIONS_ITEMS
                        + " is missing from JSON object: " + permissionData.toString());
            }
            JSONArray jsonPerms = permissionData.getJSONArray(JSON_KEY_PERMISSIONS_ITEMS);
            ArrayList<GooglePermission> permissions = new ArrayList<GoogleDocsService.GooglePermission>(
                    jsonPerms.length());
            for (int i = 0; i < jsonPerms.length(); i++) {
                JSONObject jsonPerm = jsonPerms.getJSONObject(i);
                String authorityId, authorityType, roleName;
                if (jsonPerm.has(JSON_KEY_AUTHORITY_ID)) {
                    authorityId = jsonPerm.getString(JSON_KEY_AUTHORITY_ID);
                } else {
                    throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Key " + JSON_KEY_AUTHORITY_ID
                            + " is missing from JSON object: " + jsonPerm.toString());
                }
                if (jsonPerm.has(JSON_KEY_AUTHORITY_TYPE)) {
                    authorityType = jsonPerm.getString(JSON_KEY_AUTHORITY_TYPE);
                } else {
                    authorityType = JSON_VAL_AUTHORITY_TYPE_DEFAULT;
                }
                if (jsonPerm.has(JSON_KEY_ROLE_NAME)) {
                    roleName = jsonPerm.getString(JSON_KEY_ROLE_NAME);
                } else {
                    throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Key " + JSON_KEY_ROLE_NAME
                            + " is missing from JSON object: " + jsonPerm.toString());
                }
                permissions.add(new GooglePermission(authorityId, authorityType, roleName));
            }
            result.put(PARAM_PERMISSIONS, permissions);
            result.put(PARAM_SEND_EMAIL, Boolean.valueOf(sendEmail));
        }
    } catch (final IOException ioe) {
        throw new WebScriptException(HttpStatus.SC_INTERNAL_SERVER_ERROR, ioe.getMessage(), ioe);
    } catch (final JSONException je) {
        throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Unable to parse JSON: " + jsonStr);
    } catch (final WebScriptException wse) {
        throw wse; // Ensure WebScriptExceptions get rethrown verbatim
    } catch (final Exception e) {
        throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Unable to parse JSON '" + jsonStr + "'.", e);
    }

    return result;
}

From source file:org.alfresco.integrations.google.docs.webscripts.UserProfile.java

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    getGoogleDocsServiceSubsystem();//from   w  w  w . ja  va2s  .  c o m

    Map<String, Object> model = new HashMap<String, Object>();

    boolean authenticated = false;

    if (googledocsService.isAuthenticated()) {
        authenticated = true;
        try {
            Credential credential = googledocsService.getCredential();

            User user = googledocsService.getDriveUser(credential);
            model.put(MODEL_EMAIL, user.getEmailAddress());
            model.put(MODEL_NAME, user.getDisplayName());
            //model.put(MODEL_FIRSTNAME, user.getFirstName()); TODO Get first name?
            //model.put(MODEL_LASTNAME, profile.getLastName()); TODO Get last name?
            model.put(MODEL_ID, user.getPermissionId());
        } catch (GoogleDocsAuthenticationException gdae) {
            throw new WebScriptException(HttpStatus.SC_BAD_GATEWAY, gdae.getMessage());
        } catch (GoogleDocsRefreshTokenException gdrte) {
            throw new WebScriptException(HttpStatus.SC_BAD_GATEWAY, gdrte.getMessage());
        } catch (GoogleDocsServiceException gdse) {
            if (gdse.getPassedStatusCode() > -1) {
                throw new WebScriptException(gdse.getPassedStatusCode(), gdse.getMessage());
            } else {
                throw new WebScriptException(gdse.getMessage());
            }
        } catch (IOException ioe) {
            throw new WebScriptException(HttpStatus.SC_INTERNAL_SERVER_ERROR, ioe.getMessage());
        }
    }

    model.put(MODEL_AUTHENTICATED, authenticated);

    return model;
}

From source file:org.alfresco.integrations.google.glass.webscripts.UploadContent.java

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();

    String param_nodeRef = req.getParameter(PARAM_NODEREF);
    NodeRef nodeRef = new NodeRef(param_nodeRef);

    try {//from w ww.  j a  va  2 s .co  m
        googleGlassService.uploadContent(googleGlassService.getCredential(), nodeRef);
    } catch (GoogleGlassAuthenticationException ggae) {
        throw new WebScriptException(HttpStatus.SC_BAD_GATEWAY, ggae.getMessage());
    } catch (GoogleGlassServiceException ggse) {
        if (ggse.getPassedStatusCode() > -1) {
            throw new WebScriptException(ggse.getPassedStatusCode(), ggse.getMessage());
        } else {
            throw new WebScriptException(ggse.getMessage());
        }
    } catch (GoogleGlassRefreshTokenException ggrte) {
        throw new WebScriptException(HttpStatus.SC_BAD_GATEWAY, ggrte.getMessage());
    } catch (IOException ioe) {
        throw new WebScriptException(HttpStatus.SC_INTERNAL_SERVER_ERROR, ioe.getMessage(), ioe);
    } catch (Exception e) {
        throw new WebScriptException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e);
    }

    model.put(MODEL_NODEREF, nodeRef.toString());

    return model;
}

From source file:org.alfresco.repo.jive.rest.SocializeDocumentsWebScript.java

private final List<NodeRef> parseNodeRefs(final WebScriptRequest req) {
    final List<NodeRef> result = new ArrayList<NodeRef>();
    Content content = req.getContent();//from   w w  w  .  j a  v  a 2 s.  co  m
    String jsonStr = null;
    JSONObject json = null;

    try {
        if (content == null || content.getSize() == 0) {
            throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "No content sent with request.");
        }

        jsonStr = content.getContent();

        if (jsonStr == null || jsonStr.trim().length() == 0) {
            throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "No content sent with request.");
        }

        json = new JSONObject(jsonStr);

        if (!json.has(JSON_KEY_NODE_REFS)) {
            throw new WebScriptException(HttpStatus.SC_BAD_REQUEST,
                    "Key " + JSON_KEY_NODE_REFS + " is missing from JSON: " + jsonStr);
        }

        JSONArray nodeRefs = json.getJSONArray(JSON_KEY_NODE_REFS);

        for (int i = 0; i < nodeRefs.length(); i++) {
            NodeRef nodeRef = new NodeRef(nodeRefs.getString(i));
            result.add(nodeRef);
        }
    } catch (final IOException ioe) {
        throw new WebScriptException(HttpStatus.SC_INTERNAL_SERVER_ERROR, ioe.getMessage(), ioe);
    } catch (final JSONException je) {
        throw new WebScriptException(HttpStatus.SC_BAD_REQUEST, "Unable to parse JSON: " + jsonStr);
    } catch (final WebScriptException wse) {
        throw wse; // Ensure WebScriptExceptions get rethrown verbatim
    } catch (final Exception e) {
        throw new WebScriptException(HttpStatus.SC_BAD_REQUEST,
                "Unable to retrieve nodeRefs from JSON '" + jsonStr + "'.", e);
    }

    return (result);
}

From source file:org.alfresco.services.solr.GetTextContentResponse.java

private void setStatus() {
    int status = response.getStatus();
    if (status == HttpStatus.SC_NOT_MODIFIED) {
        this.status = SolrApiContentStatus.NOT_MODIFIED;
    } else if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
        this.status = SolrApiContentStatus.GENERAL_FAILURE;
    } else if (status == HttpStatus.SC_OK) {
        this.status = SolrApiContentStatus.OK;
    } else if (status == HttpStatus.SC_NO_CONTENT) {
        if (transformStatusStr == null) {
            this.status = SolrApiContentStatus.UNKNOWN;
        } else {/* w  w w  . j ava  2s. c  om*/
            if (transformStatusStr.equals("noTransform")) {
                this.status = SolrApiContentStatus.NO_TRANSFORM;
            } else if (transformStatusStr.equals("transformFailed")) {
                this.status = SolrApiContentStatus.TRANSFORM_FAILED;
            } else {
                this.status = SolrApiContentStatus.UNKNOWN;
            }
        }
    }
}