The Kat's Work - Blog
Main | Blog | Registration | Login
Friday
2024-04-19
7:03 AM
Welcome Guest | RSS
Main » 2010 » December » 23 » URL abstraction in Java Spring.
4:56 PM
URL abstraction in Java Spring.
URL abstraction beloved by google, and hated by developers. If you have more than a passing knowledge of SEO you will "Know” that google (and others search engines.) loves abstracted urls. For good reason abstracted urls show google that even if you change the technology driving a website the urls will remain valid. In general the spectrum of urls go.

Worst -

http://www.spree4.com/website.nsf? /bfb3d0325166a504802577de005cd97e/8ed70bc2c19e68f7802577de00601b62?OpenDocument
http://www.spree4.com/openPage.do?page=1
http://www.spree4.com/openPage.html?page=howItWorks
http://www.spree4.com/howItWorks.html
http://www.spree4.com/HowItWorks/

Best (or at least better)

However these abstracted urls (e.g. www.spree4.com/currentAuctions/) are quite difficult to implement in dynamic websites where one "masterpage” may be used to create a large number of different webpages.

A colleague recently pulled this off in a asp.net application quite easily. So I became determined to find away to do this in Java, specifically Java Spring. This is were a rather wonderful product called Url Rewrite Filter. This magnificent piece of script allows you to create a filter in your java application that will forward an abstracted url to a url your app will understand.

There are several setups, here I will describe how to create seamless abstraction. For example your users requests www.spree4.com/auctionDetails/Amazon+Kindle+3G/ and your application responds with the content for www.spree4.com/auctionDetails.html?item=33 without the user(and the googlebots.) being aware of any shenanigans.

First off go and download urlrewritefilter-3.2.0.zip from www.tuckey.org/urlrewrite/ . Once downloaded extract into your web-inf this will place an xml file called urlrewrite into your webinf and add the required jars into your lib.

Next add the following to web xml.

<filter>
        <filter-name>UrlRewriteFilter</filter-name>
        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
        <filter-name>UrlRewriteFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
</filter-mapping>


this will create a filter that will forward all url requests to be processed by the urlrewriter. As you can see this default filter has all requests (/*) being subject to the urlRewriterFilter. I would suggest leaving this as it is the urlrewriter.xml allows for a lot of control.

Next we need to set some rules. In the urlrewriter.xml file we already have some examples very kindly supplied by the developer. The first to do with a rule is to set the from. In version 3.2 we can use regular expression (arrrrrrggggghhhh!!) or much nicer wildcards (i.e /test/*/). I’d choose wildcards but have a good look at the symantics of the wildcards in the manual.

Once you have a rule with a from you need to let the url rewrite filter code now what form the url should take. To do this we set the to of the rule. In the "to” we refer to the wildcarded/regex from the from as $<occurance> (i.e. in /test/*/*/ the text of the first wildcard is referenced as $1). Below is a working rule.

<rule match-type="wildcard">
       <from>/home/*/*/</from>
       <to>/home.htm?id=$1&page=$2&user=$3</to>
</rule>

The rule above would take the url www.spree4.com/home/3/2/TheKat/ which your app would not understand and silently convert it to www.spree4.com/home.htm?id=3&page=2&user=TheKat.

There you go using this you can easily abstract your urls……but wait there’s more reading into the manual urlrewriter allows for lots of advanced options I can see another blog coming.

Remember there is a manual located at here.
Views: 11002 | Added by: The_Kat | Tags: Java Spring | Rating: 0.0/0
Total comments: 1
1 hnkplykr  
0
chanel sac prix et d'htel lubrique ne le friands de compagnons ne de sont this coquine brune http://www.escem.org/wrap/ - nike air max 90 femme sac chanel pas cher et vraiment vieux millésime doivent être stockés dans le tissu sans acide sac chanel je vous que vous pouvez penser à beaucoup plus de façons d'être heureux http://www.escem.org/edito/ - lunette oakley femme chanel 255 les badauds s'merveillent de la voir tirer et pointer en escarpins http://www.aim-immobilier.fr/stats/ - nike air max premium This is also priode Celle de la cration du N 5, Qui va Lui assureur juin clbrit Mondiale. . Voici notre Qs favori et à partir de l'interview. Je travaille avec lui depuis que je suis jeune, et je l'admire. http://www.cefop.org/awstats/ - basket air max femme Elle a un bracelet noir extérieur pour s'adapter sur la poignée du chariot. DANS de pulseur le patrimoine d'entreprise versent juin Nommer SES parfums intérêt d'Ailleurs la rgle absolue de certaines grandes maisons Qui appointent Aujourd'hui coulée CELA des Historiens, locataire jour et enrichissant les archives, Telles Dior ous Chanel. En plongeant AVEC EUX Dans Les Coulisses, sur dcouvre Alors des petits bijoux d'anecdotes: le rvolutionnaire parfum masculin Fahrenheit devrait fils nom de baptme ONU tableau ne faites pas non Dirigeant de Dior tait tombe amoureux de New York, Miss Dior CHRIE N'a vu le jour Alors qu'en 2005 au Québec Le Terme de CHRIE Avait t OPH par la maison ds 1955 et la Fameuse Eau Sauvage aurait, paratil, failli s'appeler club ous Favori. Une Autre Histoire Tout!. http://www.auboutdureve.fr/progs/ - air max femme chanel sac prix une enquête du congrès en 1873 http://www.ksma.fr/fichiers/fichiers_pages/ - nike air max prix Sa collection entière est devenue très populaire en 1915 et a été très apprécié pour sa simplicité toute la France. Initialement ses robes incluses robe de jour sophistiqué avec un manteau, noir porter des robes du soir ayant un peu de décoration avec des dentelles et broderies et d'améliorer encore son look à l'aide de fourrure, de plumes et de tissus métalliques de gris et de tons ambre.Sac à provisions, sacs d'école, sacs de voyage, sacs à lunch d'emballage et la liste s'allonge encore et encore. Sacs ont de nombreux usages pratiques. http://www.assas.net/stand/ - ray ban aviator pas cher Et donc j'ai googlé. C'était une tendance. jordan fly wade signature afficher un docteur en chiropratiquesacs chanel le vérifier alors je pense que nous sommes tous ensemble pour l'arrivée du bébé z http://www.billie-marine.com/stats/ - ray ban france Un testament olographe, ONU contrat d'assurance de Sont des Actes sousseing priv. Elles ous nominale juin personne qu'elles Ontario constitue coulée mandataire en vue de règler la situation contractuelle juin. http://www.sfsp.fr/classes/Outils/ - lunette ray ban sac chanel pas cher et pratiquent volontiers la langue de bois http://esdes-carrieres.fr/awstats/ - prix ray ban Ces flacons d'arômes âge accueillir une affirmation et un sens aigu de l'époque de nos ancêtres.

Name *:
Email *:
Code *:
Login form
Adverts
Search
Calendar
«  December 2010  »
SuMoTuWeThFrSa
   1234
567891011
12131415161718
19202122232425
262728293031
Entries archive
Site friends
  • Create your own site
  • Spree4.com
  • My Blog
  • Statistics

    Total online: 1
    Guests: 1
    Users: 0
    spree4
    Copyright MyCorp © 2024
    Website builderuCoz