1

spring を使用して rmi-iiop を実装しようとしています。よく検索しましたが、最新の例は見つかりませんでした。そこで、この本の「 Corba サービスの公開」セクションから始めました。以前のSpringバージョンをベースに書いていますが、動くようです。

これらは私の構成です

サーバ

public interface IRemote extends Remote{
    String getMsg() throws RemoteException;
} 
public class RemoteImpl implements IRemote {
    @Override
    public String getMsg() throws RemoteException {
            return "Hello";
    }
}

<bean id="helloWorldService"
            class="com.sample.remote.RemoteImpl" />

<bean class="org.springframework.remoting.rmi.JndiRmiServiceExporter">
            <property name="jndiName" value="HelloWorld"/>
            <property name="serviceInterface"
                    value="com.sample.remote.IRemote" />
            <property name="service" ref="helloWorldService"/>
            <property name="jndiEnvironment">
                    <props>
                            <prop key="java.naming.factory.initial">
                                    com.sun.jndi.cosnaming.CNCtxFactory
                            </prop>
                            <prop key="java.naming.provider.url">iiop://localhost:1050</prop>
                    </props>
            </property>
</bean>

クライアント

<bean id="helloWorldService" class="org.springframework.remoting.rmi.JndiRmiProxyFactoryBean">
            <property name="jndiName">
                    <value>HelloWorld</value>
            </property>

            <property name="serviceInterface">
                    <value>com.sample.remote.IRemote</value>
            </property>
            <property name="jndiEnvironment">
                    <props>
                            <prop key="java.naming.factory.initial">
                                    com.sun.jndi.cosnaming.CNCtxFactory
                            </prop>
                            <prop key="java.naming.provider.url">iiop://localhost:1050</prop>
                    </props>
            </property>
</bean>

クライアントクラス

public class Client {
    @Autowired
    IRemote remote;

    public void clientMethod() {
            try {
                    System.out.println(remote.getMsg());
            } catch (RemoteException e) {
                    e.printStackTrace();
            }
    }
}

これはそのままでうまくいきます。

しかし問題は、Spring aop を使用する場合です。aop がプロキシ Bean を作成すると、サーバーでスタブ/タイ ルックアップが失敗します。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.remoting.rmi.JndiRmiServiceExporter#0' defined in URL [jar:file:/D:/Code-base/Workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/sample-web/WEB-INF/lib/tech-ri-remote-1.0.0-M1.jar!/config/test_SpringContext.xml]: Invocation of init method failed; nested exception is java.rmi.StubNotFoundException: Stub class not found: $Proxy203_Stub; nested exception is:
        java.lang.ClassNotFoundException: $Proxy203_Stub
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:725)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)
Caused by: java.rmi.StubNotFoundException: Stub class not found: $Proxy203_Stub; nested exception is:
        java.lang.ClassNotFoundException: $Proxy203_Stub
        at sun.rmi.server.Util.createStub(Util.java:292)
        at sun.rmi.server.Util.createProxy(Util.java:140)
        at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:196)
        at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:310)
        at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:237)
        at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.exportObject(PortableRemoteObject.java:119)
        at javax.rmi.PortableRemoteObject.exportObject(PortableRemoteObject.java:103)
        at org.springframework.remoting.rmi.JndiRmiServiceExporter.prepare(JndiRmiServiceExporter.java:121)
        at org.springframework.remoting.rmi.JndiRmiServiceExporter.afterPropertiesSet(JndiRmiServiceExporter.java:106)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564)
        ... 22 more
Caused by: java.lang.ClassNotFoundException: $Proxy203_Stub
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at sun.rmi.server.Util.createStub(Util.java:286)
        ... 32 more

例外は $Proxy203_Stub が見つからないことを示していますが、デバッグ時に、Tie ルックアップが失敗したときに実際の例外が発生することがわかりました。

