Content content = req.getContent(); if (content == null) throw new WebScriptException("Failed to convert request to JSON"); try String jsonString = content.getContent(); if (jsonString.startsWith("[") == true) result = new JSONObject(jsonString); throw new WebScriptException("Failed to convert request to JSON", exception);
/** * Attach an advanced description of the status code associated to this exception * * @param statusTemplate status template * @param statusModel template model * @deprecated */ public void setStatusTemplate(final StatusTemplate statusTemplate, final Map<String, Object> statusModel) { setStatusTemplateFactory(new StatusTemplateFactory() { public Map<String, Object> getStatusModel() { return statusModel; } public StatusTemplate getStatusTemplate() { return statusTemplate; } }); }
if (scriptUrl == null || scriptUrl.length() == 0) throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Script URL not specified"); if ((match != null) && (match.getWebScript().getDescription().getRequiredAuthentication().equals(RequiredAuthentication.none))) if (match == null || match.getKind() == Match.Kind.URI) throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, msg); throw new WebScriptException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg); if (e instanceof WebScriptException && (((WebScriptException)e).getStatus() == HttpServletResponse.SC_NOT_FOUND || ((WebScriptException)e).getStatus() == HttpServletResponse.SC_UNAUTHORIZED)) String errorCode = ((WebScriptException)e).getStatus() == HttpServletResponse.SC_NOT_FOUND ? "NOT FOUND" : "UNAUTHORIZED"; logger.debug("Webscript did not execute. (" + errorCode + "): " + e.getMessage()); statusCode = we.getStatus(); statusTemplate = we.getStatusTemplate(); statusModel = we.getStatusModel(); throw new WebScriptException("Failed to find status template " + statusTemplate.getPath() + " (format: " + statusTemplate.getFormat() + ")"); throw new WebScriptException("Web Script format '" + statusTemplate.getFormat() + "' is not registered"); throw new WebScriptException("Internal error", e1);
wildcard = true; if (desc.getFormatStyle() != Description.FormatStyle.argument) String uriIdx = desc.getMethod() + ":" + uri; if (index.containsKey(uriIdx)) if (!existingService.getDescription().getId().equals(desc.getId())) String msg = "Web Script document " + desc.getDescPath() + " is attempting to define the url '" + uriIdx + "' already defined by " + existingService.getDescription().getDescPath(); throw new WebScriptException(msg);
if (scriptUrl == null || scriptUrl.length() == 0) throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Script URL not specified"); if ((match != null) && (match.getWebScript().getDescription().getRequiredAuthentication().equals(RequiredAuthentication.none))) if (match == null || match.getKind() == Match.Kind.URI) throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, msg); throw new WebScriptException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg); if (debug) logger.debug("Agent: " + scriptReq.getAgent()); final WebScript script = match.getWebScript(); final Description description = script.getDescription(); String reqFormat = scriptReq.getFormat(); String format = (reqFormat == null || reqFormat.length() == 0) ? "[undefined]" : reqFormat; Description desc = scriptReq.getServiceMatch().getWebScript().getDescription(); logger.debug("Invoking Web Script " + description.getId() + " (format " + format + ", style: " + desc.getFormatStyle() + ", default: " + desc.getDefaultFormat() + ")"); if (e instanceof WebScriptException && (((WebScriptException)e).getStatus() == HttpServletResponse.SC_NOT_FOUND || ((WebScriptException)e).getStatus() == HttpServletResponse.SC_UNAUTHORIZED)) String errorCode = ((WebScriptException)e).getStatus() == HttpServletResponse.SC_NOT_FOUND ? "NOT FOUND" : "UNAUTHORIZED"; logger.debug("Webscript did not execute. (" + errorCode + "): " + e.getMessage());
if (match != null && match.getKind() != Match.Kind.URI) Description desc = match.getWebScript().getDescription(); FormatStyle style = desc.getFormatStyle(); throw new WebScriptException("Format specified both in extension and format argument"); NegotiatedFormat[] negotiatedFormats = desc.getNegotiatedFormats(); if (accept != null && negotiatedFormats != null) if (format == null) throw new WebScriptException(HttpServletResponse.SC_NOT_ACCEPTABLE, "Cannot negotiate appropriate response format for Accept: " + accept); format = desc.getDefaultFormat();
final public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException String format = req.getFormat(); String mimetype = getContainer().getFormatRegistry().getMimeType(req.getAgent(), format); if (mimetype == null) throw new WebScriptException("Web Script format '" + format + "' is not registered"); Cache cache = new Cache(getDescription().getRequiredCache()); Map<String, Object> model = executeImpl(req, status, cache); if (model == null) ScriptDetails script = getExecuteScript(req.getContentType()); if (script != null) if (getContainer().allowCallbacks()) callback = req.getJSONCallback();
@Override protected void executeImpl(Action action, NodeRef actionedUponNodeRef) { if (condition) { // Do something } else { throw new WebScriptException("Action is failed"); } }
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars(); String packagePath = "/" + templateVars.get("package"); Registry registry = getContainer().getRegistry(); Path path = registry.getPackage(packagePath); if (path == null) throw new WebScriptException(Status.STATUS_NOT_FOUND, "Web Script Package '" + packagePath + "' not found"); if (packageDoc == null) throw new WebScriptException(Status.STATUS_NOT_FOUND, "Web Script documentation for package '" + packagePath + "' not found"); for (WebScript webscript : webscripts) TypeDescription[] requests = webscript.getDescription().getRequestTypes(); if (requests != null) TypeDescription[] responses = webscript.getDescription().getResponseTypes(); if (responses != null)
logger.debug("Initialising Web Scripts (Container: " + container.getName() + ", URI index: " + uriIndex.getClass().getName() + ")"); throw new WebScriptException("Failed to search for package descriptions in store " + apiStore, e); throw new WebScriptException("Failed to read package description document " + apiStore.getBasePath() + packageDescPath, e); throw new WebScriptException("Failed to search for schema descriptions in store " + apiStore, e); throw new WebScriptException("Failed to read Web Script description document " + apiStore.getBasePath() + schemaDescPath, e); throw new WebScriptException("Failed to search for web scripts in store " + apiStore, e); throw new WebScriptException("Failed to read Web Script description document " + apiStore.getBasePath() + serviceDescPath, e); Description existingDesc = existingService.getDescription(); String msg = "Web Script description document " + serviceDesc.getStorePath() + "/" + serviceDesc.getDescPath(); msg += " overridden by " + existingDesc.getStorePath() + "/" + existingDesc.getDescPath(); logger.debug(msg); throw new WebScriptException("Web Script kind '" + kind + "' is unknown"); throw new WebScriptException("Failed to parse extensions from Web Script description document " + apiStore.getBasePath() + serviceDescPath, e); logger.debug("Registered Web Script URL '" + serviceImpl.getDescription().getMethod() + ":" + uriTemplate + "'");
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) { // extract web script package String uriPath = req.getExtensionPath(); if (uriPath == null || uriPath.length() == 0) { uriPath = "/"; } if (!uriPath.startsWith("/")) { uriPath = "/" + uriPath; } // locate web script package Path path = getContainer().getRegistry().getLifecycle(uriPath); if (path == null) { throw new WebScriptException(Status.STATUS_NOT_FOUND, "Web Script URI '" + uriPath + "' not found"); } Map<String, Object> model = new HashMap<String, Object>(7, 1.0f); model.put("lifecycle", path); return model; }
String scriptId = getDescription().getId(); StatusTemplate template = getStatusTemplate(scriptId, statusCode, statusFormat); String mimetype = container.getFormatRegistry().getMimeType(req.getAgent(), template.getFormat()); if (mimetype == null) throw new WebScriptException("Web Script format '" + template.getFormat() + "' is not registered"); logger.debug("Force success status header in response: " + req.forceSuccessStatus()); logger.debug("Sending status " + statusCode + " (Template: " + template.getPath() + ")"); logger.debug("Rendering response: content type=" + mimetype); res.setStatus(req.forceSuccessStatus() ? HttpServletResponse.SC_OK : statusCode); String location = status.getLocation(); if (location != null && location.length() > 0)
int startIndex = 0; String queryId = req.getParameter("queryId"); String pageSizeS = req.getParameter("pageSize"); if (pageSizeS != null) throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Paging size parameters invalid"); String startIndexS = req.getParameter("startIndex"); if (startIndexS != null) throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Paging size parameters invalid"); throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Paging size parameters invalid");
String scriptId = req.getExtensionPath(); if (scriptId == null || scriptId.length() == 0) throw new WebScriptException("Web Script Id not provided"); WebScript script = getContainer().getRegistry().getWebScript(scriptId); if (script == null) throw new WebScriptException("Web Script Id '" + scriptId + "' not found"); Collection<Store> stores = getContainer().getSearchPath().getStores(); for (Store store : stores) throw new WebScriptException("Failed to search for documents for script " + script.getDescription().getId() + " in store " + store, e);
StatusTemplate statusTemplate = null; Map<String, Object> statusModel = null; String format = request.getFormat(); statusCode = we.getStatus(); statusTemplate = we.getStatusTemplate(); statusModel = we.getStatusModel(); throw new WebScriptException("Failed to find status template " + statusTemplate.getPath() + " (format: " + statusTemplate.getFormat() + ")"); statusModel.putAll(container.getTemplateParameters()); statusModel.put("url", createURLModel(request)); if (match != null && match.getWebScript() != null) statusModel.put("webscript", match.getWebScript().getDescription()); String mimetype = container.getFormatRegistry().getMimeType(request.getAgent(), statusTemplate.getFormat()); if (mimetype == null) throw new WebScriptException("Web Script format '" + statusTemplate.getFormat() + "' is not registered"); logger.debug("Force success status header in response: " + request.forceSuccessStatus()); logger.debug("Sending status " + statusCode + " (Template: " + statusTemplate.getPath() + ")"); logger.debug("Rendering response: content type=" + mimetype); throw new WebScriptException("Internal error", e1);
String configPath = getDescription().getId() + ".config.xml"; input = this.container.getSearchPath().getDocument(configPath); if (input != null) throw new WebScriptException("Failed to read script configuration file", ioe); this.scriptConfigModel = new ScriptConfigModel(this.container.getConfigService(), this.xmlConfig); this.templateConfigModel = new TemplateConfigModel(this.container.getConfigService(), this.xmlConfig);
throw new WebScriptException("Web Script install only supported via HTTP Servlet"); throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Web Script install request is not multipart/form-data"); throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Web Script install request expects only one file upload"); throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Web Script install request is missing file upload"); if (nodes.size() == 0) throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Cannot locate Web Script in uploaded file"); if (scriptId == null || scriptId.length() == 0) throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Expected scriptid value on webscript element"); if (webscriptStore == null || webscriptStore.length() == 0) throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Expected store value on webscript element"); throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Expected file value on webscript element"); throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to install Web Script " + scriptId); throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
/** * Render a template (contents as string) * * @param template the template * @param model model * @param writer output writer * @param extension optional template extension type (i.e. ftl, php) */ final protected void renderString(String template, Map<String, Object> model, Writer writer, String extension) { TemplateProcessor processor = container.getTemplateProcessorRegistry().getTemplateProcessorByExtension(extension); if (processor != null) { processor.processString(template, model, writer); } else { throw new WebScriptException("No processor found for extension " + extension); } }
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException String scriptId = req.getExtensionPath(); if (scriptId == null || scriptId.length() == 0) throw new WebScriptException("Web Script Id not provided"); WebScript script = getContainer().getRegistry().getWebScript(scriptId); if (script == null) throw new WebScriptException("Web Script Id '" + scriptId + "' not found"); try serviceDescIS = desc.getDescDocument(); OutputStream out = res.getOutputStream(); res.setContentType(Format.XML.mimetype() + ";charset=UTF-8"); throw new WebScriptException("Failed to read Web Script description document for '" + scriptId + "'", e);