Search in sources :

Example 1 with SubscriptionsDisabledException

use of org.alfresco.service.cmr.subscriptions.SubscriptionsDisabledException in project alfresco-remote-api by Alfresco.

the class AbstractSubscriptionServiceWebScript method execute.

public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {
    if (!subscriptionService.isActive()) {
        res.setStatus(404);
        return;
    }
    try {
        String userId = req.getServiceMatch().getTemplateVars().get("userid");
        Object obj = executeImpl(userId, req, res);
        if (obj instanceof JSONObject || obj instanceof JSONArray) {
            res.setContentEncoding(Charset.defaultCharset().displayName());
            res.setContentType(Format.JSON.mimetype() + ";charset=UTF-8");
            Writer writer = res.getWriter();
            if (obj instanceof JSONObject) {
                ((JSONObject) obj).writeJSONString(writer);
            } else {
                ((JSONArray) obj).writeJSONString(writer);
            }
            writer.flush();
        } else {
            res.setStatus(204);
        }
    } catch (SubscriptionsDisabledException sde) {
        throw new WebScriptException(404, "Subscription service is disabled!", sde);
    } catch (NoSuchPersonException nspe) {
        throw new WebScriptException(404, "Unknown user '" + nspe.getUserName() + "'!", nspe);
    } catch (PrivateSubscriptionListException psle) {
        throw new WebScriptException(403, "Subscription list is private!", psle);
    } catch (ParseException pe) {
        throw new WebScriptException(400, "Unable to parse JSON!", pe);
    } catch (ClassCastException cce) {
        throw new WebScriptException(400, "Unable to parse JSON!", cce);
    } catch (IOException ioe) {
        throw new WebScriptException(500, "Unable to serialize JSON!", ioe);
    }
}
Also used : PrivateSubscriptionListException(org.alfresco.service.cmr.subscriptions.PrivateSubscriptionListException) JSONObject(org.json.simple.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) NoSuchPersonException(org.alfresco.service.cmr.security.NoSuchPersonException) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) SubscriptionsDisabledException(org.alfresco.service.cmr.subscriptions.SubscriptionsDisabledException) ParseException(org.json.simple.parser.ParseException) IOException(java.io.IOException) Writer(java.io.Writer)

Aggregations

IOException (java.io.IOException)1 Writer (java.io.Writer)1 NoSuchPersonException (org.alfresco.service.cmr.security.NoSuchPersonException)1 PrivateSubscriptionListException (org.alfresco.service.cmr.subscriptions.PrivateSubscriptionListException)1 SubscriptionsDisabledException (org.alfresco.service.cmr.subscriptions.SubscriptionsDisabledException)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 ParseException (org.json.simple.parser.ParseException)1 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)1