This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JForum and the fly likes Template location incorrect behind corporate site Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » JForum
Bookmark "Template location incorrect behind corporate site" Watch "Template location incorrect behind corporate site" New topic
Author

Template location incorrect behind corporate site

Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
Preface: I have the forum working perfectly in the /Tomcat_6.0/webapps/ directory.

Setup: I have merged the config/lib/web.xml files together within our corporate website to run in the path http://testserver/ap/secure/forum. Our website security (testserver/ap/secure/) should restrict access the forum and I will use SSO later, but for now it uses default authentication.

Problem: As soon as I move the forum behind our secure Java application (physical directory = e:/Tomcat_6.0/webapps/thr3/ap/secure/forum/...), the security forces me to logon and then forwards me to http://testserver/ap/secure/forum/forums/list.page as it should. The problem is that I get the error below in a browser:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet.init() for servlet jforum threw exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Thread.java:619)

root cause

net.jforum.exceptions.ForumStartupException: Error while starting JForum
freemarker.cache.FileTemplateLoader$1.run(FileTemplateLoader.java:114)
java.security.AccessController.doPrivileged(Native Method)
freemarker.cache.FileTemplateLoader.<init>(FileTemplateLoader.java:106)
net.jforum.JForumBaseServlet.init(JForumBaseServlet.java:123)
net.jforum.JForum.init(JForum.java:91)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Thread.java:619)

root cause

java.io.FileNotFoundException: E:\Tomcat_6.0\webapps\thr3\templates does not exist.
freemarker.cache.FileTemplateLoader$1.run(FileTemplateLoader.java:114)
java.security.AccessController.doPrivileged(Native Method)
freemarker.cache.FileTemplateLoader.<init>(FileTemplateLoader.java:106)
net.jforum.JForumBaseServlet.init(JForumBaseServlet.java:123)
net.jforum.JForum.init(JForum.java:91)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Thread.java:619)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
Apache Tomcat/6.0.18


