@Override
 public String getScript(String scriptName) {
   scriptName = URIParser.convertDocURI(scriptName);
   RaptureScript script = client.getScript().getScript(scriptName);
   if (script != null) {
     return script.getScript();
   }
   return "";
 }
Ejemplo n.º 2
0
 private PluginTransportItem encodeRaw(CallingContext context, RaptureURI uri) {
   String uriString = uri.toString();
   PluginTransportItem result = new PluginTransportItem();
   RaptureScript script = Kernel.getScript().getScript(context, uriString);
   if (script == null) return null;
   String text = script.getScript();
   result.setContent(text.getBytes(Charsets.UTF_8));
   result.setUri(uriString);
   try {
     MessageDigest md = MessageDigest.getInstance("MD5");
     md.update(text.getBytes("UTF-8"));
     result.setHash(Hex.encodeHexString(md.digest()));
   } catch (NoSuchAlgorithmException e) {
     throw RaptureExceptionFactory.create("JRE does not support MD5");
   } catch (UnsupportedEncodingException e) {
     throw RaptureExceptionFactory.create("JRE does not support UTF-8");
   }
   return result;
 }
Ejemplo n.º 3
0
  private void process(
      Map<String, String> parameterMap, HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    logger.debug("req is " + req);
    logger.debug("resp is " + resp);
    logger.debug("parameterMap is " + parameterMap);

    // check script exists
    RaptureURI scriptURI = getScriptURI(req);
    logger.info(String.format("Running script for uri %s", scriptURI.toString()));
    RaptureScript script = Kernel.getScript().getScript(ContextFactory.ADMIN, scriptURI.toString());
    if (script == null || StringUtils.isBlank(script.getScript())) {
      logger.warn("Could not locate script for uri - " + scriptURI.toString());
      resp.setStatus(HttpStatus.SC_NOT_FOUND);
      return;
    }
    // run JavaScript
    try {
      CallingContext context = BaseDispatcher.validateSession(req);
      if (context != null) {
        logger.trace("Got session context " + context.debug());
        String result =
            Kernel.getScript().runScript(context, scriptURI.getFullPath(), parameterMap);
        resp.setCharacterEncoding("UTF-8");
        resp.getWriter().append(result);
        resp.setContentType("text/plain");
      } else {
        String err =
            "Cannot execute script " + script + " : cannot get session context for authorization";
        logger.error(err);
        resp.sendError(HttpURLConnection.HTTP_UNAUTHORIZED, err);
      }
    } catch (RaptNotLoggedInException re) {
      logger.error("Cannot execute script " + script + " : " + re.getMessage());
      resp.sendError(re.getStatus(), re.getMessage());
    }
  }
Ejemplo n.º 4
0
 @Override
 public String getScript(String name) {
   RaptureScript script = api.getScript().getScript(name);
   return script == null ? null : script.getScript();
 }