RMI UnmarshalException ClassNotFoundException server only - java

I have followed several tutorials on running an RMI application. However, I can't seem to make it work, as I keep getting stuck on the same exception.
I am, at this point only running a server, so no client communication is involved.
I have a simple RMI program that consists of:
A server class SortServer
An interface ISortFactory<T>
An implementation QuickSortFactory<T>
An RMIUtils class
A policy file allpermissions.policy
Policy file contents
grant {
permission java.security.AllPermission;
};
RMIUtils
static {
// Set policy
setPolicy();
// Set Security manager if not present
if(System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
setHost("127.0.0.1");
}
public static void addCodeBaseFor(Class<?> clazz) {
System.setProperty("java.rmi.server.codebase", clazz.getProtectionDomain().getCodeSource().getLocation().toString());
}
public static void setPolicy() {
System.setProperty("java.security.policy", PolicyFileLocator.getLocationOfPolicyFile());
}
public static void setHost(String hostAddress) {
System.setProperty("java.rmi.server.hostname", hostAddress);
}
public static String getHost() {
return System.getProperty("java.rmi.server.hostname");
}
SortServer
public static void main(String[] args) throws RemoteException, MalformedURLException, AlreadyBoundException {
RMIUtils.addCodeBaseFor(ISortFactory.class);
ISortFactory<String> strQSFactory = new QuickSortFactory<String>();
// Same error: Naming.bind("rmi://"+RMIUtils.getHost()+"/quicksortfactory", strQSFactory);
Registry registry = LocateRegistry.getRegistry();
registry.rebind("quicksortfactory-string", strQSFactory);
}
ISortFactory
public interface ISortFactory<T> extends Remote {
public ISorter<T> createSorter() throws RemoteException;
}
Implementing QuickSortFactory
public class QuickSortFactory<T> extends UnicastRemoteObject implements ISortFactory<T> {
private static final long serialVersionUID = -4856366323843718656L;
public QuickSortFactory() throws RemoteException {
super();
}
#Override
public ISorter<T> createSorter() throws RemoteException {
return new QuickSort<T>();
}
}
ISorter, QuickSorter and referenced objects
ISorter extends Remote and its methods throw RemoteExceptions.
QuickSort extends SortLogic and implements ISorter. Its methods throw RemoteExceptions.
SortLogic extends UnicastRemoteObject. Its methods throw RemoteExceptions.
Since I use JDK 1.5+, I shouldn't need to worry about stubs.
The rmiregistry is running fine, or I would have different errors.
Literal console output
2013-11-20 00:57:00 DEBUG RMIUtils:33 - Policy file path changed to 'C:\Users\Mark\AppData\Local\Temp\rmi-sorter5248481413010560777.policy'
2013-11-20 00:57:00 DEBUG RMIUtils:38 - RMI hostname set to 127.0.0.1
2013-11-20 00:57:00 DEBUG RMIUtils:27 - Codebase path added: file:/F:/Development/Git/Personal/parallel-sorter/bin/
Exception in thread "main" java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: nl.marktielemans.rmisorter.server.factory.ISortFactory
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:400)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:248)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at nl.marktielemans.rmisorter.server.SortServer.main(SortServer.java:42)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: nl.marktielemans.rmisorter.server.factory.ISortFactory
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:390)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:248)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassNotFoundException: nl.marktielemans.rmisorter.server.factory.ISortFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:249)
at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:709)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:653)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:590)
at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:628)
at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:294)
at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:242)
at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1535)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1491)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1748)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1327)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
... 12 more
Without codebase parameter
I've tried without codebase parameter, but am not sure how to include the classes in the RMI classpath as I read I should.
I've tried starting the registry from the code in SortServer using RegistryLocator.getRegistry() as above, as well as starting it from a command line opened in my bin directory. Still, I would get the same error.

