How to automatically add a parameter for each HTTP request?

For some specific reasons, I will need to automatically add or add a parameter to the URL for each request, if and only if this parameter already exists in the URL from the first request. In other words, if I have a URL /share/page/site/sample/documentlibrary?embedded , each request /share/page/site/sample/[whatever] should contain an inline parameter plus other parameters that could be added by the original request.

I work with Alfresco Share (v4.2.b), which means that the web application already exists, and although I can configure it, I have limitations because I cannot completely control it. If it was my web application built from scratch, that would not be a problem. According to the limitations that I have, the solution should ideally be as less intrusive as possible. At the same time, if this is a JavaScript-based solution, using YUI rather than another library is a plus, but not required.

I was looking for an approach, and after that I mean the following possible solutions:

  • Use JavaScript by adding a parameter to the URL before uploading each page. Sort of:

      window.onbeforeunload = function(e) { // Add parameter to target URL }; 

    But I believe that this does not work, as I read and according to some tests that I did. There seems to be some kind of security constraint (which, by the way, makes sense).

  • Updating the href attribute for each link ( <a/> ) using JavaScript after the page has finished loading. For example, /share/page/site/sample/document-details?nodeRef=workspace://SpacesStore/089acea3-3b37-403d-9a8d-ae484ddd2ccb can be converted to /share/page/site/sample/document-details?nodeRef=workspace://SpacesStore/089acea3-3b37-403d-9a8d-ae484ddd2ccb&embedded . The problem with this solution is that both the GET or POST and href forms launched using JavaScript will not be available ...

  • Using any technology for rewriting a URL or library, for example UrlRewriteFilter (I have not had time to test it yet, sorry).

  • Create an Alfresco Share extension module that modifies or updates each request, perhaps with a module or subcomponent evaluator. I don’t know if this is compatible with extension modules, but I believe that I read somewhere that you can make changes to queries.

I need to add (for those who have knowledge of Alfresco Share) that options 1, 2 and 4 will be implemented as an extension module.

Well, I hope I explained my question well enough. I would really appreciate some advice or possible approaches. I will work on it anyway, and I will come up with any update.

+4
source share
3 answers
  • If this is for each request, a filter is better. Share already uses urlrewrite, as you stated, so change the default value and add your parameter to it.

  • If you have knowledge about the stock, redefining the included template will be nice: override alfresco-template.ftl , which is located in the / org / alfresco / include templates. This template is always loaded when creating the page. It also has the portletMode parameter defined for the Liferay portlet.

  • What we did to implement the document library is to define our own to share the user page, so I don’t need the “always” real arg any anymore.

+2
source

How about proxying connections through Apache HTTPd using mod_proxy and then using mod_rewrite to redirect user requests if they do not already contain a required parameter? Using the RewriteRule directive, you can specify fairly rich expressions that would add a parameter if it does not already exist ( docs )

+1
source

They did not use Alfresco, but another option is to have a custom JSP tag.

Lets call it customlink, and then when you display the link on the page, use this custom jsp tag instead of the <a> tag.

For instance,

 <mynamespace:customlink href="/somelink">My Content</mynamespace:customlink> 

A custom JSP tag may be responsible for checking the query string parameter in the query, and if it exists, add it to the URL and print the tag using the query string.

This can be beneficial not dependent on JS or disclosing any of them on the client side. It also allows further expansion in the future.

0
source

All Articles