Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

ggrandes/systemclassloaderproperties

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SystemClassLoaderProperties

When you want light isolation of "System Properties" by ClassLoader in a retrocompatible way... SystemClassLoaderProperties provides Hierarchical Properties associated to a ClassLoader, maintaining the behavior of standard System.getProperty. Open Source Java project under Apache License v2.0

Current Stable Version is 1.0.0


DOC

Usage Example in a standalone Java application (programmatically)

public static void main(final String[] args) {
    // Install SystemClassLoaderProperties
    SystemClassLoaderProperties.getInstance().takeover();
    // Normal Usage
    System.setProperty("xxxxx", "value");
    System.out.println(System.getProperty("xxxxx"));
}

Usage Example in a standalone Java application (using a JavaAgent)

java -javaagent:<directory>/lib/systemclassloaderproperties-x.x.x.jar com.acme.YourClass

Usage Example in a Tomcat (using a JavaAgent)

# tomcat/bin/setenv.sh
CATALINA_OPTS="$CATALINA_OPTS -javaagent:<directory>/lib/systemclassloaderproperties-x.x.x.jar"
Proof Of Concept (Servlet Container / Tomcat)
Sample ClassLoader Hierarchy (Tomcat 7)
//      Bootstrap
//          |
//       System
//          |
//       Common
//       /     \
//  Webapp1   Webapp2
Dummy Test JSP (test.jsp) - show last value
<%
// One counter by each Webapp
Integer x = Integer.valueOf(System.getProperty("dummy.test", "0"))+1;
out.print(getClass().getClassLoader() + ":" + System.setProperty("dummy.test", String.valueOf(x)));
%>
Simple Test (bash/curl)
for j in a b c; do {
  for i in 1 2; do {
    curl http://localhost:8080/Webapp${i}/test.jsp
  } done
} done
Output will be:
org.apache.jasper.servlet.JasperLoader@7064ce:null
org.apache.jasper.servlet.JasperLoader@7df6d9:null
org.apache.jasper.servlet.JasperLoader@7064ce:1
org.apache.jasper.servlet.JasperLoader@7df6d9:1
org.apache.jasper.servlet.JasperLoader@7064ce:2
org.apache.jasper.servlet.JasperLoader@7df6d9:2
Note about Security: You may need a SecurityManager if you want strong security (this "light isolation" can be easily circumvented in a hostile environment).

MAVEN

<dependency>
    <groupId>org.javastack</groupId>
    <artifactId>systemclassloaderproperties</artifactId>
    <version>1.0.0</version>
</dependency>

Inspired in ClassLoader, this code is Java-minimalistic version.

Packages

No packages published

Languages