java.lang.ClassNotFoundException: nl.marktielemans.rmisorter.server.factory.ISortFactory
...
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
The Registry doesn't have that class available in its CLASSPATH.
If you're using the java.rmi.server.codebase property you need to set it before exporting any remote objects, and the codebase needs to be something the Registry and the clients can use.
public static void addCodeBaseFor(Class<?> clazz) {
System.setProperty("java.rmi.server.codebase", clazz.getProtectionDomain().getCodeSource().getLocation().toString());
}
This isn't going to work. The location on the server of the containing JAR file can't be seen from the client. Generally it is an http: or ftp: URL.

Related

java.lang.VerifyError: ClientProxy overrides final method

Building a Quarkus project.
Created a class which extends a 3rd party having final methods:
#ApplicationScoped
public class BotService extends TelegramLongPollingBot {
#Override
public void onUpdateReceived(Update update) {
}
#Override
public String getBotUsername() {
return "something";
}
#Override
public String getBotToken() {
return System.getenv("token");
}
}
Explicitly adding quarkus.arc.remove-final-for-proxyable-methods=true to the application.properties.
When running in dev mode, I see a lot of ignored final methods in log (including the execute()):
2020-04-19 17:44:23,676 WARN [io.qua.arc.pro.Methods] (build-25) Final method org.telegram.telegrambots.meta.bots.AbsSender.getMe() is ignored during proxy generation and should never be invoked upon the proxy instance!
2020-04-19 17:44:23,676 WARN [io.qua.arc.pro.Methods] (build-25) Final method org.telegram.telegrambots.meta.bots.AbsSender.getMeAsync() is ignored during proxy generation and should never be invoked upon the proxy instance!
2020-04-19 17:44:23,676 WARN [io.qua.arc.pro.Methods] (build-25) Final method org.telegram.telegrambots.meta.bots.AbsSender.getWebhookInfo() is ignored during proxy generation and should never be invoked upon the proxy instance!
2020-04-19 17:44:23,676 WARN [io.qua.arc.pro.Methods] (build-25) Final method org.telegram.telegrambots.meta.bots.AbsSender.getWebhookInfoAsync() is ignored during proxy generation and should never be invoked upon the proxy instance!
...
Everything looks fine, but then it fails with:
ERROR [io.qua.dev.DevModeMain] (main) Failed to start Quarkus: java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at io.quarkus.runner.bootstrap.StartupActionImpl.run(StartupActionImpl.java:83)
at io.quarkus.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:60)
at io.quarkus.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:236)
at io.quarkus.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:39)
at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:131)
at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:84)
at io.quarkus.dev.DevModeMain.start(DevModeMain.java:113)
at io.quarkus.dev.DevModeMain.main(DevModeMain.java:54)
Caused by: java.lang.RuntimeException: Failed to start quarkus
at io.quarkus.runner.ApplicationImpl.<clinit>(ApplicationImpl.zig:408)
... 10 more
Caused by: java.lang.RuntimeException: Failed to initialize Arc
at io.quarkus.arc.Arc.initialize(Arc.java:26)
at io.quarkus.arc.runtime.ArcRecorder.getContainer(ArcRecorder.java:35)
at io.quarkus.deployment.steps.ArcProcessor$generateResources23.deploy_0(ArcProcessor$generateResources23.zig:72)
at io.quarkus.deployment.steps.ArcProcessor$generateResources23.deploy(ArcProcessor$generateResources23.zig:36)
at io.quarkus.runner.ApplicationImpl.<clinit>(ApplicationImpl.zig:370)
... 10 more
Caused by: java.lang.VerifyError: class com.dubilyer.bot_market.telegram.service.BotService_ClientProxy overrides final method execute.(Lorg/telegram/telegrambots/meta/api/methods/send/SendAudio;)Lorg/telegram/telegrambots/meta/api/objects/Message;
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:757)
at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:316)
at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:275)
at com.dubilyer.bot_market.telegram.service.BotService_Bean.<init>(BotService_Bean.zig:117)
at io.quarkus.arc.setup.Default_ComponentsProvider.addBeans1(Default_ComponentsProvider.zig:142)
at io.quarkus.arc.setup.Default_ComponentsProvider.getComponents(Default_ComponentsProvider.zig:38)
at io.quarkus.arc.impl.ArcContainerImpl.<init>(ArcContainerImpl.java:103)
at io.quarkus.arc.Arc.initialize(Arc.java:20)
... 14 more
Any ideas what can cause it and how to avoid it?

