Search in sources :

Example 41 with ServiceName

use of jp.ossc.nimbus.core.ServiceName in project nimbus by nimbus-org.

the class SelectableServletFilterInterceptorChainListServiceTest method test1.

public void test1() throws Throwable {
    ServletRequest request = new DummyHttpServletRequest();
    ServletResponse response = new DummyHttpServletResponse();
    FilterChain chain = new DummyFilterChain();
    ServletFilterInvocationContext context = new ServletFilterInvocationContext(request, response, chain);
    final Interceptor interceptor1 = new TestInterceptor();
    final Interceptor interceptor2 = new TestInterceptor();
    ServiceManagerFactory.registerManager("Test");
    ServiceManagerFactory.registerService("Test", "DefaultChainList", new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2 }));
    SelectableServletFilterInterceptorChainListService chainList = new SelectableServletFilterInterceptorChainListService();
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        ServiceManagerFactory.findManager("Test").startAllService();
        chainList.setDefaultInterceptorChainListServiceName(new ServiceName("Test", "DefaultChainList"));
        chainList.create();
        chainList.start();
        assertEquals(interceptor1, chainList.getInterceptor(context, 0));
        assertEquals(interceptor2, chainList.getInterceptor(context, 1));
    } finally {
        chainList.stop();
        chainList.destroy();
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : ServletRequest(javax.servlet.ServletRequest) ServletResponse(javax.servlet.ServletResponse) ServiceName(jp.ossc.nimbus.core.ServiceName) FilterChain(javax.servlet.FilterChain)

Example 42 with ServiceName

use of jp.ossc.nimbus.core.ServiceName in project nimbus by nimbus-org.

the class SelectableServletFilterInterceptorChainListServiceTest method test2.

public void test2() throws Throwable {
    DummyHttpServletRequest request = new DummyHttpServletRequest();
    DummyHttpServletResponse response = new DummyHttpServletResponse();
    FilterChain chain = new DummyFilterChain();
    ServletFilterInvocationContext context = new ServletFilterInvocationContext(request, response, chain);
    final Interceptor interceptor1 = new TestInterceptor();
    final Interceptor interceptor2 = new TestInterceptor();
    final Interceptor interceptor3 = new TestInterceptor();
    final Interceptor interceptor4 = new TestInterceptor();
    ServiceManagerFactory.registerManager("Test");
    ServiceManagerFactory.registerService("Test", "DefaultChainList", new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2 }));
    ServiceManagerFactory.registerService("Test", "ChainList1", new DefaultInterceptorChainList(new Interceptor[] { interceptor3, interceptor4 }));
    SelectableServletFilterInterceptorChainListService chainList = new SelectableServletFilterInterceptorChainListService();
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        ServiceManagerFactory.findManager("Test").startAllService();
        Properties enabledURLMapping = new Properties();
        enabledURLMapping.setProperty("http://nimbus.ossc.jp/hoge/fuga/.*\\.html", "Test#ChainList1");
        chainList.setEnabledURLMapping(enabledURLMapping);
        chainList.setDefaultInterceptorChainListServiceName(new ServiceName("Test", "DefaultChainList"));
        chainList.create();
        chainList.start();
        request.setScheme("http");
        request.setServerName("nimbus.ossc.jp");
        request.setRequestURI("/hoge/fuga/a.html");
        assertEquals(interceptor3, chainList.getInterceptor(context, 0));
        assertEquals(interceptor4, chainList.getInterceptor(context, 1));
        request.setRequestURI("/hoge/fuga2/a.html");
        assertEquals(interceptor1, chainList.getInterceptor(context, 0));
        assertEquals(interceptor2, chainList.getInterceptor(context, 1));
    } finally {
        chainList.stop();
        chainList.destroy();
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : ServiceName(jp.ossc.nimbus.core.ServiceName) FilterChain(javax.servlet.FilterChain) Properties(java.util.Properties)

Example 43 with ServiceName

use of jp.ossc.nimbus.core.ServiceName in project nimbus by nimbus-org.

the class SelectableServletFilterInterceptorChainListServiceTest method test5.

public void test5() throws Throwable {
    DummyHttpServletRequest request = new DummyHttpServletRequest();
    DummyHttpServletResponse response = new DummyHttpServletResponse();
    FilterChain chain = new DummyFilterChain();
    ServletFilterInvocationContext context = new ServletFilterInvocationContext(request, response, chain);
    final Interceptor interceptor1 = new TestInterceptor();
    final Interceptor interceptor2 = new TestInterceptor();
    final Interceptor interceptor3 = new TestInterceptor();
    final Interceptor interceptor4 = new TestInterceptor();
    ServiceManagerFactory.registerManager("Test");
    ServiceManagerFactory.registerService("Test", "DefaultChainList", new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2 }));
    ServiceManagerFactory.registerService("Test", "ChainList1", new DefaultInterceptorChainList(new Interceptor[] { interceptor3, interceptor4 }));
    SelectableServletFilterInterceptorChainListService chainList = new SelectableServletFilterInterceptorChainListService();
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        ServiceManagerFactory.findManager("Test").startAllService();
        Properties disabledURIMapping = new Properties();
        disabledURIMapping.setProperty("/hoge/fuga/.*\\.html", "Test#ChainList1");
        chainList.setDisabledURIMapping(disabledURIMapping);
        chainList.setDefaultInterceptorChainListServiceName(new ServiceName("Test", "DefaultChainList"));
        chainList.create();
        chainList.start();
        request.setRequestURI("/hoge/fuga/a.html");
        assertEquals(interceptor1, chainList.getInterceptor(context, 0));
        assertEquals(interceptor2, chainList.getInterceptor(context, 1));
        request.setRequestURI("/hoge/fuga2/a.html");
        assertEquals(interceptor3, chainList.getInterceptor(context, 0));
        assertEquals(interceptor4, chainList.getInterceptor(context, 1));
    } finally {
        chainList.stop();
        chainList.destroy();
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : ServiceName(jp.ossc.nimbus.core.ServiceName) FilterChain(javax.servlet.FilterChain) Properties(java.util.Properties)

Example 44 with ServiceName

use of jp.ossc.nimbus.core.ServiceName in project nimbus by nimbus-org.

the class SelectableServletFilterInterceptorChainListServiceTest method test6.

public void test6() throws Throwable {
    DummyHttpServletRequest request = new DummyHttpServletRequest();
    DummyHttpServletResponse response = new DummyHttpServletResponse();
    FilterChain chain = new DummyFilterChain();
    ServletFilterInvocationContext context = new ServletFilterInvocationContext(request, response, chain);
    final Interceptor interceptor1 = new TestInterceptor();
    final Interceptor interceptor2 = new TestInterceptor();
    final Interceptor interceptor3 = new TestInterceptor();
    final Interceptor interceptor4 = new TestInterceptor();
    ServiceManagerFactory.registerManager("Test");
    ServiceManagerFactory.registerService("Test", "DefaultChainList", new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2 }));
    ServiceManagerFactory.registerService("Test", "ChainList1", new DefaultInterceptorChainList(new Interceptor[] { interceptor3, interceptor4 }));
    SelectableServletFilterInterceptorChainListService chainList = new SelectableServletFilterInterceptorChainListService();
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        ServiceManagerFactory.findManager("Test").startAllService();
        Properties enabledPathMapping = new Properties();
        enabledPathMapping.setProperty("/fuga/.*\\.html", "Test#ChainList1");
        chainList.create();
        chainList.setEnabledPathMapping(enabledPathMapping);
        chainList.setDefaultInterceptorChainListServiceName(new ServiceName("Test", "DefaultChainList"));
        chainList.start();
        request.setPathInfo("/fuga/a.html");
        assertEquals(interceptor3, chainList.getInterceptor(context, 0));
        assertEquals(interceptor4, chainList.getInterceptor(context, 1));
        request.setPathInfo(null);
        request.setServletPath("/fuga/a.html");
        assertEquals(interceptor3, chainList.getInterceptor(context, 0));
        assertEquals(interceptor4, chainList.getInterceptor(context, 1));
        request.setServletPath(null);
        request.setPathInfo("/fuga2/a.html");
        assertEquals(interceptor1, chainList.getInterceptor(context, 0));
        assertEquals(interceptor2, chainList.getInterceptor(context, 1));
    } finally {
        chainList.stop();
        chainList.destroy();
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : ServiceName(jp.ossc.nimbus.core.ServiceName) FilterChain(javax.servlet.FilterChain) Properties(java.util.Properties)

Example 45 with ServiceName

use of jp.ossc.nimbus.core.ServiceName in project nimbus by nimbus-org.

the class ContextImportInterceptorServiceTest method test1.

public void test1() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    ServiceManagerFactory.registerService("Test", "Context", new DefaultContextService());
    Interceptor interceptor1 = new Interceptor() {

        public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
            Map importContext = new HashMap();
            importContext.put("A", "100");
            importContext.put("B", "200");
            context.setAttribute(ContextImportInterceptorService.DEFAULT_ATTRIBUTE_NAME, importContext);
            return chain.invokeNext(context);
        }
    };
    ContextImportInterceptorService interceptor2 = new ContextImportInterceptorService();
    ServiceManagerFactory.registerService("Test", "ContextImportInterceptor", interceptor2);
    Interceptor interceptor3 = new Interceptor() {

        public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
            Context ctx = (Context) ServiceManagerFactory.getServiceObject("Test", "Context");
            assertEquals(2, ctx.size());
            assertEquals("100", ctx.get("A"));
            assertEquals("200", ctx.get("B"));
            return chain.invokeNext(context);
        }
    };
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        interceptor2.setContextServiceName(new ServiceName("Test", "Context"));
        ServiceManagerFactory.findManager("Test").startAllService();
        new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2, interceptor3 }), null).invokeNext(new DefaultInvocationContext());
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : DefaultInvocationContext(jp.ossc.nimbus.service.aop.DefaultInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) Context(jp.ossc.nimbus.service.context.Context) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) DefaultInvocationContext(jp.ossc.nimbus.service.aop.DefaultInvocationContext) HashMap(java.util.HashMap) ServiceName(jp.ossc.nimbus.core.ServiceName) DefaultContextService(jp.ossc.nimbus.service.context.DefaultContextService) DefaultInvocationContext(jp.ossc.nimbus.service.aop.DefaultInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) HashMap(java.util.HashMap) Map(java.util.Map) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Aggregations

