Hi,
I've got some problems binding an RMI-Object to a NamingService. I tried to
bind it to JNDI first. Here's the code:
public AccountImpl(String id) throws RemoteException {
this.accountId = id;
try {
InitialContext jndiContext = new InitialContext(getEnv());
jndiContext.bind("account" + id, this);
} catch (Exception e) {
System.out.println("AccountImpl err: " + e.getMessage());
e.printStackTrace();
}
}
public static Properties getEnv() {
Properties env = new Properties();
env.setProperty(
"java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
env.setProperty("java.naming.provider.url", "127.0.0.1:1099");
env.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
return env;
}
if I run the code inside JBoss2.2, I get the following Exception:
java.net.SocketException: Connection shutdown: JVM_recv in socket input
stream read
[EmbeddedTomcat] java.net.SocketException: Connection shutdown: JVM_recv in
socket input stream read
[EmbeddedTomcat] at java.net.SocketInputStream.socketRead(Native Method)
[EmbeddedTomcat] at java.net.SocketInputStream.read(Unknown Source)
[EmbeddedTomcat] at java.io.BufferedInputStream.fill(Unknown Source)
[EmbeddedTomcat] at java.io.BufferedInputStream.read(Unknown Source)
[EmbeddedTomcat] at java.io.DataInputStream.readByte(Unknown Source)
[EmbeddedTomcat] at
sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
[EmbeddedTomcat] at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown
Source)
[EmbeddedTomcat] at sun.rmi.server.UnicastRef.newCall(Unknown Source)
[EmbeddedTomcat] at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown
Source)
[EmbeddedTomcat] at java.rmi.Naming.rebind(Unknown Source)
[EmbeddedTomcat] at accounting.AccountImpl.<init>(AccountImpl.java:22)
[EmbeddedTomcat] at
testing.AccountTests.createAccount(AccountTests.java:25)
[EmbeddedTomcat] at
testing.AccountTests.testMakeDeposit(AccountTests.java:163)
then I tried to use JDK's RMIRegistry from inside JBoss. Here's the code:
public AccountImpl(String id) throws RemoteException {
this.accountId = id;
try {
Naming.rebind("//localhost:99/account" + id, this);
System.out.println("Account bound in registry");
} catch (Exception e) {
System.out.println("AccountImpl err: " + e.getMessage());
e.printStackTrace();
}
}
I started RMIRegistry on port 99.
But still exceptions are thrown. The code is invoked several times an causes
the exception listed above and furthermore the following exception:
java.rmi.MarshalException: Transport protocol not supported by server
[EmbeddedTomcat] at
sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
[EmbeddedTomcat] at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown
Source)
[EmbeddedTomcat] at sun.rmi.server.UnicastRef.newCall(Unknown Source)
[EmbeddedTomcat] at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown
Source)
[EmbeddedTomcat] at java.rmi.Naming.rebind(Unknown Source)
[EmbeddedTomcat] at accounting.AccountImpl.<init>(AccountImpl.java:22)
[EmbeddedTomcat] at
testing.AccountTests.createAccount(AccountTests.java:25)
[EmbeddedTomcat] at
testing.AccountTests.testCreateAccount(AccountTests.java:50)
Did someone try to register RMI-Objects inside of JBoss, too? And could give
me a hint how to do it? That would be very nice.
Thanks in advance
Matthias