Archive for the ‘Java’ Category

Rules for Url Rewrite Filter

Tuesday, July 27th, 2004

For those of you who use the excellent Url Rewrite Filter, a Java Web Filter which allows you to rewrite URLs before they get to your code, here are a couple of more-or-less useful rewrite rules that I’ve created.

The first rule redirects access made through a non-preferred domain or subdomain name to the preferred one. For example, if you’re using the example.com domain name for your website, you might want to redirect http://example.com/page.jsp to http://www.example.com/page.jsp.

<rule>
 <name>Domain Name Check</name>
 <condition name="host"
  operator="notequal">www.example.com</condition>
 <!–
     Needed if using a version prior to 2.0-alpha:
     <condition name=”host”
      operator=”notequal”>www.example.com</condition>
 –>
 <from>(.*)</from>
 <to type=”redirect”>http://www.example.com/context$1</to>
</rule>

Obviously, just replace www.example.com with the domain name that you prefer, and context with the context which your webapp is deployed at, or if using the root context, remove /context altogether.

I should mention that I didn’t write the same condition twice by mistake. There seems to be a bug in UrlRewriteFilter (version 1.2) which causes such conditions to be ignored unless written twice. If somebody hasn’t filed a report on that one already, I guess I better do it. Update: Paul Tuckey, the creator of Url Rewrite Filter, emailed me to let me know that this problem has been fixed in version 2.0-alpha.

The second rule blocks access to JSPs (or anything you want) that you don’t want to be accessible by anyone, and shows the 403: Forbidden error page which you’ve configured in your web.xml file.

<rule>
 <name>JSP block</name>
 <from>^/jsp/.*$</from>
 <set type="request" name="status_code">403</set>
 <to>/jsp/sendError.jsp</to>
</rule>

Where /jsp/sendError.jsp contains the following:

<%
 response.sendError(Integer.parseInt(
  (String)request.getAttribute("status_code")));
%>

Note that you could use any status code you want; if you want to give the user a 404: Not Found error, just write 404 instead of 403 in the rule configuration.

Now, what’s the best RegExp to find out whether a given user-agent is from a cell phone? Hmm.

Weblog Added to java.blogs

Tuesday, July 20th, 2004

The Java category (feed) of this weblog is now aggregated on java.blogs. I thought it would be a good idea to add it there, and the referrer statistics seem to prove me right.

Since I added the feed of the Java category, entries like this one won’t show up on java.blogs. After all, I’ve been posting quite a lot of entries unrelated to Java, so I thought that would be the best way to do it.

Anyhow, all of you who’ve come here from java.blogs, and all other new readers as well, welcome!

J2SE 1.5…Um, 5.0

Monday, July 12th, 2004

Ok, what was going to be Java 2 Platform, Standard Edition version 1.5 is now going to be Standard Edition version 5.0. I didn’t like Sun’s way of naming the versions of their products before, and I don’t like it now.

Everything is still Java version 2 and I think it’d be hard to do a third version since the 2 (J2SE, J2EE) has become very much a part of the brand names. Obviously, the 2 doesn’t have much of a meaning anymore. So, when what everyone expected to be J2SE 1.5 is suddenly 5.0, it just adds to the mess. I wonder who came up with that idea.

Well, let’s leave that aside. Here’s a pretty good article for catching up with what’s new in 5.0 (though the page still says 1.5).

Generics and autoboxing are, in my opinion, good features. The enumerated types and static imports are good as well. I guess one can always question how those features have been implemented, and while they don’t actually bring much new, I believe they will make development faster and easier. I am looking forward to J2SE 5.0.

Entries (RSS)