@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { String surfBugStatusUpdate = req.getParameter(UPDATE_STATUS_REQUEST_PARAMETER); this.webFrameworkConfigElement.setSurfBugEnabled(surfBugStatusUpdate != null && surfBugStatusUpdate.equals(DEBUG_ENABLED)); Map<String, Object> model = new HashMap<String, Object>(7, 1.0f); model.put("surfbugEnabled", this.webFrameworkConfigElement.isSurfBugEnabled()); return model; } }
/** * Gets the values of template variables * * @return map of value indexed by variable name (or the empty map) */ public Map<String, String> getTemplateArgs() { Map<String, String> args = req.getServiceMatch().getTemplateVars(); return (args == null) ? emptyArgs : args; } }
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);
/** * Create a map of (array) arguments from Web Script Request (for scripting) * * @param req Web Script Request * @return argument map */ final protected Map<String, String[]> createArgsM(WebScriptRequest req) { String[] names = req.getParameterNames(); Map<String, String[]> args = new HashMap<String, String[]>(names.length, 1.0f); for (String name : names) { args.put(name, req.getParameterValues(name)); } return args; }
/** * Create a map of arguments from Web Script Request (for scripting) * * @param req Web Script Request * @return argument map */ final protected Map<String, String> createArgs(WebScriptRequest req) { String[] names = req.getParameterNames(); Map<String, String> args = new HashMap<String, String>(names.length, 1.0f); for (String name : names) { args.put(name, req.getParameter(name)); } return args; }
String[] moduleIdsToDeploy = req.getParameterValues("deployedModules"); if (moduleIdsToDeploy == null) JSONObject modAsJson = new JSONObject(modAsJsonStr); modulesToDeploy.add(modAsJson);
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) if (debug) logger.debug("Agent: " + scriptReq.getAgent()); 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() + ")"); String format = req.getFormat(); String mimetype = container.getFormatRegistry().getMimeType(req.getAgent(), statusTemplate.getFormat()); if (mimetype == null) logger.debug("Force success status header in response: " + req.forceSuccessStatus()); logger.debug("Sending status " + statusCode + " (Template: " + statusTemplate.getPath() + ")"); logger.debug("Rendering response: content type=" + mimetype); res.setCache(cache); res.setStatus(req.forceSuccessStatus() ? HttpServletResponse.SC_OK : statusCode); res.setContentType(mimetype + ";charset=UTF-8"); try
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"); ScriptDetails script = getExecuteScript(req.getContentType()); if (script != null) if (statusCode != HttpServletResponse.SC_OK && !req.forceSuccessStatus()) logger.debug("Force success status header in response: " + req.forceSuccessStatus()); logger.debug("Setting status " + statusCode); res.setStatus(statusCode); res.setHeader(WebScriptResponse.HEADER_LOCATION, location); res.setCache(cache); if (getContainer().allowCallbacks()) callback = req.getJSONCallback();
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.reset(); res.setCache(cache); res.setStatus(req.forceSuccessStatus() ? HttpServletResponse.SC_OK : statusCode); String location = status.getLocation(); if (location != null && location.length() > 0)
res.setContentType(Format.JAVASCRIPT.mimetype() + ";charset=UTF-8"); res.setCache(cache); String locale = req.getParameter("locale"); if (locale == null || locale.length() == 0) throw new WebScriptException("Locale parameter is mandatory."); res.getWriter().write(result); res.getWriter().flush(); res.getWriter().close();
StatusTemplate statusTemplate = null; Map<String, Object> statusModel = null; String format = request.getFormat(); statusCode = we.getStatus(); statusTemplate = we.getStatusTemplate(); statusModel = we.getStatusModel(); 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) 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); response.setStatus(request.forceSuccessStatus() ? HttpServletResponse.SC_OK : statusCode); response.setContentType(mimetype + ";charset=UTF-8"); statusProcessor.process(validTemplatePath, statusModel, response.getWriter());
params.put("webscript", req.getServiceMatch().getWebScript().getDescription()); params.put("format", new FormatModel(container.getFormatRegistry(), req.getFormat())); params.put("args", createArgs(req)); params.put("argsM", createArgsM(req)); params.put("headers", createHeaders(req)); params.put("headersM", createHeadersM(req)); params.put("guest", req.isGuest()); params.put("url", createURLModel(req)); params.put("msg", getScriptMessage()); final String contentType = req.getContentType(); if (script != null) FormatReader<Object> reader = container.getFormatRegistry().getReader(script.getRequestType()); if (!(WebScriptRequestImpl.MULTIPART_FORM_DATA.equals(contentType) && getDescription().getMultipartProcessing() == false)) params.putAll(req.getRuntime().getScriptParameters()); params.putAll(container.getScriptParameters());
params.putAll(req.getRuntime().getTemplateParameters()); params.putAll(container.getTemplateParameters()); params.put("webscript", req.getServiceMatch().getWebScript().getDescription()); params.put("format", new FormatModel(container.getFormatRegistry(), req.getFormat())); params.put("args", createArgs(req)); params.put("argsM", createArgsM(req)); params.put("headers", createHeaders(req)); params.put("headersM", createHeadersM(req)); params.put("guest", req.isGuest()); params.put("url", createURLModel(req)); params.put("absurl", new AbsoluteUrlMethod(req.getServerPath())); params.put("formatwrite", new FormatWriterMethod(container.getFormatRegistry(), req.getFormat())); params.put("message", getMessageMethod()); // for compatibility with repo templates params.put("msg", getMessageMethod()); // short form for presentation webscripts
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() + ")"); res.setCache(cache);
@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().getUri(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("uri", path); return model; }
public String encodeScriptUrl(String url) { WebScriptRequest req = new WebScriptPortletRequest(getRuntime(), null, url, null); PortletURL portletUrl = res.createActionURL(); portletUrl.setParameter("scriptUrl", req.getServicePath()); String[] parameterNames = req.getParameterNames(); for (String parameterName : parameterNames) { portletUrl.setParameter("arg." + parameterName, req.getParameter(parameterName)); } return portletUrl.toString(); }
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"); OutputStream out = res.getOutputStream(); res.setContentType(Format.XML.mimetype() + ";charset=UTF-8"); byte[] buffer = new byte[2048]; int read = serviceDescIS.read(buffer); throw new WebScriptException("Failed to read Web Script description document for '" + scriptId + "'", e);
throw new WebScriptException("Web Script install only supported via HTTP Servlet"); Object content = req.parseContent(); if (content == null || !(content instanceof FormData)) 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"); InputStream fileIS = file.getContent().getInputStream(); try getContainer().reset(); Registry registry = getContainer().getRegistry(); WebScript webscript = registry.getWebScript(scriptId); if (webscript == null)
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");
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) { List<String> tasks = new ArrayList<String>(); // reset index String reset = req.getParameter("reset"); if (reset != null && reset.equals("on")) { // reset list of web scripts int previousCount = getContainer().getRegistry().getWebScripts().size(); int previousFailures = getContainer().getRegistry().getFailures().size(); getContainer().reset(); tasks.add("Reset Web Scripts Registry; registered " + getContainer().getRegistry().getWebScripts().size() + " Web Scripts. Previously, there were " + previousCount + "."); int newFailures = getContainer().getRegistry().getFailures().size(); if (newFailures != 0 || previousFailures != 0) { tasks.add("Warning: found " + newFailures + " broken Web Scripts. Previously, there were " + previousFailures + "."); } } // create model for rendering Map<String, Object> model = new HashMap<String, Object>(7, 1.0f); model.put("tasks", tasks); model.put("webscripts", getContainer().getRegistry().getWebScripts()); model.put("failures", getContainer().getRegistry().getFailures()); return model; }