unnivm / jwebsocket

Automatically exported from code.google.com/p/jwebsocket
1 stars 0 forks source link

JWEBSOCKET_HOME override/ignore #149

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. embed JWebSocket server (1.0-nb20105) inside a custom web application, and 
setup ContextListener etc.
2. run the webapp

What is the expected output? What do you see instead?

expecting normal servlet context startup
instead, a NullPointerException was received
during call to JWebSocketFactory.start()
more specifically from within JWebSocketFactory.setProperties()
reason is there is no JWebSocketServerConstants.JWEBSOCKET_HOME environment 
variable
and it is not needed here, alternative configuration location will be provided

What version of the product are you using? On what operating system?

1.0-nb20105 on Windows7

Please provide any additional information below.

need to override JWebSocketServerConstants.JWEBSOCKET_HOME environment variable 
with alternative configuration location provided by webapp implementation

Original issue reported on code.google.com by eliasbal...@gmail.com on 8 Jan 2012 at 1:00

GoogleCodeExporter commented 9 years ago
a quick source code investigation revealed many calls  
toSystem.getenv(JWebSocketServerConstants.JWEBSOCKET_HOME) throughout whole 
JWebSocket implementation and all of them used to retrieve the configuration 
files

I believe that these calls need to be replaced with calls to 
System.getProperty(JWebSocketServerConstants.JWEBSOCKET_HOME which is initially 
being assigned at startup (JWebSocketFactory.start, 
JWebSocketFactory.setProperties)

thus, initially overriding JWebSocketServerConstants.JWEBSOCKET_HOME in 
JWebSocketFactory will force the alternative configuration location to whole 
JWebSocket implementation

it is just an idea, I cannot be sure if this will work

please advise and provide a solution/workaround without using environment 
variables

Original comment by eliasbal...@gmail.com on 8 Jan 2012 at 1:15

GoogleCodeExporter commented 9 years ago
this issue is a duplicate of issue #135 - "jwebsocket will not run on tomcat 
without JWEBSOCKET_HOME defined (fix suggested)"

Original comment by eliasbal...@gmail.com on 8 Jan 2012 at 1:18

GoogleCodeExporter commented 9 years ago
it actually worked, application started successfully

I modified my local copy replacing all 
"System.getenv(JWebSocketServerConstants.JWEBSOCKET_HOME)" calls with 
"System.getProperty(JWebSocketServerConstants.JWEBSOCKET_HOME)"

and 

explicitly setting JWebSocketServerConstants.JWEBSOCKET_HOME property using 
"System.setProperty(JWebSocketServerConstants.JWEBSOCKET_HOME)" before calling 
"JWebSocketfactory.start()" in ContextListener

Original comment by eliasbal...@gmail.com on 8 Jan 2012 at 3:37

GoogleCodeExporter commented 9 years ago
I forgot to mention,
I also modified implementation for JWebSocketfactory.setProperties
...
if (
    System.getProperty(JWebSocketServerConstants.JWEBSOCKET_HOME)
    ==null
) {
    System.setProperty(
        JWebSocketServerConstants.JWEBSOCKET_HOME,
        System.getenv(JWebSocketServerConstants.JWEBSOCKET_HOME)
        );
}
...

please provide a more efficient workaround/solution and include in next release

Original comment by eliasbal...@gmail.com on 8 Jan 2012 at 7:55

GoogleCodeExporter commented 9 years ago
furthermore, I see many references to environment variable JWEBSOCKET_HOME in 
configuration files
which are replaced in implementation with values of respective environment 
variables in Tools.expandEnvVars
e.g. ${JWEBSOCKET_HOME} is replaced with value of environment variable 
JWEBSOCKET_HOME

replacing implementation of Tools.expandEnvVars in local copy to use java 
properties instead of environment variables

please provide a more efficient workaround/solution and include in next release

Original comment by eliasbal...@gmail.com on 8 Jan 2012 at 10:06

GoogleCodeExporter commented 9 years ago
replaced implementation of Tools.expandVars giving priority to Java properties 
instead of environment variables

public static String expandEnvVars(String aString) {
    Map<String, String> vars = new HashMap<String, String>();
    Properties properties = System.getProperties();
    String property;
    for (Object key : properties.keySet()) {
        if (key instanceof String) {
            property = (String)key;
            vars.put(
                property,
                properties.getProperty(
                    property
                    )
                );
        }
    }
    aString = expandVars(aString, vars, EXPAND_CASE_INSENSITIVE);
    vars = System.getenv();
    return expandVars(aString, vars, EXPAND_CASE_INSENSITIVE);
}

it worked,
however, I am not sure whether this is the best workaround

please provide a more efficient workaround/solution and include in next release

Original comment by eliasbal...@gmail.com on 8 Jan 2012 at 10:41