-1

I have gone through the solution provided by peter for setting system properties dynamically in multithreading with the below link

System.setProperty used by a thread impacts other thread in communication to external network elements. How to resolve it?

But the problem is, tomcat is not considering the system properties that i am setting. So how to achieve this ?

I have mutiple threads in a management station connecting to different servers through RMI APIs and download the stub accordingly. I am referring to the same name jar file as a stub at different locations for each server. note: jar versions may differ at each location. Eg: MS --> serv1 --> stublocation (http://15.xx.xx.xx:port/myfolder/myapp.jar) MS --> serv2 --> stublocation (http://15.yy.yy.yy:port/myfolder/myapp.jar)

I want to set java.rmi.server.codebase system property for each of these locations dynamically and make it threadLocal so that it will not override each other settings.

With the example provided in the above link, I hope to achieve the solution for above problem.

But to test the resolution, i am unable to set these properties in tomcat. Tomcat is ignoring the system properties that i am setting. Tomcat is considering the JVM arguments that are set through catalina.bat or service.bat but not through the system.properties as i need it to be dynamically set.

Any help here will be great! Thanks.

user207421
  • 305,947
  • 44
  • 307
  • 483

2 Answers2

0

The java.rmi.server.codebase property is set at the JVM which exports remote objects. Setting it in a client JVM accomplishes exactly nothing, unless that JVM exports remote objects too, i.e. callbacks. It doesn't seem likely that you will be dealing with multiple versions of your own application within the same JVM.

In short, your question doesn't make sense.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • My question is real production scenario where we were using java.rmi.server.usecodebaseonly=false and this option is reported as java security vulnerability issue at customer site. Hence I am trying to use java.rmi.server.codebase property to solve the problem. – user3789817 Mar 19 '18 at 16:20
0

As EJP points out, (successfully) setting that property is unlikely to achieve what you want.

But there are a couple of other important misconceptions in your question.

  1. Tomcat doesn't implement RMI. RMI is actually implemented by the Java SE itself. Therefore, it is not up to Tomcat to pay attention to those property settings.

  2. Typical Java services that use system properties for configuration purposes do it once during the lifetime of the JVM. Typically this happens when the relevant subsystem (e.g. RMI) initializes. The problem with setting system properties programmatically ("dynamically") is ensuring that they are set before the relevant initialization code uses them.


Going back to what you are trying to achieve, it seems that it is the same as or similar to this:

Nobody was able to help that person, and he ended up solving his problem another way. (I think he is saying that he handled serialVerionId mismatches with customized readObject / writeObject methods ...)

But his Q&A offers one possible way to solve the problem. It is a bit complicated.

The RMI system allows you to provide your own classloader for RMI to use. You do this by implementing the RMIClassLoaderSpi API and then registering your providers as described in the RMIClassLoader javadoc. That's one part of the equation.

The problem is that the RMI classloader is global, but you want RMI on different threads to use different class loaders.

Solution: delegate!

  • You implement your custom RMI classloader to delegate to one of a number of different classloaders, depending on which versions of the remote APIs that the context requires.

  • Since you have proposed using thread locals, you can declare a thread local variable for use by the custom RMI classloader, and have it use that variable's value to decide which classloader to delegate to.

CAVEAT ... I have not tried this!

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216