use of jp.ossc.nimbus.core.ServiceMetaData in project nimbus by nimbus-org.
the class MethodJournalInterceptorServiceTest method setUp.
protected void setUp() throws Exception {
ServiceManagerFactory.registerManager("Test");
ServiceMetaData serviceData = new ServiceMetaData();
serviceData.setCode(ThreadManagedJournalService.class.getName());
serviceData.setName("Journal");
AttributeMetaData attr = new AttributeMetaData(serviceData);
attr.setName("EditorFinderName");
attr.setValue("#JournalEditorFinder");
serviceData.addAttribute(attr);
attr = new AttributeMetaData(serviceData);
attr.setName("WritableElementKey");
attr.setValue("MethodJournal");
serviceData.addAttribute(attr);
attr = new AttributeMetaData(serviceData);
attr.setName("CategoryServiceNames");
attr.setValue("#JournalCategory");
serviceData.addAttribute(attr);
serviceData.addDepends(serviceData.createDependsMetaData("Test", "JournalEditorFinder"));
serviceData.addDepends(serviceData.createDependsMetaData("Test", "JournalCategory"));
ServiceManagerFactory.registerService("Test", serviceData);
serviceData = new ServiceMetaData();
serviceData.setCode(SimpleCategoryService.class.getName());
serviceData.setName("JournalCategory");
attr = new AttributeMetaData(serviceData);
attr.setName("MessageWriterServiceName");
attr.setValue("#JournalWriter");
serviceData.addAttribute(attr);
attr = new AttributeMetaData(serviceData);
attr.setName("WritableRecordFactoryServiceName");
attr.setValue("#JournalWritableRecordFactory");
serviceData.addAttribute(attr);
serviceData.addDepends(serviceData.createDependsMetaData("Test", "JournalWriter"));
serviceData.addDepends(serviceData.createDependsMetaData("Test", "JournalWritableRecordFactory"));
ServiceManagerFactory.registerService("Test", serviceData);
serviceData = new ServiceMetaData();
serviceData.setCode(PropertyWritableRecordFactoryService.class.getName());
serviceData.setName("JournalWritableRecordFactory");
attr = new AttributeMetaData(serviceData);
attr.setName("FormatKeyMapping");
attr.setValue("REQUEST_ID=MethodJournal.RequestID\n" + "CALL=MethodJournal.JournalRecords.MethodCall[0]\n" + "RETURN=MethodJournal.JournalRecords.MethodReturn[0]\n");
serviceData.addAttribute(attr);
attr = new AttributeMetaData(serviceData);
attr.setName("Format");
attr.setValue("%REQUEST_ID%%CALL%%RETURN%");
serviceData.addAttribute(attr);
ServiceManagerFactory.registerService("Test", serviceData);
writer = new TestMessageWriter();
ServiceManagerFactory.registerService("Test", "JournalWriter", writer);
serviceData = new ServiceMetaData();
serviceData.setCode(ObjectMappedEditorFinderService.class.getName());
serviceData.setName("JournalEditorFinder");
attr = new AttributeMetaData(serviceData);
attr.setName("EditorProperties");
attr.setValue("java.lang.Object=#ObjectJournalEditor\n" + "jp.ossc.nimbus.service.journal.RequestJournal=#RequestJournalEditor\n");
serviceData.addAttribute(attr);
serviceData.addDepends(serviceData.createDependsMetaData("Test", "ObjectJournalEditor"));
serviceData.addDepends(serviceData.createDependsMetaData("Test", "RequestJournalEditor"));
ServiceManagerFactory.registerService("Test", serviceData);
serviceData = new ServiceMetaData();
serviceData.setCode(SimpleRequestMapJournalEditorService.class.getName());
serviceData.setName("RequestJournalEditor");
ServiceManagerFactory.registerService("Test", serviceData);
serviceData = new ServiceMetaData();
serviceData.setCode(ThreadContextService.class.getName());
serviceData.setName("Context");
ServiceManagerFactory.registerService("Test", serviceData);
serviceData = new ServiceMetaData();
serviceData.setCode(MutableObjectJournalEditorService.class.getName());
serviceData.setName("ObjectJournalEditor");
ServiceManagerFactory.registerService("Test", serviceData);
interceptorServiceData = new ServiceMetaData();
interceptorServiceData.setCode(MethodJournalInterceptorService.class.getName());
interceptorServiceData.setName("MethodJournalInterceptor");
attr = new AttributeMetaData(interceptorServiceData);
attr.setName("JournalServiceName");
attr.setValue("#Journal");
interceptorServiceData.addAttribute(attr);
attr = new AttributeMetaData(interceptorServiceData);
attr.setName("ThreadContextServiceName");
attr.setValue("#Context");
interceptorServiceData.addAttribute(attr);
interceptorServiceData.addDepends(serviceData.createDependsMetaData("Test", "Journal"));
interceptorServiceData.addDepends(serviceData.createDependsMetaData("Test", "Context"));
}
use of jp.ossc.nimbus.core.ServiceMetaData in project nimbus by nimbus-org.
the class MethodMappingInterceptorServiceTest method test2.
public void test2() throws Throwable {
ServiceManagerFactory.registerManager("Test");
ServiceMetaData serviceData = new ServiceMetaData();
serviceData.setCode(MethodMappingInterceptorService.class.getName());
serviceData.setName("MethodMappingInterceptor");
AttributeMetaData attr = new AttributeMetaData(serviceData);
attr.setName("TargetMethodMapping");
attr.setValue("java\\.util\\..*#get(java.lang.Object)=#Interceptor2\n" + "java\\.util\\..*#put(java.lang.Object, java.lang.Object)=#Interceptor3");
serviceData.addAttribute(attr);
ServiceManagerFactory.registerService("Test", serviceData);
Interceptor interceptor1 = (Interceptor) ServiceManagerFactory.getServiceObject("Test", "MethodMappingInterceptor");
Interceptor interceptor2 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
return this;
}
};
ServiceManagerFactory.registerService("Test", "Interceptor2", interceptor2);
Interceptor interceptor3 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
return this;
}
};
ServiceManagerFactory.registerService("Test", "Interceptor3", interceptor3);
try {
ServiceManagerFactory.findManager("Test").createAllService();
ServiceManagerFactory.findManager("Test").startAllService();
assertEquals(interceptor2, new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("get", new Class[] { Object.class }), null)));
assertEquals(interceptor3, new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("put", new Class[] { Object.class, Object.class }), null)));
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.core.ServiceMetaData in project nimbus by nimbus-org.
the class DefaultInterceptorChainListServiceTest method test2.
public void test2() throws Throwable {
final ServiceMetaData chainListServiceData = new ServiceMetaData();
chainListServiceData.setCode(DefaultInterceptorChainListService.class.getName());
chainListServiceData.setName("ChainList");
chainListServiceData.addDepends(chainListServiceData.createDependsMetaData("Test", "Interceptor1"));
chainListServiceData.addDepends(chainListServiceData.createDependsMetaData("Test", "Interceptor2"));
chainListServiceData.addDepends(chainListServiceData.createDependsMetaData("Test", "Interceptor3"));
final Interceptor interceptor1 = new TestInterceptor();
final Interceptor interceptor2 = new TestInterceptor();
final Interceptor interceptor3 = new TestInterceptor();
ServiceManagerFactory.registerManager("Test");
ServiceManagerFactory.registerService("Test", chainListServiceData);
ServiceManagerFactory.registerService("Test", "Interceptor1", interceptor1);
ServiceManagerFactory.registerService("Test", "Interceptor2", interceptor2);
ServiceManagerFactory.registerService("Test", "Interceptor3", interceptor3);
try {
DefaultInterceptorChainListService chainList = (DefaultInterceptorChainListService) ServiceManagerFactory.getServiceObject("Test", "ChainList");
chainList.setInterceptorServiceNames(new ServiceName[] { new ServiceName("Test", "Interceptor1"), new ServiceName("Test", "Interceptor2"), new ServiceName("Test", "Interceptor3") });
ServiceManagerFactory.findManager("Test").createAllService();
ServiceManagerFactory.findManager("Test").startAllService();
assertEquals(interceptor1, chainList.getInterceptor(null, 0));
assertEquals(interceptor2, chainList.getInterceptor(null, 1));
assertEquals(interceptor3, chainList.getInterceptor(null, 2));
} finally {
ServiceManagerFactory.findManager("Test").stop();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.core.ServiceMetaData in project nimbus by nimbus-org.
the class BeanFlowRestServerService method reload.
public synchronized void reload() throws Exception {
if (serverDefinitionPath == null || serverDefinitionPath.length() == 0) {
throw new IllegalArgumentException("ServerDefinitionPath is null");
}
File serviceDefDir = null;
if (getServiceNameObject() != null) {
ServiceMetaData metaData = ServiceManagerFactory.getServiceMetaData(getServiceNameObject());
if (metaData != null) {
jp.ossc.nimbus.core.ServiceLoader loader = metaData.getServiceLoader();
if (loader != null) {
String filePath = loader.getServiceURL().getFile();
if (filePath != null) {
serviceDefDir = new File(filePath).getParentFile();
}
}
}
}
URL url = null;
File localFile = new File(serverDefinitionPath);
if (!localFile.exists() && serviceDefDir != null) {
localFile = new File(serviceDefDir, serverDefinitionPath);
}
if (localFile.exists()) {
if (!localFile.isFile()) {
throw new IllegalArgumentException("ServerDefinitionPath must be file : " + localFile);
}
try {
url = localFile.toURI().toURL();
} catch (MalformedURLException e) {
// この例外は発生しないはず
}
} else {
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final URL resource = classLoader.getResource(serverDefinitionPath);
if (resource != null) {
url = resource;
}
}
if (url == null) {
throw new IllegalArgumentException("ServerDefinitionPath not found : " + serverDefinitionPath);
}
final InputSource inputSource = new InputSource(url.openStream());
DocumentBuilderFactory domFactory = null;
if (documentBuilderFactoryClassName == null) {
domFactory = DocumentBuilderFactory.newInstance();
} else {
domFactory = (DocumentBuilderFactory) Class.forName(documentBuilderFactoryClassName, true, NimbusClassLoader.getInstance()).newInstance();
}
domFactory.setValidating(isValidate());
final DocumentBuilder builder = domFactory.newDocumentBuilder();
final NimbusEntityResolver resolver = new NimbusEntityResolver();
builder.setEntityResolver(resolver);
final MyErrorHandler handler = new MyErrorHandler();
builder.setErrorHandler(handler);
final Document doc = builder.parse(inputSource);
if (handler.isError()) {
throw new DeploymentException("Failed to parse ServerDefinition");
}
final RestServerMetaData serverData = new RestServerMetaData();
serverData.importXML(doc.getDocumentElement());
restServerMetaData = serverData;
}
use of jp.ossc.nimbus.core.ServiceMetaData in project nimbus by nimbus-org.
the class MethodMappingInterceptorServiceTest method test3.
public void test3() throws Throwable {
ServiceManagerFactory.registerManager("Test");
ServiceMetaData serviceData = new ServiceMetaData();
serviceData.setCode(MethodMappingInterceptorService.class.getName());
serviceData.setName("MethodMappingInterceptor");
AttributeMetaData attr = new AttributeMetaData(serviceData);
attr.setName("TargetMethodMapping");
attr.setValue("java\\.util\\..*#get(*)=#Interceptor2\n" + "java\\.util\\..*#.*(java.lang.Object, java.lang.Object)=#Interceptor3");
serviceData.addAttribute(attr);
ServiceManagerFactory.registerService("Test", serviceData);
Interceptor interceptor1 = (Interceptor) ServiceManagerFactory.getServiceObject("Test", "MethodMappingInterceptor");
Interceptor interceptor2 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
return this;
}
};
ServiceManagerFactory.registerService("Test", "Interceptor2", interceptor2);
Interceptor interceptor3 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
return this;
}
};
ServiceManagerFactory.registerService("Test", "Interceptor3", interceptor3);
try {
ServiceManagerFactory.findManager("Test").createAllService();
ServiceManagerFactory.findManager("Test").startAllService();
assertEquals(interceptor2, new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("get", new Class[] { Object.class }), null)));
assertEquals(interceptor2, new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, ArrayList.class.getMethod("get", new Class[] { Integer.TYPE }), null)));
assertEquals(interceptor3, new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("put", new Class[] { Object.class, Object.class }), null)));
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
Aggregations