[Yanel-dev] Patch for Redirect Resource

Michael Wechner michael.wechner at wyona.com
Sat Sep 18 22:26:52 CEST 2010


Balz Schreier wrote:
> Hi Michael,
>
> I would like to reuse 98% of the redirect resource.
> My local redirect resource which extends the yanel redirect resource 
> is not expecting a URL from the resource config (where to redirect) 
> but rather from the URL.
> To do so, I would like to extend it, so that the resource does not 
> expect a hardcoded redirect URL anymore.
>
> For that, I would like to overwrite 
> Resource.getResourceConfigProperty():
> if the passed key is "href", then I will return my own value instead 
> of the resource config property.
>
> As the parameter name "href" is hardcoded in the RedirectResource, I 
> introduced a public constant, so that I can reuse that key in my 
> extended class.

Can you send me a "configuration/URL" example how you are using this 
enhanced version?
I am asking because I would like to write a test for it ;-)

Thanks

Michael
>
> The patch for the RedirectResource is here:
>
> Index: 
> src/contributions/resources/redirect/src/java/org/wyona/yanel/impl/resources/redirect/RedirectResource.java
> ===================================================================
> --- 
> src/contributions/resources/redirect/src/java/org/wyona/yanel/impl/resources/redirect/RedirectResource.java 
> (revision 53304)
> +++ 
> src/contributions/resources/redirect/src/java/org/wyona/yanel/impl/resources/redirect/RedirectResource.java 
> (working copy)
> @@ -41,6 +41,7 @@
>      private static Category log = 
> Category.getInstance(RedirectResource.class);
>      
>      public static String IDENTITY_MAP_KEY = "identity-map";
> +    public static final String RESOURCE_CONFIG_PARAM_HREF = "href";
>  
>      // Only a temporary variable needed during creation (roundtrip)
>      private String defaultHrefSetByCreator;
> @@ -72,7 +73,7 @@
>  
>          HttpServletResponse response = getResponse();
>  
> -        String defaultHref = getResourceConfigProperty("href");
> +        String defaultHref = 
> getResourceConfigProperty(RESOURCE_CONFIG_PARAM_HREF);
>  
>          if (defaultHref == null) throw new Exception("No default 
> redirect has been set!");
>  
> @@ -96,7 +97,7 @@
>                  try {
>                      if 
> (languageRedirectConfigs[i].getAttribute("code").equals(localizationLanguage)) 
> {
>                          response.setStatus(307);
> -                        response.setHeader("Location", 
> languageRedirectConfigs[i].getAttribute("href"));
> +                        response.setHeader("Location", 
> languageRedirectConfigs[i].getAttribute(RESOURCE_CONFIG_PARAM_HREF));
>                      }
>                  } catch (Exception e) {
>                      log.error(e.getMessage(), e);
> @@ -117,7 +118,7 @@
>                      try {
>                          if 
> (userRedirectConfigs[i].getAttribute("name") == currentUser || 
> (currentUser).equals(userRedirectConfigs[i].getAttribute("name"))) {
>                              response.setStatus(307);
> -                            response.setHeader("Location", 
> userRedirectConfigs[i].getAttribute("href"));
> +                            response.setHeader("Location", 
> userRedirectConfigs[i].getAttribute(RESOURCE_CONFIG_PARAM_HREF));
>                          }
>                      } catch (Exception e) {
>                          log.error(e.getMessage(), e);
> @@ -188,7 +189,7 @@
>       */
>      public HashMap createRTIProperties(HttpServletRequest request) {
>          HashMap map = new HashMap();
> -        map.put("href", request.getParameter("rp." + REDIRECT_URL));
> +        map.put(RESOURCE_CONFIG_PARAM_HREF, 
> request.getParameter("rp." + REDIRECT_URL));
>          return map;
>      }
>  
>
>
> Cheers
> Balz



More information about the Yanel-development mailing list