ServiceName (jp.ossc.nimbus.core.ServiceName)66 ServiceNameRef (jp.ossc.nimbus.core.ServiceNameRef)13 ServiceNameEditor (jp.ossc.nimbus.beans.ServiceNameEditor)12 DefaultInterceptorChainList (jp.ossc.nimbus.service.aop.DefaultInterceptorChainList)9 DefaultMethodInvocationContext (jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext)8 Interceptor (jp.ossc.nimbus.service.aop.Interceptor)8 InvocationContext (jp.ossc.nimbus.service.aop.InvocationContext)8 FilterChain (javax.servlet.FilterChain)7 InterceptorChain (jp.ossc.nimbus.service.aop.InterceptorChain)7 Map (java.util.Map)6 Properties (java.util.Properties)6 DefaultInterceptorChain (jp.ossc.nimbus.service.aop.DefaultInterceptorChain)6 HashMap (java.util.HashMap)5 ServiceMetaData (jp.ossc.nimbus.core.ServiceMetaData)5 Invoker (jp.ossc.nimbus.service.aop.Invoker)5 Iterator (java.util.Iterator)4 Method (java.lang.reflect.Method)3 ServletConfig (javax.servlet.ServletConfig)3 DefaultThreadLocalInterceptorChain (jp.ossc.nimbus.service.aop.DefaultThreadLocalInterceptorChain)3 DefaultSemaphoreService (jp.ossc.nimbus.service.semaphore.DefaultSemaphoreService)3