Search in sources :

Example 1 with OpenSessionInViewFilter

use of org.springframework.orm.hibernate3.support.OpenSessionInViewFilter in project opennms by OpenNMS.

the class AbstractSpringJerseyRestTestCase method setUp.

@Before
public void setUp() throws Throwable {
    beforeServletStart();
    setUser("admin", new String[] { "ROLE_ADMIN" });
    DaoTestConfigBean bean = new DaoTestConfigBean();
    bean.afterPropertiesSet();
    MockDatabase db = new MockDatabase(true);
    DataSourceFactory.setInstance(db);
    XADataSourceFactory.setInstance(db);
    try {
        MockFilterConfig filterConfig = new MockFilterConfig(servletContext, "openSessionInViewFilter");
        setFilter(new OpenSessionInViewFilter());
        getFilter().init(filterConfig);
        // Jersey
        /*
            setServletConfig(new MockServletConfig(servletContext, "dispatcher"));
            getServletConfig().addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
            getServletConfig().addInitParameter("com.sun.jersey.config.property.packages", "org.codehaus.jackson.jaxrs;org.opennms.web.rest;org.opennms.web.rest.config");
            getServletConfig().addInitParameter("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.GZIPContentEncodingFilter");
            getServletConfig().addInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters", "com.sun.jersey.api.container.filter.GZIPContentEncodingFilter");
            setDispatcher(new SpringServlet());
            getDispatcher().init(getServletConfig());
            */
        // Apache CXF
        setServletConfig(new MockServletConfig(servletContext, "dispatcher"));
        getServletConfig().addInitParameter("config-location", m_cxfContextPath);
        CXFServlet servlet = new CXFServlet();
        setDispatcher(servlet);
        getDispatcher().init(getServletConfig());
    } catch (ServletException se) {
        throw se.getRootCause();
    }
    afterServletStart();
    System.err.println("------------------------------------------------------------------------------");
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) OpenSessionInViewFilter(org.springframework.orm.hibernate3.support.OpenSessionInViewFilter) ServletException(javax.servlet.ServletException) MockDatabase(org.opennms.core.test.db.MockDatabase) MockServletConfig(org.springframework.mock.web.MockServletConfig) CXFServlet(org.apache.cxf.transport.servlet.CXFServlet) MockFilterConfig(org.springframework.mock.web.MockFilterConfig) Before(org.junit.Before)

Example 2 with OpenSessionInViewFilter

use of org.springframework.orm.hibernate3.support.OpenSessionInViewFilter in project opennms by OpenNMS.

the class HttpRemotingContextIT method testLoadContext.

public void testLoadContext() throws Throwable {
    DaoTestConfigBean bean = new DaoTestConfigBean();
    bean.afterPropertiesSet();
    MockDatabase db = new MockDatabase(true);
    DataSourceFactory.setInstance(db);
    servletContext = new MockServletContext("file:src/main/webapp");
    servletContext.addInitParameter("contextConfigLocation", "classpath:/META-INF/opennms/applicationContext-commonConfigs.xml " + "classpath:/META-INF/opennms/applicationContext-soa.xml " + "classpath:/META-INF/opennms/applicationContext-mockDao.xml " + "classpath*:/META-INF/opennms/component-service.xml " + "classpath*:/META-INF/opennms/component-dao.xml " + // Contexts within this project
    "/WEB-INF/applicationContext-common.xml " + "/WEB-INF/applicationContext-serviceRegistryRemoting.xml " + "/WEB-INF/applicationContext-spring-security.xml " + "/WEB-INF/applicationContext-svclayer.xml ");
    servletContext.addInitParameter("parentContextKey", "daoContext");
    ServletContextEvent e = new ServletContextEvent(servletContext);
    contextListener = new ContextLoaderListener();
    contextListener.contextInitialized(e);
    servletContext.setContextPath(contextPath);
    servletConfig = new MockServletConfig(servletContext, "dispatcher");
    servletConfig.addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
    servletConfig.addInitParameter("com.sun.jersey.config.property.packages", "org.opennms.web.rest");
    try {
        MockFilterConfig filterConfig = new MockFilterConfig(servletContext, "openSessionInViewFilter");
        filter = new OpenSessionInViewFilter();
        filter.init(filterConfig);
    } catch (ServletException se) {
        throw se.getRootCause();
    }
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) OpenSessionInViewFilter(org.springframework.orm.hibernate3.support.OpenSessionInViewFilter) ServletException(javax.servlet.ServletException) MockDatabase(org.opennms.core.test.db.MockDatabase) MockServletConfig(org.springframework.mock.web.MockServletConfig) ContextLoaderListener(org.springframework.web.context.ContextLoaderListener) MockServletContext(org.springframework.mock.web.MockServletContext) ServletContextEvent(javax.servlet.ServletContextEvent) MockFilterConfig(org.springframework.mock.web.MockFilterConfig)

Example 3 with OpenSessionInViewFilter

use of org.springframework.orm.hibernate3.support.OpenSessionInViewFilter in project mzzb-server by mingzuozhibi.

the class WebMvcConfig method filterRegistrationBean.

@Bean
public FilterRegistrationBean filterRegistrationBean() {
    FilterRegistrationBean bean = new FilterRegistrationBean();
    bean.setUrlPatterns(Collections.singletonList("/api/*"));
    bean.setFilter(new OpenSessionInViewFilter());
    LOGGER.info("已成功配置OpenSessionInViewFilter");
    return bean;
}
Also used : OpenSessionInViewFilter(org.springframework.orm.hibernate5.support.OpenSessionInViewFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

ServletException (javax.servlet.ServletException)2 MockDatabase (org.opennms.core.test.db.MockDatabase)2 DaoTestConfigBean (org.opennms.test.DaoTestConfigBean)2 MockFilterConfig (org.springframework.mock.web.MockFilterConfig)2 MockServletConfig (org.springframework.mock.web.MockServletConfig)2 OpenSessionInViewFilter (org.springframework.orm.hibernate3.support.OpenSessionInViewFilter)2 ServletContextEvent (javax.servlet.ServletContextEvent)1 CXFServlet (org.apache.cxf.transport.servlet.CXFServlet)1 Before (org.junit.Before)1 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)1 Bean (org.springframework.context.annotation.Bean)1 MockServletContext (org.springframework.mock.web.MockServletContext)1 OpenSessionInViewFilter (org.springframework.orm.hibernate5.support.OpenSessionInViewFilter)1 ContextLoaderListener (org.springframework.web.context.ContextLoaderListener)1