Search in sources :

Example 6 with ServiceName

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

the class HttpResponseImplTest method testSetObjectByServiceName.

/**
 * HttpResponseのストリームを設定、取得するテスト。
 * <p>
 * 条件:
 * <ul>
 * <li>XMLストリームデータをデータセットに変換して取得する</li>
 * <li>次の内容をDataSetXMLConverterで変換する<BR>
 * <PRE>
 * <?xml version="1.0" encoding="UTF-8"?>
 *  <dataSet>
 *   <schema>
 *    <header name="TestHeader">
 *     :A,java.util.Date,
 *     "jp.ossc.nimbus.util.converter.DateFormatConverter{ConvertType=2;Format="yyyy-MM-DD"}",
 *     "jp.ossc.nimbus.util.converter.DateFormatConverter{ConvertType=1;Format="yyyy-MM-DD"}",
 *     "@value@ != null"
 *     :B,java.lang.String,,,
 *    </header>
 *   </schema>
 *    <header name="TestHeader"><A>2008-01-28</A><B>TestValue</B></header></dataSet>
 * <PRE></li>
 * <li>上記のストリームデータとコンバータをプロパティに設定して、<BR>
 * HttpResponse#getObjectを実行</li>
 * </ul>
 * 確認:
 * <ul>
 * <li>正しい値が返ってくることを確認</li>
 * </ul>
 */
public void testSetObjectByServiceName() {
    try {
        // コンバータサービスの定義ファイルをロード
        if (!ServiceManagerFactory.loadManager("jp/ossc/nimbus/service/http/httpclient/service-conv.xml")) {
            System.exit(-1);
        }
        HttpResponseImpl res = new HttpResponseImpl();
        // CharacterEncodingを設定しておく
        res.headerMap = new HashMap();
        String[] vals = new String[] { "application/xml;charset=Shift_JIS" };
        res.headerMap.put("Content-Type", vals);
        String inxml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<dataSet><schema><header name=\"TestHeader\">" + ":A,java.util.Date," + "\"jp.ossc.nimbus.util.converter.DateFormatConverter{ConvertType=2;Format=\"yyyy-MM-DD\"}\"," + "\"jp.ossc.nimbus.util.converter.DateFormatConverter{ConvertType=1;Format=\"yyyy-MM-DD\"}\"," + "\"@value@ != null\"\n:B,java.lang.String,,," + "</header></schema><header name=\"TestHeader\">" + "<A>2008-01-28</A><B>TestValue</B></header></dataSet>";
        // 入力ストリームとコンバーターサービス名をプロパティにセット
        InputStream is = new ByteArrayInputStream(inxml.getBytes());
        res.setInputStream(is);
        ServiceName name = new ServiceName("DataSetXMLConverter");
        res.setStreamConverterServiceName(name);
        // 
        DataSet dataset = (DataSet) res.getObject();
        assertEquals("TestHeader", dataset.getHeader("TestHeader").getName());
        assertEquals(":A,java.util.Date," + "\"jp.ossc.nimbus.util.converter.DateFormatConverter{ConvertType=2;Format=\"yyyy-MM-DD\"}\"," + "\"jp.ossc.nimbus.util.converter.DateFormatConverter{ConvertType=1;Format=\"yyyy-MM-DD\"}\"," + "\"@value@ != null\"\n:B,java.lang.String,,,", dataset.getHeader("TestHeader").getSchema());
        assertEquals("2008-01-28", dataset.getHeader("TestHeader").getFormatProperty("A"));
        assertEquals("TestValue", dataset.getHeader("TestHeader").getProperty("B"));
    } catch (PropertySchemaDefineException e) {
        e.printStackTrace();
        fail("例外発生");
    } catch (ConvertException e) {
        e.printStackTrace();
        fail("例外発生");
    } finally {
        ServiceManagerFactory.unloadManager("jp/ossc/nimbus/service/http/httpclient/service-conv.xml");
    }
}
Also used : PropertySchemaDefineException(jp.ossc.nimbus.beans.dataset.PropertySchemaDefineException) ConvertException(jp.ossc.nimbus.util.converter.ConvertException) ServiceName(jp.ossc.nimbus.core.ServiceName) DataSet(jp.ossc.nimbus.beans.dataset.DataSet)

Example 7 with ServiceName

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

the class SelectableServletFilterInterceptorChainListServiceTest method test4.

public void test4() 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 enabledURIMapping = new Properties();
        enabledURIMapping.setProperty("/hoge/fuga/.*\\.html", "Test#ChainList1");
        chainList.setEnabledURIMapping(enabledURIMapping);
        chainList.setDefaultInterceptorChainListServiceName(new ServiceName("Test", "DefaultChainList"));
        chainList.create();
        chainList.start();
        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 8 with ServiceName

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

the class SelectableServletFilterInterceptorChainListServiceTest method test3.

public void test3() 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 disabledURLMapping = new Properties();
        disabledURLMapping.setProperty("http://nimbus.ossc.jp/hoge/fuga/.*\\.html", "Test#ChainList1");
        chainList.setDisabledURLMapping(disabledURLMapping);
        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(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 9 with ServiceName

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

the class SelectableServletFilterInterceptorChainListServiceTest method test7.

public void test7() 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 disabledPathMapping = new Properties();
        disabledPathMapping.setProperty("/fuga/.*\\.html", "Test#ChainList1");
        chainList.setDisabledPathMapping(disabledPathMapping);
        chainList.setDefaultInterceptorChainListServiceName(new ServiceName("Test", "DefaultChainList"));
        chainList.create();
        chainList.start();
        request.setPathInfo("/fuga/a.html");
        assertEquals(interceptor1, chainList.getInterceptor(context, 0));
        assertEquals(interceptor2, chainList.getInterceptor(context, 1));
        request.setPathInfo(null);
        request.setServletPath("/fuga/a.html");
        assertEquals(interceptor1, chainList.getInterceptor(context, 0));
        assertEquals(interceptor2, chainList.getInterceptor(context, 1));
        request.setPathInfo("/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 10 with ServiceName

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

the class ContextExportInterceptorServiceTest 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 {
            Context ctx = (Context) ServiceManagerFactory.getServiceObject("Test", "Context");
            ctx.put("A", "100");
            ctx.put("B", "200");
            return chain.invokeNext(context);
        }
    };
    ContextExportInterceptorService interceptor2 = new ContextExportInterceptorService();
    ServiceManagerFactory.registerService("Test", "ContextExportInterceptor", interceptor2);
    Interceptor interceptor3 = new Interceptor() {

        public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
            Map exportedContext = (Map) context.getAttribute(ContextExportInterceptorService.DEFAULT_ATTRIBUTE_NAME);
            assertEquals(2, exportedContext.size());
            assertEquals("100", exportedContext.get("A"));
            assertEquals("200", exportedContext.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) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain) DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) DefaultInvocationContext(jp.ossc.nimbus.service.aop.DefaultInvocationContext) 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) 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