コード例 #1
0
ファイル: BaseActionTestCase.java プロジェクト: slacrey/eduoa
  @Before
  public void onSetUp() {
    smtpPort = smtpPort + (int) (Math.random() * 100);

    LocalizedTextUtil.addDefaultResourceBundle(Constants.BUNDLE_KEY);

    // Initialize ActionContext
    ConfigurationManager configurationManager = new ConfigurationManager();
    configurationManager.addContainerProvider(new XWorkConfigurationProvider());
    Configuration config = configurationManager.getConfiguration();
    Container container = config.getContainer();

    ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
    stack.getContext().put(ActionContext.CONTAINER, container);
    ActionContext.setContext(new ActionContext(stack.getContext()));

    ActionContext.getContext().setSession(new HashMap<String, Object>());

    // change the port on the mailSender so it doesn't conflict with an
    // existing SMTP server on localhost
    JavaMailSenderImpl mailSender = (JavaMailSenderImpl) applicationContext.getBean("mailSender");
    mailSender.setPort(getSmtpPort());
    mailSender.setHost("localhost");

    // populate the request so getRequest().getSession() doesn't fail in BaseAction.java
    ServletActionContext.setRequest(new MockHttpServletRequest());
  }
コード例 #2
0
ファイル: Dispatcher.java プロジェクト: phani6292/struts
  private Container init_PreloadConfiguration() {
    Configuration config = configurationManager.getConfiguration();
    Container container = config.getContainer();

    boolean reloadi18n =
        Boolean.valueOf(container.getInstance(String.class, StrutsConstants.STRUTS_I18N_RELOAD));
    LocalizedTextUtil.setReloadBundles(reloadi18n);

    return container;
  }
コード例 #3
0
ファイル: Dispatcher.java プロジェクト: phani6292/struts
 /**
  * Expose the dependency injection container.
  *
  * @return Our dependency injection container
  */
 public Container getContainer() {
   ConfigurationManager mgr = getConfigurationManager();
   if (mgr == null) {
     throw new IllegalStateException("The configuration manager shouldn't be null");
   } else {
     Configuration config = mgr.getConfiguration();
     if (config == null) {
       throw new IllegalStateException("Unable to load configuration");
     } else {
       return config.getContainer();
     }
   }
 }
コード例 #4
0
ファイル: Dispatcher.java プロジェクト: faithyee/Struts2
 /**
  * Expose the dependency injection container.
  *
  * @return Our dependency injection container
  */
 public Container getContainer() {
   if (ContainerHolder.get() != null) {
     return ContainerHolder.get();
   }
   ConfigurationManager mgr = getConfigurationManager();
   if (mgr == null) {
     throw new IllegalStateException("The configuration manager shouldn't be null");
   } else {
     Configuration config = mgr.getConfiguration();
     if (config == null) {
       throw new IllegalStateException("Unable to load configuration");
     } else {
       Container container = config.getContainer();
       ContainerHolder.store(container);
       return container;
     }
   }
 }
コード例 #5
0
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    mapper = new Restful2ActionMapper();
    mapper.setExtensions("");
    req = new MockHttpServletRequest();
    req.setupGetParameterMap(new HashMap());
    req.setupGetContextPath("/my/namespace");

    config = new DefaultConfiguration();
    PackageConfig pkg = new PackageConfig.Builder("myns").namespace("/my/namespace").build();
    PackageConfig pkg2 = new PackageConfig.Builder("my").namespace("/my").build();
    config.addPackageConfig("mvns", pkg);
    config.addPackageConfig("my", pkg2);
    configManager =
        new ConfigurationManager() {
          public Configuration getConfiguration() {
            return config;
          }
        };
  }
