aspose file tools*
The moose likes JForum and the fly likes URL namespacing for JForum Pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JForum
Bookmark "URL namespacing for JForum Pages" Watch "URL namespacing for JForum Pages" New topic
Author

URL namespacing for JForum Pages

robert crowther
Ranch Hand

Joined: Oct 19, 2013
Posts: 41
    
  10
This is what I would like to do,

(host)/(appname)/(extra URL element for namespacing)/jforumURLelements)
e.g.
http://localhost:8080/myApp/forum/forums/list.page

/forum/ being the extra namespacing element. JForum seems to have plenty of configuration on board to do something like this (though I do not know if that is the intention of these options). Here's what I have so far (with notes),

- web.xml
<filter-mapping>
<filter-name>clickstream-jforum</filter-name>
<!--
<url-pattern>*.page</url-pattern>
-->
<url-pattern>/forum/*</url-pattern>
</filter-mapping>

<servlet-mapping>

<servlet-name>jforum</servlet-name>
<!--
<url-pattern>*.page</url-pattern>
-->
<url-pattern>/forum/*</url-pattern>
</servlet-mapping>

(if JForum URLs are revised in this way, then this is a nice mapping. Though it may affect code elsewhere?)



- System Globals
forum.link = http://localhost:8080/forum/jforum
(in simpler configurations I found this affected the links, and does change them as I wish)

homepage.link = http://localhost:8080/forum/
(seemed deductive?)

# If "true", all redirect URLs will include the value of "redirect.base.url" as prefix
#redirect.absolute.paths = false
redirect.absolute.paths = true
(wouldn't have touched this to start with, tried without, but here as reference)

# This property is only used when redirect.absolute.paths = true. You can use
# it to force a redirect prefix other than forum.link. It is specially useful
# when using proxied.context.path
#redirect.base.url = ${forum.link}
redirect.base.url = http://localhost:8080/forum/jforum
(wouldn't have touched this to start with, tried without, but here as reference)

# In case you're using mod_proxy or something similar, you can set this
# property to force JForum to use a specific context path.
#
# Leave it blank if you don't need to use it.
#
# Note that if you set this property, you will also want to properly
# set "forum.link" to use the same context path.
proxied.context.path = http://localhost:8080/forum/jforum
(this one seems key. Looking at code, this configuaration option seems to be a complete substitution for any path derived from servlet data)


I've also tinkered with the templates path, but simpler configurations suggest this is not the problem.

I'm also aware that these changes may affect directory structure but, being new to Java, I don't have those effects to hand. I found a post elsewhere on CodeRanch which explained Tomcat, failing to find a sevlet at an expected location, would look, before giving up, in web root too. This gives me some hope this is possible, by a combination of configuration and directory organisation...

(Why not use a rewriter? I'm using http://tuckey.org/urlrewrite/ at the moment, but this would be nice and robust)
robert crowther
Ranch Hand

Joined: Oct 19, 2013
Posts: 41
    
  10
No wonder nobody swaps code much Java code - it cost so much to get there, tiredness kicks in at the outcome.

A few clues,

appBase > WEB-INF > config > SystemGlobals

contains some interesting config variables,

freemarker.extra.template.path =

Must be of use, nice provision. However, if code is kept tidy, by sinking into a folder under the web Root, Java's "physical layout reflecting package structuring" concept kicks in, and there is still an extra URL element to be dealt with. My guess is this is intended for extending JForum itself in a modular and maintainable fashion.

proxied.context.path =

I finally got to source, and this entirely replaces/overrides the web context in the JForum servlet. This seems promising, and indeed it can introduce an extra URL element. But then all the links must be altered using forum.link, and the redirects too,

redirect.absolute.paths = true
redirect.base.url = /forum

and I seem to recall this may mean rebuilding the structure of all static resources. Yuch.

Also, I tried mangling with the powerful and very cool UrlRewriter .jar. But this mostly means grappling with URLs like *.page, which is bad regex. And UrlRewriter rewrites on the way out, which I suppose can also be configured to rewrite, but this is sledgehammer behaviour. Might be good for some sites...

When finally I came across this Stackoverflow post,

http://stackoverflow.com/questions/870150/how-to-access-static-resources-when-using-default-servlet

...build yourself a custom Filter from "/*". No outbound effects, no changing in config files, no template demolition - an internal affair to forward short site URLs to a seperate sevlet. My version even talks to the servlet to handle root URLs to home.
robert crowther
Ranch Hand

Joined: Oct 19, 2013
Posts: 41
    
  10
I've revisited this, and feel I havn't explained enough by far.

A way of (reasonably cleanly) building a supplementary site with seperate servlet into exisiting JForum structure

Don't use config, it has too many repercussions. Don't use UrlRewriter, it can't handle a base separation from a URL to add an additional URL element (or is overload).

Reverse the thinking. Add a URL namespace for the site, not JForum.

Steps

Follow the Stackoverflow post above. Build yourself a custom Filter from "/*". Use it to namespace known site URLs into site URLs.

e.g.

/about

becomes,

/mysite/about

The filter, however you code it, must ignore (by forwarding) static resources (e.g. .jpgs, .js etc.), and JForum URLs (which all have .page extensions).


Once the filter is in place, web.xml (or servlet annotation) can be used to route the now namespaced site URLs to an appropriate supplementary servlet e.g.



Now we have a seperately handled site, with site URLs clearly signalled within web.xml.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URL namespacing for JForum Pages
 
Similar Threads
Jforum + GWT
404 When trying to install 2.1.6
Spring security sample is not working? Please help.
Jforum SSO - restrict direct forum access => redirect to login page if not loged in please help!!!
bytearray image decoding