[Yanel-dev] Patch for Redirect Resource

Michael Wechner michael.wechner at wyona.com
Sun Sep 19 23:56:44 CEST 2010


Balz Schreier wrote:
> Hi Michael,
>
> the enhanced version is stored in our project's SVN, you should have 
> access:
>
> /zwischengas/src/java/com/zwischengas/resource/redirect/LoginRedirect.java
>
> What the extension does is:
> - if a config property is retrieved, the extension verifies whether 
> the key matches the "href" parameter, now available 
> as RedirectResource.RESOURCE_CONFIG_PARAM_HREF
> - if this parameter is retrieved, the extension returns the value 
> retrieved from the request's parameter instead of the configured value 
> from the resource config.

what I mean re an example how does the URL look like? Does it look like 
something

http://127.0.0.1:8080/yanel/MY_REALM/en/login?href=/en/hello-world.html

?

Thanks

Michael
>
> he code is very simple but does its job for me.
>
> Cheers
> Balz
>
> On Sat, Sep 18, 2010 at 10:26 PM, Michael Wechner 
> <michael.wechner at wyona.com <mailto:michael.wechner at wyona.com>> wrote:
>
>     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
>
>
>     -- 
>     Yanel-development mailing list Yanel-development at wyona.com
>     <mailto:Yanel-development at wyona.com>
>     http://lists.wyona.org/cgi-bin/mailman/listinfo/yanel-development
>
>



More information about the Yanel-development mailing list