Search in sources :

Example 16 with DynaActionForm

use of org.apache.struts.action.DynaActionForm in project sonarqube by SonarSource.

the class TestRequestUtils method testCreateActionForm3a.

// Default module -- Dynamic ActionForm should be created
public void testCreateActionForm3a() {
    request.setPathElements("/myapp", "/dynamic.do", null, null);
    ActionMapping mapping = (ActionMapping) moduleConfig.findActionConfig("/dynamic");
    assertNotNull("Found /dynamic mapping", mapping);
    assertNotNull("Mapping has non-null name", mapping.getName());
    assertEquals("Mapping has correct name", "dynamic", mapping.getName());
    assertNotNull("AppConfig has form bean " + mapping.getName(), moduleConfig.findFormBeanConfig(mapping.getName()));
    ActionForm form = RequestUtils.createActionForm(request, mapping, moduleConfig, null);
    assertNotNull("ActionForm returned", form);
    assertTrue("ActionForm of correct type", form instanceof DynaActionForm);
}
Also used : ActionMapping(org.apache.struts.action.ActionMapping) DynaActionForm(org.apache.struts.action.DynaActionForm) ActionForm(org.apache.struts.action.ActionForm) DynaActionForm(org.apache.struts.action.DynaActionForm)

Example 17 with DynaActionForm

use of org.apache.struts.action.DynaActionForm in project sonar-java by SonarSource.

the class TestRequestUtils method testCreateActionForm4a.

// Default module -- Dynamic ActionForm with initializers
public void testCreateActionForm4a() {
    // Retrieve an appropriately configured DynaActionForm instance
    request.setPathElements("/myapp", "/dynamic0.do", null, null);
    ActionMapping mapping = (ActionMapping) moduleConfig.findActionConfig("/dynamic0");
    assertNotNull("Found /dynamic0 mapping", mapping);
    assertNotNull("Mapping has non-null name", mapping.getName());
    assertEquals("Mapping has correct name", "dynamic0", mapping.getName());
    assertNotNull("AppConfig has form bean " + mapping.getName(), moduleConfig.findFormBeanConfig(mapping.getName()));
    ActionForm form = RequestUtils.createActionForm(request, mapping, moduleConfig, null);
    assertNotNull("ActionForm returned", form);
    assertTrue("ActionForm of correct type", form instanceof DynaActionForm);
    // Validate the property values
    DynaActionForm dform = (DynaActionForm) form;
    Boolean booleanProperty = (Boolean) dform.get("booleanProperty");
    assertTrue("booleanProperty is true", booleanProperty.booleanValue());
    String stringProperty = (String) dform.get("stringProperty");
    assertEquals("stringProperty is correct", "String Property", stringProperty);
    Object value = null;
    value = dform.get("intArray1");
    assertNotNull("intArray1 exists", value);
    assertTrue("intArray1 is int[]", value instanceof int[]);
    int[] intArray1 = (int[]) value;
    assertEquals("intArray1 length is correct", 3, intArray1.length);
    assertEquals("intArray1[0] value is correct", 1, intArray1[0]);
    assertEquals("intArray1[1] value is correct", 2, intArray1[1]);
    assertEquals("intArray1[2] value is correct", 3, intArray1[2]);
    value = dform.get("intArray2");
    assertNotNull("intArray2 exists", value);
    assertTrue("intArray2 is int[]", value instanceof int[]);
    int[] intArray2 = (int[]) value;
    assertEquals("intArray2 length is correct", 5, intArray2.length);
    assertEquals("intArray2[0] value is correct", 0, intArray2[0]);
    assertEquals("intArray2[1] value is correct", 0, intArray2[1]);
    assertEquals("intArray2[2] value is correct", 0, intArray2[2]);
    assertEquals("intArray2[3] value is correct", 0, intArray2[3]);
    assertEquals("intArray2[4] value is correct", 0, intArray2[4]);
    value = dform.get("principal");
    assertNotNull("principal exists", value);
    assertTrue("principal is MockPrincipal", value instanceof MockPrincipal);
    value = dform.get("stringArray1");
    assertNotNull("stringArray1 exists", value);
    assertTrue("stringArray1 is int[]", value instanceof String[]);
    String[] stringArray1 = (String[]) value;
    assertEquals("stringArray1 length is correct", 3, stringArray1.length);
    assertEquals("stringArray1[0] value is correct", "aaa", stringArray1[0]);
    assertEquals("stringArray1[1] value is correct", "bbb", stringArray1[1]);
    assertEquals("stringArray1[2] value is correct", "ccc", stringArray1[2]);
    value = dform.get("stringArray2");
    assertNotNull("stringArray2 exists", value);
    assertTrue("stringArray2 is int[]", value instanceof String[]);
    String[] stringArray2 = (String[]) value;
    assertEquals("stringArray2 length is correct", 3, stringArray2.length);
    assertEquals("stringArray2[0] value is correct", new String(), stringArray2[0]);
    assertEquals("stringArray2[1] value is correct", new String(), stringArray2[1]);
    assertEquals("stringArray2[2] value is correct", new String(), stringArray2[2]);
    // Different form beans should get different property value instances
    Object value1 = null;
    DynaActionForm dform1 = (DynaActionForm) RequestUtils.createActionForm(request, mapping, moduleConfig, null);
    value = dform.get("principal");
    value1 = dform1.get("principal");
    assertEquals("Different form beans get equal instance values", value, value1);
    assertTrue("Different form beans get different instances 1", value != value1);
    value = dform.get("stringArray1");
    value1 = dform1.get("stringArray1");
    assertTrue("Different form beans get different instances 2", value != value1);
    dform1.set("stringProperty", "Different stringProperty value");
    value = dform.get("stringProperty");
    value1 = dform1.get("stringProperty");
    assertTrue("Different form beans get different instances 3", value != value1);
}
Also used : ActionMapping(org.apache.struts.action.ActionMapping) DynaActionForm(org.apache.struts.action.DynaActionForm) ActionForm(org.apache.struts.action.ActionForm) DynaActionForm(org.apache.struts.action.DynaActionForm) MockPrincipal(org.apache.struts.mock.MockPrincipal)