I can access any image files using its path (i.e. http://testserver/ap/secure/forum/templates/default/images/folder.gif) so I know the jforum application is in the correct place. Going to the root of the jforum URL forwards me to ../forum/forums/list.page so it is working, but the path to the template is wrong. It should be E:\Tomcat_6.0\webapps\thr3\ap\secure\forum\templates. Any idea why the templates are not in the correct path?

Edit: bold template path in stack trace.

[originally posted on jforum.net by Opsman]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
The location of a lot of jforum files is hard coded based on the location of the root context. I.e. what can be determined from the getRealPath and getContextPath information.

FWIW, even if the template files are not secure, they don't represent a security problem since they are called and populated from the jForum servlet which it sounds like you have secured.

You will also have to have the images directory at the root as the template HTML uses them.

Note that file uploads and avatar images are also expected to be located in the web app root directory.
[originally posted on jforum.net by monroe]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
Every time I think we are getting closer, another problem shows up. :? The only change has been that I moved the images and templates folders into the root of our web app (thr3). When we go to the forum page (http://testserver/ap/secure/forum), it forwards us to http://testserver/thr3/ap/secure/forum/forums/list.page, but gives a 404 error. In the stack trace, I can see that directories are being referenced incorrectly for jforum with a combination of / and \ in the directory path. BTW--This is a Windows server.

Here is our stack trace (the authentication is from our web app to access the private forum and worked correctly):

17:09:17,633 INFO [JForumBaseServlet:110] - Starting JForum. Debug mode is true
17:09:17,649 INFO [ConfigLoader:227] - Using cache engine: net.jforum.cache.DefaultCacheEngine
17:09:17,649 INFO [ConfigLoader:240] - Creating an instance of net.jforum.repository.BBCodeRepository
17:09:17,649 INFO [ConfigLoader:240] - Creating an instance of net.jforum.repository.RankingRepository
17:09:17,649 INFO [ConfigLoader:240] - Creating an instance of net.jforum.repository.SmiliesRepository
17:09:17,649 INFO [ConfigLoader:240] - Creating an instance of net.jforum.repository.ForumRepository
17:09:17,665 INFO [ConfigLoader:240] - Creating an instance of net.jforum.repository.TopicRepository
17:09:17,665 INFO [ConfigLoader:240] - Creating an instance of net.jforum.SessionFacade
17:09:17,665 INFO [ConfigLoader:240] - Creating an instance of net.jforum.repository.PostRepository
17:09:17,665 INFO [ConfigLoader:240] - Creating an instance of net.jforum.repository.Tpl
17:09:17,665 INFO [ConfigLoader:240] - Creating an instance of net.jforum.repository.RolesRepository
17:09:17,665 INFO [ConfigLoader:240] - Creating an instance of net.jforum.repository.SecurityRepository
17:09:17,665 INFO [ConfigLoader:240] - Creating an instance of net.jforum.repository.BanlistRepository
17:09:17,790 INFO [FileMonitor:86] - Watching E:\Tomcat_6.0\webapps\thr3/WEB-INF/config/languages/en_US.properties
17:09:17,805 INFO [ConfigLoader:211] - Loading JDBC driver net.jforum.dao.mysql.MysqlDataAccessDriver
17:09:17,868 INFO [FileMonitor:86] - Watching E:\Tomcat_6.0\webapps\thr3/WEB-INF/config/database/generic/generic_queries.sql
17:09:17,868 INFO [FileMonitor:86] - Watching E:\Tomcat_6.0\webapps\thr3/WEB-INF/config/database/mysql/mysql.sql
17:09:17,868 INFO [FileMonitor:86] - Watching E:\Tomcat_6.0\webapps\thr3/WEB-INF/config/SystemGlobals.properties
17:09:17,868 INFO [FileMonitor:86] - Watching E:\Tomcat_6.0\webapps\thr3/WEB-INF/config/jforum-custom.conf
17:09:18,024 INFO [MLog:80] - MLog clients using log4j logging.
17:09:18,071 INFO [C3P0Registry:170] - Initializing c3p0-0.9.1-pre9 [built 23-September-2006 01:47:24; debug? true; trace: 10]
17:09:18,149 INFO [AbstractPoolBackedDataSource:300] - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 120000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 7f29b00a, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 7f29b00a, idleConnectionTestPeriod -> 3600, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost:3306/jforum?user=root&password=sa&autoReconnect=true&useNewIO=false&zeroDateTimeBehavior=convertToNull&useServerPrepStmts=false&dumpQueriesOnException=true&jdbcCompliantTruncation=false, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 10, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 5, numHelperThreads -> 3, preferredTestQuery -> null, properties -> {}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 180, usesTraditionalReflectiveProxies -> false ]
17:09:23,571 WARN [LoggerListener:60] - Authentication event AuthenticationSuccessEvent: smholmes@travelhost.com; details: org.acegisecurity.ui.WebAuthenticationDetails@b364: RemoteIpAddress: 172.17.2.30; SessionId: 7394488A72E12523A7DAE845D5CF7AFB
17:09:23,571 WARN [LoggerListener:60] - Authentication event InteractiveAuthenticationSuccessEvent: smholmes@travelhost.com; details: org.acegisecurity.ui.WebAuthenticationDetails@b364: RemoteIpAddress: 172.17.2.30; SessionId: 7394488A72E12523A7DAE845D5CF7AFB
17:09:23,587 INFO [ConfigLoader:57] - Loading clickstream config from E:\Tomcat_6.0\webapps\thr3/WEB-INF/config/clickstream-jforum.xml

Any idea where the problem may be?
[originally posted on jforum.net by Opsman]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
The "incorrect directory reference" is not an issue. Unless you're running a VERY old version of Java (like 1.2?), all the Java IO stuff treats '\' and '/' in file strings as path separators. The low level classes all translate them to the native system path separator when it passes the request off to the OS. This makes writing portable code much easier.

However, the actual Strings stay the same and can look odd. Especially if they are created from a combination of info returned by the App Container which will have the native separators and app code.. but they still work.

I think your underlying problem is that the templates have to write URLs. They do this via a couple of ways. Either using the built-in Freemarker $context property or the JForumContext.encodeURL method. You may need to write your own URL generators and replace the defaults in the templates to get the URLs you need.
[originally posted on jforum.net by monroe]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Template location incorrect behind corporate site
 
Similar Threads
SSO error message "RemoteUserSSO cannot be cast LoginAuthenticator"
cache memory problem.
Does anyone get the following error
take in file from client machine
FrontMan: Startup Error.