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