Guice Assisted Inject - java.lang.IllegalStateException: zip file closed

I'm having problems with using Guice's assisted inject within my spigot plugin, and can't seem to narrow down the problem. This is the error I'm getting:
> [12:00:38 INFO]: [DestinyMC] Enabling DestinyMC v1.0
> 2019-01-14 12:00:41,492 Log4j2-TF-1-AsyncLogger[AsyncContext#5c647e05]-1 ERROR An exception occurred processing Appender File com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalStateException: zip file closed
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2217)
at com.google.common.cache.LocalCache.get(LocalCache.java:4154)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4158)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5147)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:5153)
at com.google.inject.internal.util.StackTraceElements.forMember(StackTraceElements.java:71)
at com.google.inject.internal.Messages.formatSource(Messages.java:241)
at com.google.inject.internal.Messages.formatSource(Messages.java:220)
at com.google.inject.internal.Messages.formatMessages(Messages.java:90)
at com.google.inject.CreationException.getMessage(CreationException.java:50)
at org.apache.logging.log4j.core.impl.ThrowableProxy.<init>(ThrowableProxy.java:134)
at org.apache.logging.log4j.core.impl.ThrowableProxy.<init>(ThrowableProxy.java:122)
at org.apache.logging.log4j.core.async.RingBufferLogEvent.getThrownProxy(RingBufferLogEvent.java:330)
at org.apache.logging.log4j.core.pattern.ExtendedThrowablePatternConverter.format(ExtendedThrowablePatternConverter.java:61)
at org.apache.logging.log4j.core.pattern.PatternFormatter.format(PatternFormatter.java:38)
at org.apache.logging.log4j.core.layout.PatternLayout$PatternSelectorSerializer.toSerializable(PatternLayout.java:455)
at org.apache.logging.log4j.core.layout.PatternLayout.toText(PatternLayout.java:232)
at org.apache.logging.log4j.core.layout.PatternLayout.encode(PatternLayout.java:217)
at org.apache.logging.log4j.core.layout.PatternLayout.encode(PatternLayout.java:57)
at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.directEncodeEvent(AbstractOutputStreamAppender.java:177)
at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.tryAppend(AbstractOutputStreamAppender.java:170)
at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:161)
at org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender.append(RollingRandomAccessFileAppender.java:218)
at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:448)
at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:433)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:417)
at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:79)
at org.apache.logging.log4j.core.async.AsyncLogger.actualAsyncLog(AsyncLogger.java:337)
at org.apache.logging.log4j.core.async.RingBufferLogEvent.execute(RingBufferLogEvent.java:161)
at org.apache.logging.log4j.core.async.RingBufferLogEventHandler.onEvent(RingBufferLogEventHandler.java:45)
at org.apache.logging.log4j.core.async.RingBufferLogEventHandler.onEvent(RingBufferLogEventHandler.java:29)
at com.lmax.disruptor.BatchEventProcessor.processEvents(BatchEventProcessor.java:168)
at com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:125)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: zip file closed
at java.util.zip.ZipFile.ensureOpen(Unknown Source)
at java.util.zip.ZipFile.getEntry(Unknown Source)
at java.util.jar.JarFile.getEntry(Unknown Source)
at java.util.jar.JarFile.getJarEntry(Unknown Source)
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:120)
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:104)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.google.inject.internal.util.StackTraceElements$1.load(StackTraceElements.java:49)
at com.google.inject.internal.util.StackTraceElements$1.load(StackTraceElements.java:45)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3716)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2424)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2298)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2211)
... 39 more
This is my Binder Class:
public class MainBinder extends AbstractModule {
#Override
protected void configure() {
bind(DestinyMC.class).toInstance(this.plugin);
install(new FactoryModuleBuilder().build(InventoryFromFileFactory.class));
}
The error goes away when I comment out the install line. That line uses this factory class
public interface InventoryFromFileFactory {
InventoryFromFile create(String targetRootKey, String targetFile);
}
which declare the parameters that need to be manually provided at object creation for this class:
public class InventoryFromFile {
#Inject
public InventoryFromFile
(
#Assisted String targetRootKey,
#Assisted String targetFile,
ConfigAccessorFactory configAccessorFactory
)
{
ConfigurationSection targetCS = configAccessorFactory.create(targetFile).getCustomConfig().getConfigurationSection(targetRootKey);
...
}
}
The ConfigAccessFactory is another factory class for assisted inject
public interface ConfigAccessorFactory {
ConfigAccessor create(String filename);
}
which is used here:
public class ConfigAccessor {
private Plugin plugin;
private final String customFileName;
#Inject
public ConfigAccessor
(
#Assisted String fileName,
DestinyMC plugin
)
{
this.customFileName = fileName;
this.plugin = plugin;
}
...
}
Finally, the DestinyMC dependency is the main class for the spigot plugin:
public class DestinyMC extends JavaPlugin {
//Inject dependencies
#Inject private ConfigAccessorFactory configAccessorFactory;
//Code only run once when the plugin is enabled
public void onEnable() {
MainBinder mainBinder = new MainBinder(this);
Injector injector = Guice.createInjector(mainBinder);
injector.injectMembers(this);
//Saves config files to disk if they don't exist
saveDefaultConfig();
Arrays.asList(
"inventory-gui.yml",
"player-tree-template.yml",
"player-tree-data.yml"
).forEach((file) -> {
configAccessorFactory.create(file).saveDefaultConfig();
});
...
}
I'm not too sure what I'm doing wrong, but I'm fairly new to Guice so I'm most likely misunderstanding something. Also, if there's simply a better way to do this, let me know. Thanks for the help.

How to lookup EJB remoting from a EJB application into a java application?

I'm working on a tow projects , EJB project (where i have all my EJB Remote) and the other project is a simple java application with main method. but when i try to lookup an EJB statless and remote via JNDI , it doesn't work.
Really i used many way but no good results.
this is the code and the consol error .
1) My Ejb project when i clean and install it , it gives me a jar file.
2) I use Jboss EAP6.
3) i have a jndi.properties insid of src/main/ressouces where i have this :
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url = localhost:1099
PersonalFactory.java (EJB of the EJB project)
import javax.ejb.Remote;
import javax.ejb.Stateless;
import com.lazrak.common.logging.CommonLogger;
import com.lazrak.remotes.IPersonFactoryRemote;
#Remote(IPersonFactoryRemote.class)
#Stateless
public class PersonFactory implements IPersonFactoryRemote
#Override
public void findMe() {
System.out.println("I'am inside of the method findMe");
}
MyMainClass.java (where i have the main method and it is in the second java project)
All import ...
public class MyMainClass {
public static void main(String[] args) throws Exception {
System.out.println("Main start ");
invokeStatelessBean();
}
private static void invokeStatelessBean(){
Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
props.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");
props.put(Context.PROVIDER_URL,"jnp://localhost:1099");
InitialContext context = null;
try {
context = new InitialContext(props);
} catch (NamingException e) {
System.out.println("Faild to add properties to InitialContext"+e.getMessage());
}
try {
final IPersonFactoryRemote statelessRemoteCalculator = (IPersonFactoryRemote) context
.lookup("ejb:"+moduleName+"/"+PersonFactory.class.getSimpleName();+"/"+IPersonFactoryRemote.class.getName());
} catch (NamingException e) {
System.out.println("EJB Remot doesn't been fined\n"+e.getMessage());
}
}
}
when i run my main application , it gives me that :
Main start
enter 2014-09-26 15:57:26,098 DEBUG org.jboss.logging - InitialContextFactory.java:64 - Logging Provider: org.jboss.logging.Log4jLoggerProvider
Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/remoting3/spi/ConnectionProviderFactory
at org.jboss.naming.remote.client.InitialContextFactory.<clinit>(InitialContextFactory.java:99)
at org.jboss.naming.remote.client.InitialContextFactory.<clinit>(InitialContextFactory.java:99)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:72)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:61)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:671)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
at RemoteEJBClient.invokeStatelessBean(RemoteEJBClient.java:42)
at RemoteEJBClient.main(RemoteEJBClient.java:18)
Caused by: java.lang.ClassNotFoundException:
org.jboss.remoting3.spi.ConnectionProviderFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 11 more
props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
props.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");
props.put(Context.PROVIDER_URL,"jnp://localhost:1099");
Those properties are used for connecting to an older jboss version.. For eap 6, you have to use remoting instead of jnp.
HereĀ“s a tutorial that will show you how to connect
http://www.mastertheboss.com/jboss-server/jboss-as-7/jboss-as-7-remote-ejb-client-tutorial

