Search in sources :

Example 11 with ServiceMetaData

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

the class MethodMappingInterceptorServiceTest method test4.

public void test4() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    ServiceMetaData serviceData = new ServiceMetaData();
    serviceData.setCode(MethodMappingInterceptorService.class.getName());
    serviceData.setName("MethodMappingInterceptor");
    AttributeMetaData attr = new AttributeMetaData(serviceData);
    attr.setName("TargetMethodReturnMapping");
    attr.setValue("java.util.HashMap#get(java.lang.Object)=A\n" + "java.util.HashMap#put(java.lang.Object, java.lang.Object)=B");
    serviceData.addAttribute(attr);
    attr = new AttributeMetaData(serviceData);
    attr.setName("ContextServiceName");
    attr.setValue("#Context");
    serviceData.addAttribute(attr);
    ServiceManagerFactory.registerService("Test", serviceData);
    Interceptor interceptor1 = (Interceptor) ServiceManagerFactory.getServiceObject("Test", "MethodMappingInterceptor");
    Context context = new DefaultContextService();
    ServiceManagerFactory.registerService("Test", "Context", context);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        ServiceManagerFactory.findManager("Test").startAllService();
        context.put("A", new Integer(100));
        context.put("B", new Integer(200));
        assertEquals(new Integer(100), new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("get", new Class[] { Object.class }), null)));
        assertEquals(new Integer(200), 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 : InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) Context(jp.ossc.nimbus.service.context.Context) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) AttributeMetaData(jp.ossc.nimbus.core.AttributeMetaData) HashMap(java.util.HashMap) DefaultContextService(jp.ossc.nimbus.service.context.DefaultContextService) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Example 12 with ServiceMetaData

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

the class MethodMappingInterceptorServiceTest method test1.

public void test1() 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.HashMap#get(java.lang.Object)=#Interceptor2\n" + "java.util.HashMap#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 13 with ServiceMetaData

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

the class JaxRpcServiceFactoryService method startService.

public void startService() throws Exception {
    if (nameSpace == null) {
        // ネームスペースが設定されていない。
        throw new IllegalArgumentException("nameSpace must be specified.");
    }
    if (jaxRpcServiceName == null) {
        // JAX-RPCサービス名が設定されていない。
        throw new IllegalArgumentException("jaxRpcServiceName must be specified.");
    }
    if (wsdlPath != null) {
        URL url = null;
        File localFile = new File(wsdlPath);
        if (localFile.exists()) {
            if (!localFile.isFile()) {
                throw new IllegalArgumentException("WsdlPath must be file : " + localFile);
            }
            try {
                wsdlURL = localFile.toURL();
            } catch (MalformedURLException e) {
            // この例外は発生しないはず
            }
        } else {
            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();
                        }
                    }
                }
            }
            localFile = new File(serviceDefDir, wsdlPath);
            if (localFile.exists()) {
                if (!localFile.isFile()) {
                    throw new IllegalArgumentException("WsdlPath must be file : " + localFile);
                }
                try {
                    wsdlURL = localFile.toURL();
                } catch (MalformedURLException e) {
                // この例外は発生しないはず
                }
            } else {
                final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
                final URL resource = classLoader.getResource(wsdlPath);
                if (resource != null) {
                    wsdlURL = resource;
                }
            }
        }
        if (wsdlURL == null) {
            // WSDLのURLが設定されていない。
            throw new IllegalArgumentException("WsdlPath could not find. path=" + wsdlURL);
        }
    }
    if (wsdlURL == null) {
        // WSDLのURLが設定されていない。
        throw new IllegalArgumentException("wsdlURL must be specified.");
    }
    if (serviceFactoryClassName != null) {
        System.setProperty(ServiceFactory.SERVICEFACTORY_PROPERTY, serviceFactoryClassName);
    }
    // JAX-RPCサービスファクトリー
    jaxRpcFactory = ServiceFactory.newInstance();
    getService();
}
Also used : MalformedURLException(java.net.MalformedURLException) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) File(java.io.File) URL(java.net.URL)

Example 14 with ServiceMetaData

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

the class HttpTestStubService method startService.

public void startService() throws Exception {
    if (id == null) {
        throw new IllegalArgumentException("Id is null.");
    }
    if (stubResourceManagerServiceName != null) {
        stubResourceManager = (StubResourceManager) ServiceManagerFactory.getServiceObject(stubResourceManagerServiceName);
    }
    if (stubResourceManager == null) {
        throw new IllegalArgumentException("StubResourceManager is null.");
    }
    if (interpreterServiceName != null) {
        interpreter = (Interpreter) ServiceManagerFactory.getServiceObject(interpreterServiceName);
    }
    File serviceDefDir = null;
    if (getServiceNameObject() != null) {
        ServiceMetaData metaData = ServiceManagerFactory.getServiceMetaData(getServiceNameObject());
        if (metaData != null) {
            ServiceLoader loader = metaData.getServiceLoader();
            if (loader != null) {
                String filePath = loader.getServiceURL().getFile();
                if (filePath != null) {
                    serviceDefDir = new File(filePath).getParentFile();
                }
            }
        }
    }
    if (resourceDirectory == null) {
        resourceDirectory = serviceDefDir == null ? new File(id) : new File(serviceDefDir, id);
    } else if (!resourceDirectory.isAbsolute() && !resourceDirectory.exists() && serviceDefDir != null) {
        resourceDirectory = new File(serviceDefDir, resourceDirectory.getPath());
    }
    if (!resourceDirectory.exists()) {
        resourceDirectory.mkdirs();
    }
    if (binaryFileExtensions != null) {
        for (int i = 0; i < binaryFileExtensions.length; i++) {
            String ext = binaryFileExtensions[i];
            if (ext == null || ext.length() == 0) {
                continue;
            }
            if (ext.charAt(0) != '.') {
                ext = '.' + ext;
            }
            binaryFileExtensionSet.add(ext);
        }
    }
}
Also used : ServiceLoader(jp.ossc.nimbus.core.ServiceLoader) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) File(java.io.File)

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