Amazon S3 in Europe

Tuesday, November 6th, 2007

In today’s newsletter from Amazon Web Services, I found out that Amazon S3 is launching storage in Europe. Some of the prices are slightly higher (compare here) but for the potentially higher EU transfer speeds, it should be well worth it.

As of now, the code samples appear to have been updated to support creation of buckets located in the EU, but the documentation is still the old one. Some of the more popular S3 tools, such as S3Sync and JetS3t, are also yet to be updated.

Update: S3Sync and JetS3t now support EU buckets, and updated documentation on how to create them using the API is available here.

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.

XSL for Formatting OPML

Wednesday, July 21st, 2004

I just wrote a simple XSL file that formats OPML files which contain lists of feeds/websites, like the ones you get when exporting feed listings from a feed reader. In particular, I wanted to be able to convert the OPML files created by FeedDemon to XHTML, and put them on this site.

Here it is, in case you want to have it:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/1999/xhtml">
 <xsl:output method="xml" encoding="UTF-8"
  omit-xml-declaration="yes" indent="yes"
  doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
  doctype-system=
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" />

 <xsl:template match="/opml">
  <html>
   <head>
    <title>
     <xsl:apply-templates select="head/title" /> (OPML)
    </title>
    <meta http-equiv="Content-Type"
     content="text/html; charset=UTF-8" />
   </head>
   <body>
    <h1><xsl:apply-templates select="head/title" /></h1>
    <ul class="opml">
     <xsl:apply-templates select="body/outline" />
    </ul>
   </body>
  </html>
 </xsl:template>

 <xsl:template match="outline">
  <li>
   <a href="{@htmlUrl}"><xsl:value-of select="@text" /></a>
  </li>
 </xsl:template>

</xsl:stylesheet>

It’s not much, but it’s a start, and it does what I want it to. Feel free to use and modify it.

Entries (RSS)