WSO2 Governance Registry - Adding Notification for Service

I am following the example listed in this link to add custom email notifications.
In my maven project 'RegistryService': I created the EmailTransformHandler and used maven to create the RegistryService-0.1.jar. I also modified the GREG_HOME/repository/conf/axis2/axis2.xml by adding the handler:
<handler name="EmailTransformHandler"
class="com.registration.example.service.EmailTransformHandler"/>
and dropped the RegistryService-0.1.jar in GREG_HOME/repository/components/dropins
package com.registration.example.service;
import java.util.ArrayList;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.xpath.AXIOMXPath;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.engine.Handler;
import org.apache.axis2.handlers.AbstractHandler;
public class EmailTransformHandler extends AbstractHandler implements Handler {
private String name;
public String getName() {
return name;
}
#Override
public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
if (msgContext.getTo() != null && msgContext.getTo().getAddress().startsWith("mailto:")) {
try {
SOAPEnvelope env = msgContext.getEnvelope();
AXIOMXPath xPath = new AXIOMXPath("//ns:text");
xPath.addNamespace("ns", "registry_example");
OMElement element = (OMElement) ((ArrayList) xPath.evaluate(env)).get(0);
element.setText(element.getText().replace("--", "This message intercepted by Terminator"));
} catch (Exception e) {
e.printStackTrace();
}
}
return InvocationResponse.CONTINUE;
}
}
When I go to the GREG_HOME/bin and start the server I get following exception:
2013-02-08 12:05:00,952] FATAL {org.wso2.carbon.core.init.CarbonServerManager} - WSO2 Carbon initialization Failed
org.apache.axis2.AxisFault: Exception occured while loading the Axis configuration from GREG_HOME/wso2/wso2greg-4.5.3/repository/conf/axis2/axis2.xml
at org.wso2.carbon.core.CarbonAxisConfigurator.getAxisConfiguration(CarbonAxisConfigurator.java:190)
at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContext(ConfigurationContextFactory.java:64)
at org.wso2.carbon.core.CarbonConfigurationContextFactory.createNewConfigurationContext(CarbonConfigurationContextFactory.java:65)
at org.wso2.carbon.core.init.CarbonServerManager.initializeCarbon(CarbonServerManager.java:398)
at org.wso2.carbon.core.init.CarbonServerManager.removePendingItem(CarbonServerManager.java:290)
at org.wso2.carbon.core.init.PreAxis2ConfigItemListener.bundleChanged(PreAxis2ConfigItemListener.java:118)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:847)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: org.apache.axis2.deployment.DeploymentException: com.registration.example.service.EmailTransformHandler
at org.apache.axis2.deployment.util.Utils.loadHandler(Utils.java:149)
at org.apache.axis2.deployment.AxisConfigBuilder.processPhaseList(AxisConfigBuilder.java:549)
at org.apache.axis2.deployment.AxisConfigBuilder.processPhaseOrders(AxisConfigBuilder.java:584)
at org.apache.axis2.deployment.AxisConfigBuilder.populateConfig(AxisConfigBuilder.java:150)
at org.wso2.carbon.core.CarbonAxisConfigurator.populateAxisConfiguration(CarbonAxisConfigurator.java:308)
at org.wso2.carbon.core.CarbonAxisConfigurator.getAxisConfiguration(CarbonAxisConfigurator.java:188)
... 8 more
Caused by: java.lang.ClassNotFoundException: com.registration.example.service.EmailTransformHandler
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.apache.axis2.util.Loader.loadClass(Loader.java:261)
at org.apache.axis2.util.Loader.loadClass(Loader.java:229)
at org.apache.axis2.deployment.util.Utils.loadHandler(Utils.java:116)
... 13 more
What configuration am I missing? Googling about this error does not yield any relevant results( except some Russian forums which do not help me much). I even tried adding the jar via WSO2 Management Console as an extension, but I still get this exception.
According to the error, your RegistryService-0.1.jar is not set properly to the class path.
If the jar file is not an OSGI bundle that jar file should be drop in to the "GREG_HOME/repository/components/lib" directory.
-Ajith

