[JAVASERVERFACES-1885] GAE incompatibility in WebConfiguration class Created: 07/Dec/10  Updated: 25/Oct/12  Resolved: 25/Oct/12

Status: Closed
Project: javaserverfaces
Component/s: None
Affects Version/s: 2.0.4
Fix Version/s: 2.1.15, 2.2.0-m06

Type: Bug Priority: Trivial
Reporter: nick_belaevski Assignee: Unassigned
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: 2 days
Time Spent: Not Specified
Original Estimate: 2 days

Attachments: Text File changebundle.txt    
Status Whiteboard:

size_small importance_large


 Description   

Google App Engine restricts access to InitialContext while Mojarra uses it for initialization.
Here is the proposed change for WebConfiguration#canProcessJndiEntries:

private boolean canProcessJndiEntries() {

try

{ Util.getCurrentLoader(this).loadClass("javax.naming.InitialContext").getConstructors(); }

catch (Throwable e) {
if (LOGGER.isLoggable(Level.FINE))

{ LOGGER.fine( "javax.naming is unavailable. JNDI entries related to Mojarra configuration will not be processed."); }

return false;
}
return true;

}



 Comments   
Comment by yonatan [ 06/Aug/11 ]

The above suggestion doesn't detect properly if InitialContext is available on GAE 1.5.1, since Google are using Java Agent to verify the whitelist class loading, rather than the SecurityManager.

My suggestion is:

com.sun.faces.config.WebConfiguration
... 
private boolean canProcessJndiEntries() {
  try {
    Util.getCurrentLoader(this).loadClass("javax.naming.InitialContext").getConstructor().newInstance();
  } catch (Exception e) {
    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine("javax.naming is unavailable.  JNDI entries related to Mojarra configuration will not be processed.");
    }
    return false;
  }
  return true;
}
...
Comment by Ed Burns [ 09/Aug/11 ]

Thanks for reporting this and supplying a suggested fix. GAE support is important to me personally because the website for my book is running on JSF on GAE <http://jsfcompref.com>.

Comment by Hanspeter Duennenberger [ 27/Apr/12 ]

Hello.

I'm in the middle of trying to run a JSF 2.2 (own build) app on GAE - and the solution outlined above does not work.
GAE already complains when InitialContext class is test-loaded with an Exception:

java.lang.NoClassDefFoundError: javax.naming.InitialContext is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
at com.sun.faces.config.WebConfiguration.processJndiEntries(WebConfiguration.java:687)
at com.sun.faces.config.WebConfiguration.<init>(WebConfiguration.java:134)
...

I think the best solution is outlined by http://digitaljoel.nerd-herders.com/2009/12/21/jsf-2-0-2-and-google-app-engine/ - an additional context-param to disable JNDI usage.

Will try it and in case it works add the according changebundle here.

Cheers
Hanspeter

Comment by Hanspeter Duennenberger [ 02/May/12 ]

Added changebundle based on proposal from http://digitaljoel.nerd-herders.com/2009/12/21/jsf-2-0-2-and-google-app-engine/

Hi Ed.

With that change I could successfully run an application on GAE.
I also propose this fix to be applied to the 2.0 and 2.1 branches.
Do you agree?

Cheers
Hanspeter

Comment by Hanspeter Duennenberger [ 02/May/12 ]

disussing this on chat has lead to simpler proposal from Manfred. Also catching NoClassDefFoundException in WebConfiguration.canProcessJNDIEntries should do the trick. I'll try tomorrow and add the result then.

Cheers
Hanspeter

Comment by Hanspeter Duennenberger [ 03/May/12 ]

Catching NoClassDefFoundException in WebConfiguration.processJndiEntries() does work. The updated changebundle contains this change. No need for an additional context-param.
I could successfully run GAE based JSF app locally. Unfortunately I cannot deploy to GAE from work (some proxy issue), but I'll try from home later on.

Again, I think this should be added to trunk, 2.1- and 2.0 branch.

Cheers
Hanspeter

Comment by Manfred Riem [ 03/May/12 ]

r=mriem

Comment by Hanspeter Duennenberger [ 05/May/12 ]

Added to trunk (2.2)

Fixes http://java.net/jira/browse/JAVASERVERFACES-1885, r=mriem

  • catch NoClassDefFoundError thrown by GAE while trying to instantiate InitialContext

M C:/cs/ws/mojarra_trunk/Mojarra/jsf-ri/src/main/java/com/sun/faces/config/WebConfiguration.java
Committed revision 9926

Comment by Manfred Riem [ 28/Jun/12 ]

Can you also add the fix to the 2.1 branch?

Comment by Manfred Riem [ 25/Oct/12 ]

Applied to 2.1 branch,

commit -m "Fixes http://java.net/jira/browse/JAVASERVERFACES-1885, Backported to 2.1"
Sending jsf-ri/src/main/java/com/sun/faces/config/WebConfiguration.java
Transmitting file data ...
Committed revision 10918.

Generated at Tue Mar 31 09:10:15 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.