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");
}
}
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");
}
}
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");
}
}
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");
}
}
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");
}
}
Aggregations