예제 #1
0
    public HttpPost getPostMethod() throws Exception {
      if (post == null) {
        Map<String, Object> message = Maps.newHashMap();
        ArrayList<Map<String, Object>> actionInstanceArray = new ArrayList<>();
        for (int i = 0; i < qualifiedName.size(); i++) {
          Map<String, Object> actionInstance = Maps.newHashMap();
          actionInstance.put("descriptor", qualifiedName.get(i));
          if (actionParams.get(i) != null) {
            actionInstance.put("params", actionParams.get(i));
          }
          actionInstanceArray.add(actionInstance);
        }
        if (app == null) {
          app =
              Aura.getDefinitionService()
                  .getDefDescriptor("auratest:test_SimpleServerRenderedPage", ApplicationDef.class);
        }
        message.put("actions", actionInstanceArray.toArray());
        String jsonMessage = Json.serialize(message);
        Map<String, String> params = Maps.newHashMap();
        params.put("message", jsonMessage);
        params.put("aura.token", getTestServletConfig().getCsrfToken());

        params.put("aura.context", getAuraTestingUtil().buildContextForPost(mode, app, null, dn));
        post = obtainPostMethod("/aura", params);
      }
      return post;
    }
예제 #2
0
  /**
   * Convenience method for executing an Action
   *
   * @param descriptor fully qualified descriptor string for the action - e.g.
   *     java://org.auraframework.components.test.java.controller.JavaTestController/ACTION$getString
   * @param params a set of name value string pairs to use as parameters to the post call.
   * @return a {@link HttpPost}
   * @throws Exception
   */
  protected HttpPost executeAuraAction(
      Class<?> serverControllerClass,
      String methodName,
      Map<String, String> actionParams,
      Map<String, String> postParams)
      throws Exception {
    Map<String, Object> message = new HashMap<>();
    Map<String, Object> actionInstance = new HashMap<>();
    String descriptor =
        "java://" + serverControllerClass.getCanonicalName() + "/ACTION$" + methodName;
    actionInstance.put("descriptor", descriptor);
    if (actionParams != null) {
      actionInstance.put("params", actionParams);
    }
    Map<?, ?>[] actions = {actionInstance};
    message.put("actions", actions);
    String jsonMessage = Json.serialize(message);

    if (postParams == null) {
      postParams = Maps.newHashMap();
    }
    postParams.put("message", jsonMessage);
    if (!postParams.containsKey("aura.token")) {
      postParams.put("aura.token", getCsrfToken());
    }
    if (!postParams.containsKey("aura.context")) {
      postParams.put(
          "aura.context",
          Aura.getContextService().getCurrentContext().serialize(EncodingStyle.Normal));
    }
    HttpPost post = obtainPostMethod("/aura", postParams);
    perform(post);
    post.releaseConnection();
    return post;
  }
예제 #3
0
 @SuppressWarnings("unchecked")
 private void verifyStyleDefSerialization(DefDescriptor<StyleDef> styleDesc, Boolean expectCode)
     throws Exception {
   String serialized = Json.serialize(styleDesc.getDef());
   Object o = new JsonReader().read(serialized);
   assertTrue(o instanceof Map);
   Map<String, Object> outerMap = (Map<String, Object>) o;
   assertEquals(styleDesc.toString(), outerMap.get("descriptor"));
   assertEquals(
       styleDesc.getNamespace() + AuraTextUtil.initCap(styleDesc.getName()),
       outerMap.get("className"));
   if (expectCode) {
     assertEquals(
         "StyleDef content not included.", styleDesc.getDef().getCode(), outerMap.get("code"));
   } else {
     assertNull("StyleDef content should not be included.", outerMap.get("code"));
   }
 }
  @Override
  public void write(T value, Map<String, Object> componentAttributes, Appendable out)
      throws IOException {
    try {

      AuraContext context = Aura.getContextService().getCurrentContext();
      InstanceService instanceService = Aura.getInstanceService();
      RenderingService renderingService = Aura.getRenderingService();
      BaseComponentDef def = value.getDescriptor().getDef();

      ComponentDef templateDef = def.getTemplateDef();
      Map<String, Object> attributes = Maps.newHashMap();

      StringBuilder sb = new StringBuilder();
      writeHtmlStyles(new ArrayList<>(Arrays.asList(Aura.getConfigAdapter().getResetCssURL())), sb);
      attributes.put("auraResetCss", sb.toString());
      sb.setLength(0);
      writeHtmlStyles(AuraServlet.getStyles(), sb);
      attributes.put("auraStyleTags", sb.toString());
      sb.setLength(0);
      writeHtmlScripts(AuraServlet.getScripts(), sb);
      DefDescriptor<StyleDef> styleDefDesc = templateDef.getStyleDescriptor();
      if (styleDefDesc != null) {
        attributes.put("auraInlineStyle", styleDefDesc.getDef().getCode());
      }

      String contextPath = context.getContextPath();
      Mode mode = context.getMode();

      if (mode.allowLocalRendering() && def.isLocallyRenderable()) {
        BaseComponent<?, ?> cmp =
            (BaseComponent<?, ?>) instanceService.getInstance(def, componentAttributes);

        attributes.put("body", Lists.<BaseComponent<?, ?>>newArrayList(cmp));
        attributes.put("bodyClass", "");
        attributes.put("autoInitialize", "false");

        Component template = instanceService.getInstance(templateDef.getDescriptor(), attributes);

        renderingService.render(template, out);
      } else {

        attributes.put("auraScriptTags", sb.toString());
        Map<String, Object> auraInit = Maps.newHashMap();
        if (componentAttributes != null && !componentAttributes.isEmpty()) {
          auraInit.put("attributes", componentAttributes);
        }
        auraInit.put("descriptor", def.getDescriptor());
        auraInit.put("deftype", def.getDescriptor().getDefType());
        auraInit.put("host", contextPath);

        attributes.put("autoInitialize", "false");
        attributes.put("autoInitializeSync", "true");

        auraInit.put("instance", value);
        auraInit.put("token", AuraBaseServlet.getToken());

        StringBuilder contextWriter = new StringBuilder();
        Aura.getSerializationService()
            .write(context, null, AuraContext.class, contextWriter, "JSON");
        auraInit.put("context", new Literal(contextWriter.toString()));

        attributes.put("auraInitSync", Json.serialize(auraInit));

        Component template = instanceService.getInstance(templateDef.getDescriptor(), attributes);
        renderingService.render(template, out);
      }
    } catch (QuickFixException e) {
      throw new AuraRuntimeException(e);
    }
  }