コード例 #6
0
  @Before
  public void onSetUp() {
    smtpPort = (new Random().nextInt(9999 - 1000) + 1000);
    log.debug("SMTP Port set to: " + smtpPort);

    LocalizedTextUtil.addDefaultResourceBundle(Constants.BUNDLE_KEY);

    // Initialize ActionContext
    ConfigurationManager configurationManager = new ConfigurationManager();
    configurationManager.addContainerProvider(new XWorkConfigurationProvider());
    Configuration config = configurationManager.getConfiguration();
    Container container = config.getContainer();

    ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
    stack.getContext().put(ActionContext.CONTAINER, container);
    ActionContext.setContext(new ActionContext(stack.getContext()));

    ActionContext.getContext().setSession(new HashMap<String, Object>());

    // populate the request so getRequest().getProject() doesn't fail in BaseAction.java
    ServletActionContext.setRequest(new MockHttpServletRequest());
  }
  public void testGlobalResultInheritenceTest() throws Exception {
    ConfigurationProvider provider =
        buildConfigurationProvider(
            "com/opensymphony/xwork2/config/providers/xwork-test-global-result-inheritence.xml");

    ConfigurationManager configurationManager = new ConfigurationManager();
    configurationManager.addContainerProvider(new XWorkConfigurationProvider());
    configurationManager.addContainerProvider(provider);
    Configuration configuration = configurationManager.getConfiguration();

    ActionConfig parentActionConfig =
        configuration.getRuntimeConfiguration().getActionConfig("/base", "parentAction");
    ActionConfig anotherActionConfig =
        configuration.getRuntimeConfiguration().getActionConfig("/base", "anotherAction");
    ActionConfig childActionConfig =
        configuration.getRuntimeConfiguration().getActionConfig("/base", "childAction");

    ResultConfig parentResultConfig1 = parentActionConfig.getResults().get("mockResult1");
    ResultConfig parentResultConfig2 = parentActionConfig.getResults().get("mockResult2");
    ResultConfig anotherResultConfig1 = anotherActionConfig.getResults().get("mockResult1");
    ResultConfig anotherResultConfig2 = anotherActionConfig.getResults().get("mockResult2");
    ResultConfig childResultConfig1 = childActionConfig.getResults().get("mockResult1");
    ResultConfig childResultConfig2 = childActionConfig.getResults().get("mockResult2");

    System.out.println(parentResultConfig1.getParams().get("identity"));
    System.out.println(parentResultConfig2.getParams().get("identity"));
    System.out.println(anotherResultConfig1.getParams().get("identity"));
    System.out.println(anotherResultConfig2.getParams().get("identity"));
    System.out.println(childResultConfig1.getParams().get("identity"));
    System.out.println(childResultConfig2.getParams().get("identity"));

    assertFalse(parentResultConfig1 == anotherResultConfig1);
    assertFalse(parentResultConfig2 == anotherResultConfig2);

    assertFalse(parentResultConfig1 == childResultConfig1);
    assertTrue(parentResultConfig2 == childResultConfig2);
  }
コード例 #8
0
ファイル: Dispatcher.java プロジェクト: faithyee/Struts2
  /**
   * Load Action class for mapping and invoke the appropriate Action method, or go directly to the
   * Result.
   *
   * <p>This method first creates the action context from the given parameters, and then loads an
   * <tt>ActionProxy</tt> from the given action name and namespace. After that, the Action method is
   * executed and output channels through the response object. Actions not found are sent back to
   * the user via the {@link Dispatcher#sendError} method, using the 404 return code. All other
   * errors are reported by throwing a ServletException.
   *
   * @param request the HttpServletRequest object
   * @param response the HttpServletResponse object
   * @param mapping the action mapping object
   * @throws ServletException when an unknown error occurs (not a 404, but typically something that
   *     would end up as a 5xx by the servlet container)
   * @param context Our ServletContext object
   */
  public void serviceAction(
      HttpServletRequest request,
      HttpServletResponse response,
      ServletContext context,
      ActionMapping mapping)
      throws ServletException {

    Map<String, Object> extraContext = createContextMap(request, response, mapping, context);

    // If there was a previous value stack, then create a new copy and pass it in to be used by the
    // new Action
    ValueStack stack =
        (ValueStack) request.getAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY);
    boolean nullStack = stack == null;
    if (nullStack) {
      ActionContext ctx = ActionContext.getContext();
      if (ctx != null) {
        stack = ctx.getValueStack();
      }
    }
    if (stack != null) {
      extraContext.put(ActionContext.VALUE_STACK, valueStackFactory.createValueStack(stack));
    }

    String timerKey = "Handling request from Dispatcher";
    try {
      UtilTimerStack.push(timerKey);
      String namespace = mapping.getNamespace();
      String name = mapping.getName();
      String method = mapping.getMethod();

      Configuration config = configurationManager.getConfiguration();
      ActionProxy proxy =
          config
              .getContainer()
              .getInstance(ActionProxyFactory.class)
              .createActionProxy(namespace, name, method, extraContext, true, false);

      request.setAttribute(
          ServletActionContext.STRUTS_VALUESTACK_KEY, proxy.getInvocation().getStack());

      // if the ActionMapping says to go straight to a result, do it!
      if (mapping.getResult() != null) {
        Result result = mapping.getResult();
        result.execute(proxy.getInvocation());
      } else {
        proxy.execute();
      }

      // If there was a previous value stack then set it back onto the request
      if (!nullStack) {
        request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);
      }
    } catch (ConfigurationException e) {
      // WW-2874 Only log error if in devMode
      if (devMode) {
        String reqStr = request.getRequestURI();
        if (request.getQueryString() != null) {
          reqStr = reqStr + "?" + request.getQueryString();
        }
        LOG.error("Could not find action or result\n" + reqStr, e);
      } else {
        if (LOG.isWarnEnabled()) {
          LOG.warn("Could not find action or result", e);
        }
      }
      sendError(request, response, context, HttpServletResponse.SC_NOT_FOUND, e);
    } catch (Exception e) {
      if (handleException || devMode) {
        sendError(request, response, context, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
      } else {
        throw new ServletException(e);
      }
    } finally {
      UtilTimerStack.pop(timerKey);
    }
  }