public void testCharacterEncodingSetBeforeRequestWrappingAndActionService() throws Exception {
    MockServletContext servletContext = new MockServletContext();
    MockFilterConfig filterConfig = new MockFilterConfig(servletContext);
    MockHttpServletRequest req = new MockHttpServletRequest(servletContext);
    MockHttpServletResponse res = new MockHttpServletResponse();
    MockFilterChain chain = new MockFilterChain();
    final InnerDispatcher _dispatcher = new InnerDispatcher(servletContext);
    Dispatcher.setInstance(null);

    _dispatcher.setDefaultEncoding("UTF-16_DUMMY");

    FilterDispatcher filter =
        new FilterDispatcher() {
          protected Dispatcher createDispatcher(FilterConfig filterConfig) {
            return _dispatcher;
          }
        };
    filter.init(filterConfig);
    // set ActionMapper after init() as all dependencies will be injected in init()
    filter.setActionMapper(new InnerActionMapper());
    _dispatcher.setDefaultEncoding("UTF-16_DUMMY");
    filter.doFilter(req, res, chain);

    assertTrue(_dispatcher.wrappedRequest);
    assertTrue(_dispatcher.serviceRequest);
  }
Example #2
0
 /** Cleans up a request of thread locals */
 public void cleanupRequest(HttpServletRequest request) {
   Integer counterVal = (Integer) request.getAttribute(CLEANUP_RECURSION_COUNTER);
   if (counterVal != null) {
     counterVal -= 1;
     request.setAttribute(CLEANUP_RECURSION_COUNTER, counterVal);
     if (counterVal > 0) {
       if (log.isDebugEnabled()) {
         log.debug("skipping cleanup counter=" + counterVal);
       }
       return;
     }
   }
   // always clean up the thread request, even if an action hasn't been executed
   try {
     dispatcher.cleanUpRequest(request);
   } catch (IOException e) {
     if (LOG.isWarnEnabled()) {
       LOG.warn(
           "Cannot clean up the request, some files can still remain in #0 after upload!",
           e,
           StrutsConstants.STRUTS_MULTIPART_SAVEDIR);
     }
   } finally {
     ActionContext.setContext(null);
     Dispatcher.setInstance(null);
   }
 }
  public void testIfActionMapperIsNullDontServiceAction() throws Exception {
    MockServletContext servletContext = new MockServletContext();
    MockFilterConfig filterConfig = new MockFilterConfig(servletContext);
    MockHttpServletRequest req = new MockHttpServletRequest(servletContext);
    MockHttpServletResponse res = new MockHttpServletResponse();
    MockFilterChain chain = new MockFilterChain();
    final NoOpDispatcher _dispatcher = new NoOpDispatcher(servletContext);
    ConfigurationManager confManager = new ConfigurationManager();
    confManager.setConfiguration(new DefaultConfiguration());
    _dispatcher.setConfigurationManager(confManager);
    Dispatcher.setInstance(_dispatcher);

    FilterDispatcher filter =
        new FilterDispatcher() {
          protected Dispatcher createDispatcher() {
            return _dispatcher;
          }
        };
    filter.init(filterConfig);
    filter.setActionMapper(null);
    filter.doFilter(req, res, chain);

    assertFalse(_dispatcher.serviceRequest);
  }
Example #4
0
 /** Assigns the dispatcher to the dispatcher thread local */
 public void assignDispatcherToThread() {
   Dispatcher.setInstance(dispatcher);
 }