You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Jose L Martinez-Avial (JIRA)" <ji...@apache.org> on 2012/07/10 17:39:34 UTC

[jira] [Created] (WW-3849) Hability PrefixBasedActionMapper to exclude the prefix when retrieveing the ActionMapper

Jose L Martinez-Avial created WW-3849:
-----------------------------------------

             Summary: Hability PrefixBasedActionMapper to exclude the prefix when retrieveing the ActionMapper
                 Key: WW-3849
                 URL: https://issues.apache.org/jira/browse/WW-3849
             Project: Struts 2
          Issue Type: Improvement
          Components: Dispatch Filter
    Affects Versions: 2.2.3
            Reporter: Jose L Martinez-Avial


The PrefixBasedActionMapper is able to map different actions to different mappers using prefixes. So you can have something like this:

/preffix1:mapper1,/preffix2:mapper2,:defaultMapper
/mynamespace1/myaction1,
/preffix1/mynamespace1/myaction1
/preffix2/mynamespace1/myaction1

So you can have three different ActionMappers, one per prefix. The problem with this is that you can not reuse the same actions for different prefixes, since the ActionMapper will try to match the full URI, without taking out the prefix. I suggest to parametrize the PrefixBasedActionMapper to remove the preffix from the URI when calling the ActionMapper, so the same mapper can be used more than once.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (WW-3849) Hability PrefixBasedActionMapper to exclude the prefix when retrieveing the ActionMapper

Posted by "Jose L Martinez-Avial (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3849?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13412559#comment-13412559 ] 

Jose L Martinez-Avial commented on WW-3849:
-------------------------------------------

I would like to reuse the actions, excluding the prefix from the URI before calling the mapper. So the uris /mypackage/myaction, /en/mypackage/myaction and /pt/mypackage/myaction would be processed by the same action mapping.

The idea would be to provide a list of prefixes that need to be removed from the URI when looking for the corresponding ActionMapping. Initially I thought that the best option was using PrefixBaseActionMapper, but since it does not remove the prefix, I can not use it.

After some thinking, I ended extending the methods parseNameAndNamespace and getUriFromActionMapping from DefaultActionMapper. The method parseNameAndNamespace  checks the uri agains the prefixes, and removes the prefix if there is a match, and then calls the parent's method. Then the prefix is saved in the request context:

	private String prefixes[] = new String[] { "/en", "/pt", "/es" };

	public static final String PREFFIX_ATTRIBUTE_NAME = "PREFFIX_ATTRIBUTE_NAME";
	protected void parseNameAndNamespace(String uri, ActionMapping mapping, ConfigurationManager configManager) {
		String actionPrefix = null;

		for (String prefix1 : prefixes) {
			if (uri.startsWith(prefix1)) {
				actionPrefix = prefix1;
				//LOG.debug("Removing preffix " + prefix1);
				uri = uri.substring(prefix1.length());
				//LOG.debug("New URI " + uri);
				break;
			}
		}
		super.parseNameAndNamespace(uri,mapping,configManager);
		if (actionPrefix != null) {
			HttpServletRequest request = ServletActionContext.getRequest();
			request.setAttribute(PREFFIX_ATTRIBUTE_NAME, actionPrefix);
		}

	}