Example 18 with DynaActionForm

use of org.apache.struts.action.DynaActionForm in project iaf by ibissource.

the class ActionBase method getPersistentForm.

protected DynaActionForm getPersistentForm(ActionMapping mapping, ActionForm form, HttpServletRequest request) {
    if (form == null) {
        log.debug(" Creating new FormBean under key " + mapping.getAttribute());
        form = new DynaActionForm();
        if ("request".equals(mapping.getScope())) {
            request.setAttribute(mapping.getAttribute(), form);
        } else {
            session.setAttribute(mapping.getAttribute(), form);
        }
    }
    return (DynaActionForm) form;
}
Also used : DynaActionForm(org.apache.struts.action.DynaActionForm)

Example 19 with DynaActionForm

use of org.apache.struts.action.DynaActionForm in project iaf by ibissource.

the class ShowMonitors method executeSub.

public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // Initialize action
    initAction(request);
    if (ibisManager == null)
        return (mapping.findForward("noIbisContext"));
    String forward = null;
    DynaActionForm monitorForm = getPersistentForm(mapping, form, request);
    if (isCancelled(request)) {
        log.debug("edit is canceled");
        forward = determineExitForward(monitorForm);
    } else {
        // debugFormData(request,form);
        String action = request.getParameter("action");
        String indexStr = request.getParameter("index");
        String triggerIndexStr = request.getParameter("triggerIndex");
        int index = -1;
        if (StringUtils.isNotEmpty(indexStr)) {
            index = Integer.parseInt(indexStr);
        }
        int triggerIndex = -1;
        if (StringUtils.isNotEmpty(triggerIndexStr)) {
            triggerIndex = Integer.parseInt(triggerIndexStr);
        }
        MonitorManager mm = MonitorManager.getInstance();
        if ("getStatus".equals(action)) {
            response.setContentType("text/xml");
            PrintWriter out = response.getWriter();
            out.print(mm.getStatusXml().toXML());
            out.close();
            return null;
        }
        Lock lock = mm.getStructureLock();
        try {
            lock.acquireExclusive();
            forward = performAction(monitorForm, action, index, triggerIndex, response);
            log.debug("forward [" + forward + "] returned from performAction");
            mm.reconfigure();
        } catch (Exception e) {
            error("could not perform action [" + action + "] on monitorIndex [" + index + "] triggerIndex [" + triggerIndex + "]", e);
        } finally {
            lock.releaseExclusive();
        }
        if (response.isCommitted()) {
            return null;
        }
    }
    if (StringUtils.isEmpty(forward)) {
        log.debug("replacing empty forward with [success]");
        forward = "success";
    }
    initForm(monitorForm);
    ActionForward af = mapping.findForward(forward);
    if (af == null) {
        throw new ServletException("could not find forward [" + forward + "]");
    }
    // Forward control to the specified success URI
    log.debug("forward to [" + forward + "], path [" + af.getPath() + "]");
    return (af);
}
Also used : ServletException(javax.servlet.ServletException) MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) DynaActionForm(org.apache.struts.action.DynaActionForm) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) MonitorException(nl.nn.adapterframework.monitoring.MonitorException) ActionForward(org.apache.struts.action.ActionForward) PrintWriter(java.io.PrintWriter) Lock(nl.nn.adapterframework.util.Lock)

Example 20 with DynaActionForm

use of org.apache.struts.action.DynaActionForm in project iaf by ibissource.

the class TestService method executeSub.

public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // Initialize action
    initAction(request);
    DynaActionForm serviceTestForm = getPersistentForm(mapping, form, request);
    Iterator it = ServiceDispatcher.getInstance().getRegisteredListenerNames();
    List services = new ArrayList();
    services.add("----- select a service -----");
    while (it.hasNext()) {
        services.add((String) it.next());
    }
    serviceTestForm.set("services", services);
    // Forward control to the specified success URI
    log.debug("forward to success");
    return (mapping.findForward("success"));
}
Also used : DynaActionForm(org.apache.struts.action.DynaActionForm) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

DynaActionForm (org.apache.struts.action.DynaActionForm)20 ActionForm (org.apache.struts.action.ActionForm)8 ActionMapping (org.apache.struts.action.ActionMapping)6 IOException (java.io.IOException)5 ServletException (javax.servlet.ServletException)5 ActionForward (org.apache.struts.action.ActionForward)4 ArrayList (java.util.ArrayList)3 Cookie (javax.servlet.http.Cookie)3 StringTagger (nl.nn.adapterframework.util.StringTagger)3 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 List (java.util.List)2 IbisAppenderWrapper (nl.nn.adapterframework.extensions.log4j.IbisAppenderWrapper)2 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)2 Appender (org.apache.log4j.Appender)2 Logger (org.apache.log4j.Logger)2 MockPrincipal (org.apache.struts.mock.MockPrincipal)2 FormFile (org.apache.struts.upload.FormFile)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 PrintWriter (java.io.PrintWriter)1