[Yanel-dev] Patch for Redirect Resource

Balz Schreier balz.schreier at gmail.com
Sun Sep 19 12:46:31 CEST 2010


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.

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
> 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 rat=
her
>> 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/resou=
rces/redirect/RedirectResource.java
>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>> ---
>> src/contributions/resources/redirect/src/java/org/wyona/yanel/impl/resou=
rces/redirect/RedirectResource.java
>> (revision 53304)
>> +++
>> src/contributions/resources/redirect/src/java/org/wyona/yanel/impl/resou=
rces/redirect/RedirectResource.java
>> (working copy)
>> @@ -41,6 +41,7 @@
>>     private static Category log =3D
>> Category.getInstance(RedirectResource.class);
>>          public static String IDENTITY_MAP_KEY =3D "identity-map";
>> +    public static final String RESOURCE_CONFIG_PARAM_HREF =3D "href";
>>      // Only a temporary variable needed during creation (roundtrip)
>>     private String defaultHrefSetByCreator;
>> @@ -72,7 +73,7 @@
>>          HttpServletResponse response =3D getResponse();
>>  -        String defaultHref =3D getResourceConfigProperty("href");
>> +        String defaultHref =3D
>> getResourceConfigProperty(RESOURCE_CONFIG_PARAM_HREF);
>>          if (defaultHref =3D=3D null) throw new Exception("No default re=
direct
>> has been set!");
>>  @@ -96,7 +97,7 @@
>>                 try {
>>                     if
>> (languageRedirectConfigs[i].getAttribute("code").equals(localizationLang=
uage))
>> {
>>                         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") =
=3D=3D
>> 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 =3D 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
> http://lists.wyona.org/cgi-bin/mailman/listinfo/yanel-development
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wyona.org/pipermail/yanel-development/attachments/2010091=
9/ad772ed0/attachment.htm


More information about the Yanel-development mailing list