On the method getUriFromActionMapping I retrieve the prefix from the request:

	public String getUriFromActionMapping(ActionMapping mapping) {
		String actionPrefix = "";
		HttpServletRequest request = ServletActionContext.getRequest();

		if (request.getAttribute(PREFFIX_ATTRIBUTE_NAME) != null)
			actionPrefix = (String) request.getAttribute(PREFFIX_ATTRIBUTE_NAME);

		StringBuilder uri = new StringBuilder(actionPrefix);
[...]

It works fine, but it seems a bit of a hack, so maybe there is a better way to do this.

                
> Hability PrefixBasedActionMapper to exclude the prefix when retrieveing the ActionMapper
> ----------------------------------------------------------------------------------------
>
>                 Key: WW-3849
>                 URL: https://issues.apache.org/jira/browse/WW-3849
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Dispatch Filter
>    Affects Versions: 2.2.3
>            Reporter: Jose L Martinez-Avial
>             Fix For: 2.3.x
>
>
> The PrefixBasedActionMapper is able to map different actions to different mappers using prefixes. So you can have something like this:
> /preffix1:mapper1,/preffix2:mapper2,:defaultMapper
> And the following URIs would be processed by different mappers
> /preffix1/mynamespace1/myaction1 (by mapper1)
> /preffix2/mynamespace1/myaction1 (by mapper2)
> /mynamespace1/myaction1  (by defaultMapper)
> So you can have three different ActionMappers, one per prefix. The problem with this is that you can not reuse the same actions for different prefixes(ie, reuse an ActionMapper), since the ActionMapper will try to match the full URI, without taking out the prefix. I suggest to parametrize the PrefixBasedActionMapper to remove the preffix from the URI when calling the ActionMapper, so the same mapper can be used more than once.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (WW-3849) Hability PrefixBasedActionMapper to exclude the prefix when retrieveing the ActionMapper

Posted by "Lukasz Lenart (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3849?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13412853#comment-13412853 ] 

Lukasz Lenart commented on WW-3849:
-----------------------------------

I think that's ok, you should adjust framework to your specific needs and you did that. I don't think that we should change the PrefixBasedActionMapper - it has other job to do.
                
> Hability PrefixBasedActionMapper to exclude the prefix when retrieveing the ActionMapper
> ----------------------------------------------------------------------------------------
>
>                 Key: WW-3849
>                 URL: https://issues.apache.org/jira/browse/WW-3849
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Dispatch Filter
>    Affects Versions: 2.2.3
>            Reporter: Jose L Martinez-Avial
>             Fix For: 2.3.x
>
>
> The PrefixBasedActionMapper is able to map different actions to different mappers using prefixes. So you can have something like this:
> /preffix1:mapper1,/preffix2:mapper2,:defaultMapper
> And the following URIs would be processed by different mappers
> /preffix1/mynamespace1/myaction1 (by mapper1)
> /preffix2/mynamespace1/myaction1 (by mapper2)
> /mynamespace1/myaction1  (by defaultMapper)
> So you can have three different ActionMappers, one per prefix. The problem with this is that you can not reuse the same actions for different prefixes(ie, reuse an ActionMapper), since the ActionMapper will try to match the full URI, without taking out the prefix. I suggest to parametrize the PrefixBasedActionMapper to remove the preffix from the URI when calling the ActionMapper, so the same mapper can be used more than once.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (WW-3849) Hability PrefixBasedActionMapper to exclude the prefix when retrieveing the ActionMapper

Posted by "Lukasz Lenart (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3849?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13411290#comment-13411290 ] 

Lukasz Lenart commented on WW-3849:
-----------------------------------

I'm not sure, do you want to reuse actions or ActionMappers ?
                
> Hability PrefixBasedActionMapper to exclude the prefix when retrieveing the ActionMapper
> ----------------------------------------------------------------------------------------
>
>                 Key: WW-3849
>                 URL: https://issues.apache.org/jira/browse/WW-3849
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Dispatch Filter
>    Affects Versions: 2.2.3
>            Reporter: Jose L Martinez-Avial
>
> The PrefixBasedActionMapper is able to map different actions to different mappers using prefixes. So you can have something like this:
> /preffix1:mapper1,/preffix2:mapper2,:defaultMapper
> And the following URIs would be processed by different mappers
> /preffix1/mynamespace1/myaction1 (by mapper1)
> /preffix2/mynamespace1/myaction1 (by mapper2)
> /mynamespace1/myaction1  (by defaultMapper)
> So you can have three different ActionMappers, one per prefix. The problem with this is that you can not reuse the same actions for different prefixes(ie, reuse an ActionMapper), since the ActionMapper will try to match the full URI, without taking out the prefix. I suggest to parametrize the PrefixBasedActionMapper to remove the preffix from the URI when calling the ActionMapper, so the same mapper can be used more than once.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (WW-3849) Hability PrefixBasedActionMapper to exclude the prefix when retrieveing the ActionMapper

Posted by "Jose L Martinez-Avial (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WW-3849?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jose L Martinez-Avial updated WW-3849:
--------------------------------------

    Description: 
The PrefixBasedActionMapper is able to map different actions to different mappers using prefixes. So you can have something like this:

/preffix1:mapper1,/preffix2:mapper2,:defaultMapper

And the following URIs would be processed by different mappers

/preffix1/mynamespace1/myaction1 (by mapper1)
/preffix2/mynamespace1/myaction1 (by mapper2)
/mynamespace1/myaction1  (by defaultMapper)

So you can have three different ActionMappers, one per prefix. The problem with this is that you can not reuse the same actions for different prefixes(ie, reuse an ActionMapper), since the ActionMapper will try to match the full URI, without taking out the prefix. I suggest to parametrize the PrefixBasedActionMapper to remove the preffix from the URI when calling the ActionMapper, so the same mapper can be used more than once.

  was:
The PrefixBasedActionMapper is able to map different actions to different mappers using prefixes. So you can have something like this:

/preffix1:mapper1,/preffix2:mapper2,:defaultMapper
/mynamespace1/myaction1,
/preffix1/mynamespace1/myaction1
/preffix2/mynamespace1/myaction1

So you can have three different ActionMappers, one per prefix. The problem with this is that you can not reuse the same actions for different prefixes, since the ActionMapper will try to match the full URI, without taking out the prefix. I suggest to parametrize the PrefixBasedActionMapper to remove the preffix from the URI when calling the ActionMapper, so the same mapper can be used more than once.

    
> Hability PrefixBasedActionMapper to exclude the prefix when retrieveing the ActionMapper
> ----------------------------------------------------------------------------------------
>
>                 Key: WW-3849
>                 URL: https://issues.apache.org/jira/browse/WW-3849
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Dispatch Filter
>    Affects Versions: 2.2.3
>            Reporter: Jose L Martinez-Avial
>
> The PrefixBasedActionMapper is able to map different actions to different mappers using prefixes. So you can have something like this:
> /preffix1:mapper1,/preffix2:mapper2,:defaultMapper
> And the following URIs would be processed by different mappers
> /preffix1/mynamespace1/myaction1 (by mapper1)
> /preffix2/mynamespace1/myaction1 (by mapper2)
> /mynamespace1/myaction1  (by defaultMapper)
> So you can have three different ActionMappers, one per prefix. The problem with this is that you can not reuse the same actions for different prefixes(ie, reuse an ActionMapper), since the ActionMapper will try to match the full URI, without taking out the prefix. I suggest to parametrize the PrefixBasedActionMapper to remove the preffix from the URI when calling the ActionMapper, so the same mapper can be used more than once.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (WW-3849) Hability PrefixBasedActionMapper to exclude the prefix when retrieveing the ActionMapper

Posted by "Lukasz Lenart (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3849?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13411291#comment-13411291 ] 

Lukasz Lenart commented on WW-3849:
-----------------------------------

Or could you prepare an example application ?
                
> Hability PrefixBasedActionMapper to exclude the prefix when retrieveing the ActionMapper
> ----------------------------------------------------------------------------------------
>
>                 Key: WW-3849
>                 URL: https://issues.apache.org/jira/browse/WW-3849
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Dispatch Filter
>    Affects Versions: 2.2.3
>            Reporter: Jose L Martinez-Avial
>             Fix For: 2.3.x
>
>
> The PrefixBasedActionMapper is able to map different actions to different mappers using prefixes. So you can have something like this:
> /preffix1:mapper1,/preffix2:mapper2,:defaultMapper
> And the following URIs would be processed by different mappers
> /preffix1/mynamespace1/myaction1 (by mapper1)
> /preffix2/mynamespace1/myaction1 (by mapper2)
> /mynamespace1/myaction1  (by defaultMapper)
> So you can have three different ActionMappers, one per prefix. The problem with this is that you can not reuse the same actions for different prefixes(ie, reuse an ActionMapper), since the ActionMapper will try to match the full URI, without taking out the prefix. I suggest to parametrize the PrefixBasedActionMapper to remove the preffix from the URI when calling the ActionMapper, so the same mapper can be used more than once.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (WW-3849) Hability PrefixBasedActionMapper to exclude the prefix when retrieveing the ActionMapper

Posted by "Lukasz Lenart (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WW-3849?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lukasz Lenart updated WW-3849:
------------------------------

    Fix Version/s: 2.3.x
    
> Hability PrefixBasedActionMapper to exclude the prefix when retrieveing the ActionMapper
> ----------------------------------------------------------------------------------------
>
>                 Key: WW-3849
>                 URL: https://issues.apache.org/jira/browse/WW-3849
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Dispatch Filter
>    Affects Versions: 2.2.3
>            Reporter: Jose L Martinez-Avial
>             Fix For: 2.3.x
>
>
> The PrefixBasedActionMapper is able to map different actions to different mappers using prefixes. So you can have something like this:
> /preffix1:mapper1,/preffix2:mapper2,:defaultMapper
> And the following URIs would be processed by different mappers
> /preffix1/mynamespace1/myaction1 (by mapper1)
> /preffix2/mynamespace1/myaction1 (by mapper2)
> /mynamespace1/myaction1  (by defaultMapper)
> So you can have three different ActionMappers, one per prefix. The problem with this is that you can not reuse the same actions for different prefixes(ie, reuse an ActionMapper), since the ActionMapper will try to match the full URI, without taking out the prefix. I suggest to parametrize the PrefixBasedActionMapper to remove the preffix from the URI when calling the ActionMapper, so the same mapper can be used more than once.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira