Extensions loaded in not isolated classloader

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

fameing
Posts: 13
Joined: 18 May 2015, 10:20

Extensions loaded in not isolated classloader

Postby fameing » 20 Oct 2016, 11:43

I need to use the library in SFS2X\extensions\zone\xstream-1.4.2.jar in my extension but now in lib directory exist SFS2X\lib\xstream-1.3.1.jar.

Currently, have error

Code: Select all

java.lang.NoSuchMethodError: com.thoughtworks.xstream.io.xml.DomDriver.<init>(Ljava/lang/String;Lcom/thoughtworks/xstream/io/naming/NameCoder;)V


How can I fix this situation?
Why extensions loaded in not isolated classloader ?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Extensions loaded in not isolated classloader

Postby Lapo » 20 Oct 2016, 13:47

Hi,
the error simply indicates that a certain method signature is not found.
I am not sure why this would suggest that there's a problem with isolated class loaders.

Does your Extension compile correctly? Did you deploy the XStream 1.4.2 jar in the same folder with your Extension?
Also, are you sure you compiled the Extension having XStream-1.4.2 in the compiler's classpath (or IDE's library settings)?

thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
fameing
Posts: 13
Joined: 18 May 2015, 10:20

Re: Extensions loaded in not isolated classloader

Postby fameing » 20 Oct 2016, 14:07

My extension is compiled with the correct dependencies (xstream-1.4.2.jar)

But parent classloader first and extension classloader last.

/**
* Constructs a new URLClassLoader for the given URLs. The URLs will be
* searched in the order specified for classes and resources after first
* searching in the specified parent class loader. Any URL that ends with
* a '/' is assumed to refer to a directory. Otherwise, the URL is assumed
* to refer to a JAR file which will be downloaded and opened as needed.
*
* <p>If there is a security manager, this method first
* calls the security manager's {@code checkCreateClassLoader} method
* to ensure creation of a class loader is allowed.
*
* @param urls the URLs from which to load classes and resources
* @param parent the parent class loader for delegation
* @exception SecurityException if a security manager exists and its
* {@code checkCreateClassLoader} method doesn't allow
* creation of a class loader.
* @exception NullPointerException if {@code urls} is {@code null}.
* @see SecurityManager#checkCreateClassLoader
*/
public URLClassLoader(URL[] urls, ClassLoader parent)

If class "com.thoughtworks.xstream.io.xml.DomDriver" load from boot classloader boot can no longer with the same name.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Extensions loaded in not isolated classloader

Postby Lapo » 21 Oct 2016, 07:45

Is there a specific reason why you need that version of XStream?
Can't you work with the libraries provided in SmartFoxServer?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
fameing
Posts: 13
Joined: 18 May 2015, 10:20

Re: Extensions loaded in not isolated classloader

Postby fameing » 21 Oct 2016, 09:49

I use spring-cloud-netflix http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html
My architecture user many Microservices. Use by REST (eureka + ribbon + Feign)
But eureka client use xstream-1.4.2.jar !
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Extensions loaded in not isolated classloader

Postby Lapo » 21 Oct 2016, 09:55

Sorry we don't support that particular release. If you want you can try to replace what we use with this one, although it may not work if they have modified method signatures or package names etc...
Lapo

--

gotoAndPlay()

...addicted to flash games
fameing
Posts: 13
Joined: 18 May 2015, 10:20

Re: Extensions loaded in not isolated classloader

Postby fameing » 21 Oct 2016, 12:13

I tried to replace SFS lib to the new version. But nothing comes out.

Exception: com.thoughtworks.xstream.io.StreamException
Message: Cannot create XmlPullParser
Description: Unexpected error during Server boot. The server cannot start.
Solution: Please email us the content of this error message, including the stack trace to support[at]smartfoxserver.com
+--- --- ---+
Stack Trace:
+--- --- ---+
com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:56)
com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:65)
com.thoughtworks.xstream.XStream.fromXML(XStream.java:921)
com.smartfoxserver.v2.config.DefaultConfigLoader.loadCoreSettings(DefaultConfigLoader.java:39)
com.smartfoxserver.v2.config.SFSConfigurator.loadConfiguration(SFSConfigurator.java:50)
com.smartfoxserver.v2.SmartFoxServer.start(SmartFoxServer.java:261)
com.smartfoxserver.v2.Main.main(Main.java:27)
fameing
Posts: 13
Joined: 18 May 2015, 10:20

Re: Extensions loaded in not isolated classloader

Postby fameing » 21 Oct 2016, 12:33

Can use analog WebappClassLoader for complete zone isolation in SFS2x ?
That there has no such a problem with different zones!
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Extensions loaded in not isolated classloader

Postby Lapo » 21 Oct 2016, 14:05

Sorry, I have no idea what a WebappClassLoader is. It sounds like a specialized class found in some web-based framework. It certainly doesn't belong in the JDK.

In any case SmartFoxServer uses standard class loaders, there isn't a way to replace them on the fly.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
fameing
Posts: 13
Joined: 18 May 2015, 10:20

Re: Extensions loaded in not isolated classloader

Postby fameing » 24 Oct 2016, 08:24

As one of the options used startup of extension and In the current thread to take a class loader and has taken parent (System ClussLoader) ?

Code: Select all

jarClassLoader = new URLClassLoader(var14, parentClassLoader.getParent());


In this way, the library will not fall from the SFS\lib
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Extensions loaded in not isolated classloader

Postby Lapo » 24 Oct 2016, 14:01

I am sorry, I don't understand what you're trying to ask or say.
At the moment there isn't a support to change the way class loaders work, if this is what you are asking. Otherwise please rephrase your question.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
fameing
Posts: 13
Joined: 18 May 2015, 10:20

Re: Extensions loaded in not isolated classloader

Postby fameing » 24 Oct 2016, 14:23

How do we get out of this situation, with different versions? How can we solve this problem?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Extensions loaded in not isolated classloader

Postby Lapo » 24 Oct 2016, 17:13

As I suggested you can try replacing the XStream library included in the SmartFoxServer release with a new one.

I've tested using SFS2X 2.11 and removing the XStream jar, then I downloaded the latest XStream 1.4.9 from their website:
http://x-stream.github.io/download.html
along with the XMLPull library found in the "optional download" section. I copied the two jars to SFS2X/lib/ and started the server which didn't complain :)

I've tested the AdminTool which does heavy use of XStream and everything seems to be working fine.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
fameing
Posts: 13
Joined: 18 May 2015, 10:20

Re: Extensions loaded in not isolated classloader

Postby fameing » 25 Oct 2016, 09:19

Thanks, it works ;))))))
maimonoded
Posts: 26
Joined: 14 Jul 2010, 13:44

Re: Extensions loaded in not isolated classloader

Postby maimonoded » 23 Jan 2018, 10:47

Hi,
I'm pumping this question back up because we have same issue on our side today.

1. is there is any other solution for this issue, instead of replacing the jars inside smartfox? The issue can happen in any kind of jar, and not only this one.
2. Another question is, what would you suggest is the right way for using Spring inside an extension?
3. Another question about the class loader is: will it add XML files to the class path or only jars? currently it looks to us that only jar work

Thank you,
Oded Maimon
Playstudios

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Google [Bot] and 63 guests