org.springframework.extensions.webscripts.WebScriptException Java Examples
The following examples show how to use
org.springframework.extensions.webscripts.WebScriptException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Login.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) { // extract username and password String username = req.getParameter("u"); if (username == null || username.length() == 0) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Username not specified"); } String password = req.getParameter("pw"); if (password == null) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Password not specified"); } try { return login(username, password); } catch(WebScriptException e) { status.setCode(e.getStatus()); status.setMessage(e.getMessage()); status.setRedirect(true); return null; } }
Example #2
Source File: AssociationGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected QName getAssociationQname(WebScriptRequest req) { String associationName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_ASSOCIATION_SHORTNAME); String associationPrefix = req.getServiceMatch().getTemplateVars().get(DICTIONARY_ASSOCIATION_PREFIX); if(associationPrefix == null) { throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter association prefix in the URL"); } if(associationName == null) { throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter association name in the URL"); } return QName.createQName(getFullNamespaceURI(associationPrefix, associationName)); }
Example #3
Source File: LargeContentTestPut.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { Map<String, Object> model = new HashMap<String, Object>(); try { req.getContent().getInputStream().close(); model.put("result", "success"); } catch (IOException e) { throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "Fail to read request content."); } return model; }
Example #4
Source File: ForumPostGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef, TopicInfo topic, PostInfo post, WebScriptRequest req, JSONObject json, Status status, Cache cache) { // Build the common model parts Map<String, Object> model = buildCommonModel(site, topic, post, req); // Did they want just one post, or the whole of the topic? if (post != null) { model.put(KEY_POSTDATA, renderPost(post, site)); } else if (topic != null) { model.put(KEY_POSTDATA, renderTopic(topic, site)); } else { String error = "Node was of the wrong type, only Topic and Post are supported"; throw new WebScriptException(Status.STATUS_BAD_REQUEST, error); } // All done return model; }
Example #5
Source File: AbstractWorkflowWebscript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Retrieves the named parameter as an integer, if the parameter is not present the default value is returned * * @param req The WebScript request * @param paramName The name of parameter to look for * @param defaultValue The default value that should be returned if parameter is not present in request or if it is not positive * @return The request parameter or default value */ protected int getIntParameter(WebScriptRequest req, String paramName, int defaultValue) { String paramString = req.getParameter(paramName); if (paramString != null) { try { int param = Integer.valueOf(paramString); if (param > 0) { return param; } } catch (NumberFormatException e) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); } } return defaultValue; }
Example #6
Source File: AbstractWorkflowWebscript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Retrieves the named paramter as a date. * * @param req The WebScript request * @param paramName The name of parameter to look for * @return The request parameter value or null if the parameter is not present */ protected Date getDateParameter(WebScriptRequest req, String paramName) { String dateString = req.getParameter(paramName); if (dateString != null) { try { return ISO8601DateFormat.parse(dateString.replaceAll(" ", "+")); } catch (Exception e) { String msg = "Invalid date value: " + dateString; throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg); } } return null; }
Example #7
Source File: ADMRemoteStore.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Gets the last modified timestamp for the document. * <p> * The output will be the last modified date as a long toString(). * * @param path document path to an existing document */ @Override protected void lastModified(final WebScriptResponse res, final String store, final String path) throws IOException { AuthenticationUtil.runAs(new RunAsWork<Void>() { @SuppressWarnings("synthetic-access") public Void doWork() throws Exception { final String encpath = encodePath(path); final FileInfo fileInfo = resolveFilePath(encpath); if (fileInfo == null) { throw new WebScriptException("Unable to locate file: " + encpath); } Writer out = res.getWriter(); out.write(Long.toString(fileInfo.getModifiedDate().getTime())); out.close(); if (logger.isDebugEnabled()) logger.debug("lastModified: " + Long.toString(fileInfo.getModifiedDate().getTime())); return null; } }, AuthenticationUtil.getSystemUserName()); }
Example #8
Source File: WorkflowInstanceGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) { Map<String, String> params = req.getServiceMatch().getTemplateVars(); // getting workflow instance id from request parameters String workflowInstanceId = params.get("workflow_instance_id"); boolean includeTasks = getIncludeTasks(req); WorkflowInstance workflowInstance = workflowService.getWorkflowById(workflowInstanceId); // task was not found -> return 404 if (workflowInstance == null) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find workflow instance with id: " + workflowInstanceId); } Map<String, Object> model = new HashMap<String, Object>(); // build the model for ftl model.put("workflowInstance", modelBuilder.buildDetailed(workflowInstance, includeTasks)); return model; }
Example #9
Source File: DictionaryWebServiceBase.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * @param classname the class name as cm_person * @return String the full name in the following format {namespaceuri}shorname */ public String getFullNamespaceURI(String classname) { try { String result = null; String prefix = this.getPrefix(classname); String url = this.namespaceService.getNamespaceURI(prefix); String name = this.getShortName(classname); result = "{" + url + "}"+ name; return result; } catch (Exception e) { throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact classname - " + classname + " parameter has not been provided in the URL"); } }
Example #10
Source File: WorkflowInstancesGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Gets the specified {@link WorkflowState}, null if not requested. * * @param req The WebScript request * @return The workflow state or null if not requested */ private WorkflowState getState(WebScriptRequest req) { String stateName = req.getParameter(PARAM_STATE); if (stateName != null) { try { return WorkflowState.valueOf(stateName.toUpperCase()); } catch (IllegalArgumentException e) { String msg = "Unrecognised State parameter: " + stateName; throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg); } } return null; }
Example #11
Source File: RunningActionGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected Map<String, Object> buildModel( RunningActionModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) { // Which action did they ask for? String actionTrackingId = req.getServiceMatch().getTemplateVars().get("action_tracking_id"); ExecutionSummary action = getSummaryFromKey(actionTrackingId); // Get the details, if we can Map<String,Object> model = modelBuilder.buildSimpleModel(action); if(model == null) { throw new WebScriptException( Status.STATUS_NOT_FOUND, "No Running Action found with that tracking id" ); } return model; }
Example #12
Source File: AbstractSubscriptionServiceWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
protected int parseNumber(String name, String number, int def) { if (number != null && number.length() > 0) { try { return Integer.parseInt(number); } catch (NumberFormatException e) { throw new WebScriptException(400, name + " is not a number!", e); } } else { return def; } }
Example #13
Source File: QuickShareContentGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
protected void executeImpl(NodeRef nodeRef, Map<String, String> templateVars, WebScriptRequest req, WebScriptResponse res, Map<String, Object> model, boolean attach) throws IOException { // render content QName propertyQName = ContentModel.PROP_CONTENT; String contentPart = templateVars.get("property"); if (contentPart.length() > 0 && contentPart.charAt(0) == ';') { if (contentPart.length() < 2) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Content property malformed"); } String propertyName = contentPart.substring(1); if (propertyName.length() > 0) { propertyQName = QName.createQName(propertyName, namespaceService); } } // Stream the content streamContentLocal(req, res, nodeRef, attach, propertyQName, model); }
Example #14
Source File: SolrFacetConfigAdminDelete.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache) { // get the filterID parameter. Map<String, String> templateVars = req.getServiceMatch().getTemplateVars(); String filterID = templateVars.get("filterID"); if (filterID == null) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Filter id not provided"); } facetService.deleteFacet(filterID); Map<String, Object> model = new HashMap<String, Object>(1); model.put("success", true); if (logger.isDebugEnabled()) { logger.debug("Facet [" + filterID + "] has been deleted successfully"); } return model; }
Example #15
Source File: SolrFacetConfigAdminPost.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache) { try { SolrFacetProperties fp = parseRequestForFacetProperties(req); facetService.createFacetNode(fp); if (logger.isDebugEnabled()) { logger.debug("Created facet node: " + fp); } } catch (Throwable t) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not save the facet configuration.", t); } return new HashMap<>(); // Needs to be mutable. }
Example #16
Source File: AbstractRuleWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Parses the request and providing it's valid returns the NodeRef. * * @param req The webscript request * @return The NodeRef passed in the request * */ protected NodeRef parseRequestForNodeRef(WebScriptRequest req) { // get the parameters that represent the NodeRef, we know they are present // otherwise this webscript would not have matched Map<String, String> templateVars = req.getServiceMatch().getTemplateVars(); String storeType = templateVars.get("store_type"); String storeId = templateVars.get("store_id"); String nodeId = templateVars.get("id"); // create the NodeRef and ensure it is valid StoreRef storeRef = new StoreRef(storeType, storeId); NodeRef nodeRef = new NodeRef(storeRef, nodeId); if (!this.nodeService.exists(nodeRef)) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find node: " + nodeRef.toString()); } return nodeRef; }
Example #17
Source File: AbstractSiteWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { // Grab the site String siteName = req.getServiceMatch().getTemplateVars().get("shortname"); SiteInfo site = siteService.getSite(siteName); if (site == null) { throw new WebScriptException( Status.STATUS_NOT_FOUND, "No Site found with that short name"); } // Process return executeImpl(site, req, status, cache); }
Example #18
Source File: SiteAdminSitesGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
private int getIntParameter(WebScriptRequest req, String paramName, int defaultValue) { String paramString = req.getParameter(paramName); if (paramString != null) { try { int param = Integer.valueOf(paramString); if (param >= 0) { return param; } } catch (NumberFormatException e) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); } } return defaultValue; }
Example #19
Source File: RatingDelete.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { Map<String, Object> model = new HashMap<String, Object>(); NodeRef nodeRef = parseRequestForNodeRef(req); String ratingSchemeName = parseRequestForScheme(req); Rating deletedRating = ratingService.removeRatingByCurrentUser(nodeRef, ratingSchemeName); if (deletedRating == null) { // There was no rating in the specified scheme to delete. throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Unable to delete non-existent rating: " + ratingSchemeName + " from " + nodeRef.toString()); } model.put(NODE_REF, nodeRef.toString()); model.put(AVERAGE_RATING, ratingService.getAverageRating(nodeRef, ratingSchemeName)); model.put(RATINGS_TOTAL, ratingService.getTotalRating(nodeRef, ratingSchemeName)); model.put(RATINGS_COUNT, ratingService.getRatingsCount(nodeRef, ratingSchemeName)); return model; }
Example #20
Source File: AbstractRatingWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
protected NodeRef parseRequestForNodeRef(WebScriptRequest req) { // get the parameters that represent the NodeRef, we know they are present // otherwise this webscript would not have matched Map<String, String> templateVars = req.getServiceMatch().getTemplateVars(); String storeType = templateVars.get("store_type"); String storeId = templateVars.get("store_id"); String nodeId = templateVars.get("id"); // create the NodeRef and ensure it is valid StoreRef storeRef = new StoreRef(storeType, storeId); NodeRef nodeRef = new NodeRef(storeRef, nodeId); if (!this.nodeService.exists(nodeRef)) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find node: " + nodeRef.toString()); } return nodeRef; }
Example #21
Source File: AbstractAuditWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
private Long getLongParam(String paramStr, Long defaultVal) { if (paramStr == null) { // note: defaultVal can be null return defaultVal; } try { return Long.parseLong(paramStr); } catch (NumberFormatException e) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, e.getMessage()); } }
Example #22
Source File: AbstractArchivedNodeWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Retrieves the named parameter as an integer, if the parameter is not present the default value is returned * * @param req The WebScript request * @param paramName The name of parameter to look for * @param defaultValue The default value that should be returned if parameter is not present in request or if it is not positive * @return The request parameter or default value */ protected int getIntParameter(WebScriptRequest req, String paramName, int defaultValue) { String paramString = req.getParameter(paramName); if (paramString != null) { try { int param = Integer.valueOf(paramString); if (param >= 0) { return param; } } catch (NumberFormatException e) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); } } return defaultValue; }
Example #23
Source File: DocLinkPost.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Create link for sourceNodeRef in destinationNodeRef location * * @param destinationNodeRef * @param sourceNodeRef * @return */ private NodeRef createLink(NodeRef destinationNodeRef, NodeRef sourceNodeRef) { NodeRef linkNodeRef = null; try { linkNodeRef = documentLinkService.createDocumentLink(sourceNodeRef, destinationNodeRef); } catch (IllegalArgumentException ex) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid Arguments: " + ex.getMessage()); } catch (AccessDeniedException e) { throw new WebScriptException(Status.STATUS_FORBIDDEN, "You don't have permission to perform this operation"); } return linkNodeRef; }
Example #24
Source File: StreamACP.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Attempts to retrieve and convert a JSON array of * NodeRefs from the given JSON object. If the nodeRefs * property is not present a WebScriptException is thrown. * * @param json JSONObject * @return Array of NodeRef objects */ protected NodeRef[] getNodeRefs(JSONObject json) throws JSONException { // check the list of NodeRefs is present if (!json.has(PARAM_NODE_REFS)) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Mandatory 'nodeRefs' parameter was not provided in request body"); } NodeRef[] nodeRefs = new NodeRef[0]; JSONArray jsonArray = json.getJSONArray(PARAM_NODE_REFS); if (jsonArray.length() != 0) { // build the list of NodeRefs nodeRefs = new NodeRef[jsonArray.length()]; for (int i = 0; i < jsonArray.length(); i++) { NodeRef nodeRef = new NodeRef(jsonArray.getString(i)); nodeRefs[i] = nodeRef; } } return nodeRefs; }
Example #25
Source File: PropertyGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected QName getPropertyQname(WebScriptRequest req) { String propertyName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_SHORTPROPERTY_NAME); String propertyPrefix = req.getServiceMatch().getTemplateVars().get(DICTIONARY_PROPERTY_FREFIX); //validate the presence of property name if(propertyName == null) { throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter short propertyname in the URL"); } //validate the presence of property prefix if(propertyPrefix == null) { throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter propertyprefix in the URL"); } return QName.createQName(getFullNamespaceURI(propertyPrefix, propertyName)); }
Example #26
Source File: TemplatesWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) { String path = "/"; String templatePattern = "*.ftl"; // process extension String p = req.getExtensionPath(); // optional if ((p != null) && (p.length() > 0)) { int idx = p.lastIndexOf("/"); if (idx != -1) { path = p.substring(0, idx); templatePattern = p.substring(idx+1) + ".ftl"; } } Set<String> templatePaths = new HashSet<String>(); for (Store apiStore : searchPath.getStores()) { try { for (String templatePath : apiStore.getDocumentPaths(path, false, templatePattern)) { templatePaths.add(templatePath); } } catch (IOException e) { throw new WebScriptException("Failed to search for templates from store " + apiStore, e); } } Map<String, Object> model = new HashMap<String, Object>(); model.put("paths", templatePaths); return model; }
Example #27
Source File: WorkflowInstanceDiagramGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { Map<String, String> params = req.getServiceMatch().getTemplateVars(); // getting workflow instance id from request parameters String workflowInstanceId = params.get("workflow_instance_id"); WorkflowInstance workflowInstance = workflowService.getWorkflowById(workflowInstanceId); // workflow instance was not found -> return 404 if (workflowInstance == null) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find workflow instance with id: " + workflowInstanceId); } // check whether there is a diagram available if (!workflowService.hasWorkflowImage(workflowInstanceId)) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find diagram for workflow instance with id: " + workflowInstanceId); } // copy image data into temporary file File file = TempFileProvider.createTempFile("workflow-diagram-", ".png"); InputStream imageData = workflowService.getWorkflowImage(workflowInstanceId); OutputStream os = new FileOutputStream(file); FileCopyUtils.copy(imageData, os); // stream temporary file back to client streamContent(req, res, file); }
Example #28
Source File: WorkflowInstanceDelete.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) { Map<String, String> params = req.getServiceMatch().getTemplateVars(); // getting workflow instance id from request parameters String workflowInstanceId = params.get("workflow_instance_id"); // determine if instance should be cancelled or deleted boolean forced = getForced(req); if (canUserEndWorkflow(workflowInstanceId)) { if (forced) { workflowService.deleteWorkflow(workflowInstanceId); } else { workflowService.cancelWorkflow(workflowInstanceId); } return null; } else { throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Failed to " + (forced ? "delete" : "cancel") + " workflow instance with id: " + workflowInstanceId); } }
Example #29
Source File: BaseRemoteStore.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * Validate we have a path argument. */ private static void validatePath(String path) { if (path == null) { throw new WebScriptException("Remote Store expecting document path elements."); } }
Example #30
Source File: AlfrescoModelsDiff.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
private Map<String, Object> buildModel(WebScriptRequest req) throws JSONException, IOException { Map<String, Object> model = new HashMap<String, Object>(1, 1.0f); Content content = req.getContent(); if(content == null) { throw new WebScriptException("Failed to convert request to String"); } JSONObject o = new JSONObject(content.getContent()); JSONArray jsonModels = o.getJSONArray("models"); Map<QName, Long> models = new HashMap<QName, Long>(jsonModels.length()); for(int i = 0; i < jsonModels.length(); i++) { JSONObject jsonModel = jsonModels.getJSONObject(i); models.put(QName.createQName(jsonModel.getString("name")), jsonModel.getLong("checksum")); } List<AlfrescoModelDiff> diffs = solrTrackingComponent.getModelDiffs(models); model.put("diffs", diffs); if (logger.isDebugEnabled()) { logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model); } return model; }