Search in sources :

Example 6 with ServiceMetaData

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"));
}
Also used : SimpleRequestMapJournalEditorService(jp.ossc.nimbus.service.journal.editor.SimpleRequestMapJournalEditorService) ThreadManagedJournalService(jp.ossc.nimbus.service.journal.ThreadManagedJournalService) MutableObjectJournalEditorService(jp.ossc.nimbus.service.journal.editor.MutableObjectJournalEditorService) AttributeMetaData(jp.ossc.nimbus.core.AttributeMetaData) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) PropertyWritableRecordFactoryService(jp.ossc.nimbus.service.writer.PropertyWritableRecordFactoryService) ThreadContextService(jp.ossc.nimbus.service.context.ThreadContextService) SimpleCategoryService(jp.ossc.nimbus.service.writer.SimpleCategoryService) ObjectMappedEditorFinderService(jp.ossc.nimbus.service.journal.editorfinder.ObjectMappedEditorFinderService)

Example 7 with ServiceMetaData

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");
    }
}
Also used : DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) AttributeMetaData(jp.ossc.nimbus.core.AttributeMetaData) HashMap(java.util.HashMap) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Example 8 with ServiceMetaData

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");
    }
}
Also used : ServiceName(jp.ossc.nimbus.core.ServiceName) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData)

Example 9 with ServiceMetaData

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NimbusEntityResolver(jp.ossc.nimbus.core.NimbusEntityResolver) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) URL(java.net.URL) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NimbusClassLoader(jp.ossc.nimbus.core.NimbusClassLoader) DeploymentException(jp.ossc.nimbus.core.DeploymentException) File(java.io.File)

Example 10 with ServiceMetaData

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");
    }
}
Also used : DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) AttributeMetaData(jp.ossc.nimbus.core.AttributeMetaData) HashMap(java.util.HashMap) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) ArrayList(java.util.ArrayList) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Aggregations

ServiceMetaData (jp.ossc.nimbus.core.ServiceMetaData)14 DefaultInterceptorChainList (jp.ossc.nimbus.service.aop.DefaultInterceptorChainList)8 DefaultMethodInvocationContext (jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext)8 InvocationContext (jp.ossc.nimbus.service.aop.InvocationContext)8 Interceptor (jp.ossc.nimbus.service.aop.Interceptor)7 InterceptorChain (jp.ossc.nimbus.service.aop.InterceptorChain)6 AttributeMetaData (jp.ossc.nimbus.core.AttributeMetaData)5 ServiceName (jp.ossc.nimbus.core.ServiceName)5 DefaultInterceptorChain (jp.ossc.nimbus.service.aop.DefaultInterceptorChain)5 File (java.io.File)4 HashMap (java.util.HashMap)4 Invoker (jp.ossc.nimbus.service.aop.Invoker)4 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 DefaultThreadLocalInterceptorChain (jp.ossc.nimbus.service.aop.DefaultThreadLocalInterceptorChain)3 DefaultSemaphoreService (jp.ossc.nimbus.service.semaphore.DefaultSemaphoreService)3 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1