Two RMI registries on the same PC, NotBoundException

Scenario:
I'm implementing an RMI example between 2 PCs where the Controller PC queries the Agent PC for information. The agent PC may run Xen or KVM , hence the implementations of the queries differ(Reason for using RMI).
On the Agent's side I'm running 2 RMI registries bound to two different ports. When the same example is carried out with just 1 Registry on the agent's side, everything works fine.
Here is my code:
Controller. java(contains main() on controller's side):
public class Controller {
NetworkDiscovery n;
public static int discoveryInterval=2000;
static public PM pmlist;
public static void main(String[] args) throws UnknownHostException,NotBoundException, ` MalformedURLException, RemoteException {
pmOperations pm=(pmOperations)Naming.lookup("rmi://Agent_IP/RMIService1");
boolean l= pm.CreateVM("apple3","/var/lib/libvirt/images",1,200);
System.out.println(l);
vmOperations vm=(vmOperations)Naming.lookup("rmi://Agent_IP/RMIService2");
boolean ShutdownVM = vm.ShutdownVM("apple1");
System.out.println(ShutdownVM);
//other code
}
pmOperations.java(on controller's side)(on the agent's side, it has the same defn with implementation code inside function)
public interface pmOperations extends java.rmi.Remote{
public boolean CreateVM(String vmName,String imgSrc, int allotCPU, int allotMem )
throws java.rmi.RemoteException;
}
vmOperations.java(on controller's side)(on the agent's side, it has the same defn with implementation code inside function)
public interface vmOperations extends java.rmi.Remote{
boolean ChangeVMParam(String vmName,String paramName,String paramValue)
throws java.rmi.RemoteException;
}
Agent.java
public class Agent {
Agent() throws RemoteException, MalformedURLException{
Registry RMIService1 = LocateRegistry.createRegistry(1099);
Registry RMIService2 = LocateRegistry.createRegistry(4478);
vmOperations vmOp = new kvmVM();
pmOperations pmOp = new kvmPM();
Naming.rebind("rmi://localhost:1099/RMIService1", pmOp);
Naming.rebind("rmi://localhost:4478/RMIService2", vmOp);
}
public static void main(String[] args) throws SocketException, UnknownHostException, IOException, LibvirtException {
System.out.println("Inside main ");
new Agent();
//other code
}
}
Error I get while running above code on controller's side-no error on agent side:
Exception in thread "main" java.rmi.NotBoundException: RMIService2
at sun.rmi.registry.RegistryImpl.lookup(RegistryImpl.java:106)
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:386)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at package1.Controller.main(Controller.java:43)
Thanks!
You can't create two Registries in the same JVM.
You don't need two Registries in the same host.
You don't need to create two instances of the remote object.
Just create one Registry, one remote object, and bind it to the Registry twice, once with each name. You don't really need to bind it twice either really either. There's a lot of pointless duplication in this design.

Categories

Resources