JndiRmiServiceExporter javadoc に記載されている別のオプションとして、java.rmi.Remote インターフェイスと RemoteException なしで試してみました。しかし、Bean の作成は RmiInvocationWrapper_Stub が見つからないため失敗します。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.remoting.rmi.JndiRmiServiceExporter#0' defined in URL [jar:file:/D:/Code-base/Workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/sample-web/WEB-INF/lib/tech-ri-remote-1.0.0-M1.jar!/config/test_SpringContext.xml]: Invocation of init method failed; nested exception is java.rmi.StubNotFoundException: Stub class not found: org.springframework.remoting.rmi.RmiInvocationWrapper_Stub; nested exception is:
        java.lang.ClassNotFoundException: org.springframework.remoting.rmi.RmiInvocationWrapper_Stub
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:725)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)
Caused by: java.rmi.StubNotFoundException: Stub class not found: org.springframework.remoting.rmi.RmiInvocationWrapper_Stub; nested exception is:
        java.lang.ClassNotFoundException: org.springframework.remoting.rmi.RmiInvocationWrapper_Stub
        at sun.rmi.server.Util.createStub(Util.java:292)
        at sun.rmi.server.Util.createProxy(Util.java:140)
        at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:196)
        at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:310)
        at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:237)
        at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.exportObject(PortableRemoteObject.java:119)
        at javax.rmi.PortableRemoteObject.exportObject(PortableRemoteObject.java:103)
        at org.springframework.remoting.rmi.JndiRmiServiceExporter.prepare(JndiRmiServiceExporter.java:121)
        at org.springframework.remoting.rmi.JndiRmiServiceExporter.afterPropertiesSet(JndiRmiServiceExporter.java:106)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564)
        ... 22 more
Caused by: java.lang.ClassNotFoundException: org.springframework.remoting.rmi.RmiInvocationWrapper_Stub
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at sun.rmi.server.Util.createStub(Util.java:286)
        ... 32 more

ここでも、Tie ルックアップの失敗時に実際の例外が発生します。

RmiInvocationWrapper のスタブとタイは、最新リリースの spring-context.jar の一部ではなく、rmi には不要になっていることがわかりました。しかし、rmi-iiop に関連するものは何も見当たりませんでした。したがって、スタブとタイが必要であると仮定して、_RmiInvocationWrapper_Tie.class と _RmiInvocationHandler_Stub.class を作成し、それらを jar に追加しました。その後、サーバーが機能し始めました。

しかし、クライアントを起動すると、失敗します

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloWorldService' defined in URL [jar:file:/D:/Code-base/Workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/sample-web/WEB-INF/lib/tech-ri-1.0.0-M1.jar!/config/techri_SpringContext.xml]: Invocation of init method failed; nested exception is org.springframework.remoting.RemoteLookupFailureException: Could not narrow RMI stub to service interface [com.sample.remote.IRemote]; nested exception is java.lang.ClassCastException
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)
Caused by: org.springframework.remoting.RemoteLookupFailureException: Could not narrow RMI stub to service interface [com.sample.remote.IRemote]; nested exception is java.lang.ClassCastException
        at org.springframework.remoting.rmi.JndiRmiClientInterceptor.lookupStub(JndiRmiClientInterceptor.java:237)
        at org.springframework.remoting.rmi.JndiRmiClientInterceptor.prepare(JndiRmiClientInterceptor.java:199)
        at org.springframework.remoting.rmi.JndiRmiClientInterceptor.afterPropertiesSet(JndiRmiClientInterceptor.java:187)
        at org.springframework.remoting.rmi.JndiRmiProxyFactoryBean.afterPropertiesSet(JndiRmiProxyFactoryBean.java:79)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564)
        ... 22 more
Caused by: java.lang.ClassCastException
        at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:245)
        at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:153)
        at org.springframework.remoting.rmi.JndiRmiClientInterceptor.lookupStub(JndiRmiClientInterceptor.java:233)
        ... 27 more
Caused by: java.lang.ClassCastException: Object is not of remote type com.sample.remote.IRemote
        at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:237)
        ... 29 more

だから私は今完全に立ち往生しており、どうすればよいかわかりません。お知らせ下さい。また、誰かがこれに基づいて最新の構成例を提供できるとよいでしょう。

4

0 に答える 0