Search in sources :

Example 1 with Dispatcher

use of org.apache.struts2.dispatcher.Dispatcher in project onebusaway-application-modules by camsys.

the class UrlFunction method url.

public static String url(String value) {
    Dispatcher instance = Dispatcher.getInstance();
    if (instance == null)
        return null;
    Container container = instance.getContainer();
    UrlFunction function = new UrlFunction();
    container.inject(function);
    return function.getUrl(value);
}
Also used : Container(com.opensymphony.xwork2.inject.Container) Dispatcher(org.apache.struts2.dispatcher.Dispatcher)

Example 2 with Dispatcher

use of org.apache.struts2.dispatcher.Dispatcher in project onebusaway-application-modules by camsys.

the class ResourceUrlFunction method resource.

public static String resource(String resourcePath) {
    Dispatcher instance = Dispatcher.getInstance();
    if (instance == null)
        return null;
    Container container = instance.getContainer();
    ResourceUrlFunction function = new ResourceUrlFunction();
    container.inject(function);
    return function.getExternalUrlForResource(resourcePath);
}
Also used : Container(com.opensymphony.xwork2.inject.Container) Dispatcher(org.apache.struts2.dispatcher.Dispatcher)

Example 3 with Dispatcher

use of org.apache.struts2.dispatcher.Dispatcher in project dhis2-core by dhis2.

the class DetectingSystemAuthoritiesProvider method getSystemAuthorities.

// -------------------------------------------------------------------------
// SystemAuthoritiesProvider implementation
// -------------------------------------------------------------------------
@Override
public Collection<String> getSystemAuthorities() {
    Dispatcher instance = Dispatcher.getInstance();
    if (instance == null) {
        return emptyList();
    }
    HashSet<String> authorities = new HashSet<>();
    Configuration configuration = instance.getConfigurationManager().getConfiguration();
    for (PackageConfig packageConfig : configuration.getPackageConfigs().values()) {
        for (ActionConfig actionConfig : packageConfig.getActionConfigs().values()) {
            authorities.addAll(requiredAuthoritiesProvider.getAllAuthorities(actionConfig));
        }
    }
    return authorities;
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) Configuration(com.opensymphony.xwork2.config.Configuration) Dispatcher(org.apache.struts2.dispatcher.Dispatcher) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) HashSet(java.util.HashSet)

Example 4 with Dispatcher

use of org.apache.struts2.dispatcher.Dispatcher in project entando-core by entando.

the class ApsAdminBaseTestCase method setUp.

@Override
protected void setUp() throws Exception {
    boolean refresh = false;
    if (null == applicationContext) {
        // Link the servlet context and the Spring context
        servletContext = new MockServletContext("", new FileSystemResourceLoader());
        applicationContext = this.getConfigUtils().createApplicationContext(servletContext);
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext);
    } else {
        refresh = true;
    }
    RequestContext reqCtx = BaseTestCase.createRequestContext(applicationContext, servletContext);
    this.request = new MockHttpServletRequest();
    this.request.setAttribute(RequestContext.REQCTX, reqCtx);
    this.response = new MockHttpServletResponse();
    this.request.setSession(new MockHttpSession(servletContext));
    if (refresh) {
        try {
            ApsWebApplicationUtils.executeSystemRefresh(this.request);
            this.waitNotifyingThread();
        } catch (Throwable e) {
        }
    }
    // Use spring as the object factory for Struts
    StrutsSpringObjectFactory ssf = new StrutsSpringObjectFactory(null, null, null, null, servletContext, null, this.createContainer());
    ssf.setApplicationContext(applicationContext);
    // Dispatcher is the guy that actually handles all requests.  Pass in
    // an empty Map as the parameters but if you want to change stuff like
    // what config files to read, you need to specify them here
    // (see Dispatcher's source code)
    java.net.URL url = ClassLoader.getSystemResource("struts.properties");
    Properties props = new Properties();
    props.load(url.openStream());
    this.setInitParameters(props);
    Map params = new HashMap(props);
    this.dispatcher = new Dispatcher(servletContext, params);
    this.dispatcher.init();
    Dispatcher.setInstance(this.dispatcher);
}
Also used : HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) FileSystemResourceLoader(org.springframework.core.io.FileSystemResourceLoader) Properties(java.util.Properties) Dispatcher(org.apache.struts2.dispatcher.Dispatcher) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpSession(org.springframework.mock.web.MockHttpSession) StrutsSpringObjectFactory(org.apache.struts2.spring.StrutsSpringObjectFactory) RequestContext(com.agiletec.aps.system.RequestContext) HashMap(java.util.HashMap) Map(java.util.Map) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 5 with Dispatcher

use of org.apache.struts2.dispatcher.Dispatcher in project entando-core by entando.

the class Struts2ServletDispatcher method init.

@Override
public void init(ServletConfig filterConfig) throws ServletException {
    InitOperations init = new InitOperations();
    Dispatcher dispatcher = null;
    try {
        ServletHostConfig config = new ServletHostConfig(filterConfig);
        init.initLogging(config);
        dispatcher = init.initDispatcher(config);
        init.initStaticContentLoader(config, dispatcher);
        prepare = new PrepareOperations(dispatcher);
        execute = new ExecuteOperations(dispatcher);
    } finally {
        if (dispatcher != null) {
            dispatcher.cleanUpAfterInit();
        }
        init.cleanup();
    }
}
Also used : PrepareOperations(com.agiletec.apsadmin.system.dispatcher.PrepareOperations) InitOperations(com.agiletec.apsadmin.system.dispatcher.InitOperations) ExecuteOperations(org.apache.struts2.dispatcher.ExecuteOperations) Dispatcher(org.apache.struts2.dispatcher.Dispatcher) ServletHostConfig(org.apache.struts2.dispatcher.servlet.ServletHostConfig)

Aggregations

Dispatcher (org.apache.struts2.dispatcher.Dispatcher)10 Container (com.opensymphony.xwork2.inject.Container)3 RequestContext (com.agiletec.aps.system.RequestContext)2 HashMap (java.util.HashMap)2 ExecuteOperations (org.apache.struts2.dispatcher.ExecuteOperations)2 InitOperations (com.agiletec.apsadmin.system.dispatcher.InitOperations)1 PrepareOperations (com.agiletec.apsadmin.system.dispatcher.PrepareOperations)1 Configuration (com.opensymphony.xwork2.config.Configuration)1 ConfigurationManager (com.opensymphony.xwork2.config.ConfigurationManager)1 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)1 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ServletException (javax.servlet.ServletException)1 FilterDispatcher (org.apache.struts2.dispatcher.FilterDispatcher)1 FilterHostConfig (org.apache.struts2.dispatcher.filter.FilterHostConfig)1 ActionMapper (org.apache.struts2.dispatcher.mapper.ActionMapper)1 ActionMapping (org.apache.struts2.dispatcher.mapper.ActionMapping)1 ServletHostConfig (org.apache.struts2.dispatcher.servlet.ServletHostConfig)1