CQ5 response.sendRedirect with dispatcher - aem

I would like to redirect a request to an other page by some condition. In cq5 I can check whether the page I want to redirect the request exists or not. But dispatcher handles only static HTML, so how I can handle redirects to be compatible with dispatcher?
So how can I use response.sendRedirect() with dispatcher?

If I understand correctly, you have a page that sometimes redirects to somewhere else and sometimes simply displays a content. If the page decides to redirect, dispatcher won't cache it. However, if the page displays a content (even once), it will be cached and from this moment all users will get the cached resource.
You can do 2 things:
move the redirection logic to Javascript, so it'll executed even if the page is cached,
add a cache rule to dispatcher configuration preventing this concrete path from being cached.

Related

In JMeter why is a redirected sample disabled?

I've made a recording of actions on various web pages.
Submitting a large form causes a redirect to be recorded in JMeter under the Recording Controller.
Detected a redirect from the previous sample
In the image below, the client/create page POSTs the form data and receives a 302 redirect from the server to the create/confirm page.
JMeter is automatically disabling this GET redirect page (in grey below) as (presumably) it's something that is sent automatically and not required to be sent by the recording
When I replay this (using the validate option), the redirected page doesn't appear. Screen shot from View Results Tree:
This is a particular issue as the page contains a value that I need to extract for subsequent requests (accountselection being one).
Simply re-enabling the disabled redirect page doesn't work. Nor does blindly putting a regular expression extractor on it (as the page is disabled).
As it doesn't appear in the 'View Results Tree' I can't see the contents of the response either .
How do I get at the value in the body of the redirected page?
When recording JMeter intentionally disables Http Request that are the result of a redirect.
Now you problem is that you most probably didn't variabilize some id used for the success of the initial request leading to redirect.
Check all parameters and headers sent in this first request and make them variable when needed:
Use a post processor on the previous(can be any preceding request) request to extract the value in varName (example)
Use ${varName} to inject it
This concept is called correlation.
Click on the particular request from which redirect occurs.
Find the option "Follow Redirects" under Path.
Check it if not checked. Now rerun the script.

Is it possible to add adverts to a custom Facebook Page Tab app?

I need to create a custom Facebook Page Tab app which will show an external site in an iframe. This need to have adverts on it but I'm not sure if this is possible as the site is hosted externally.
I'm not sure if I need to sign up to the Facebook Audience Network to get approved etc. either?
Any help or advice would be great.
Many browsers have this limitation of not allowing external sites to be shown in an iframe. Imagine the case when you are working hard to create a site and others show all your content in iframes. That is, naturally frustrating.
However, there is a candidate-solution: Let's suppose you create a page which sends a request to the other site and appends all the content into the body and head of your page. This is very much possible, so the solution is to:
Create a page in your site, let's call it outsider
In the server-side code of your outsider page send a request to the desired page to be shown
You will get the html of the page. Process it and include its content into the head and body of outsider. This includes:
3.1. Checking all the CSS to be reached, as the target page might refer to local CSS, which is unreachable locally at your end. Process the URLs of CSS files
3.2. Checking all the Javascript to be reached, as the target page might refer to local JS, which is unreachable locally at your end. Process the URLs of JS files
3.3. Apply the idea described in 3.1. and 3.2. for other resources, like images, until you are satisfied with the content of outsider
Create an iframe, having the source to point to outsider. outsider is inside your scope, so it should be shown
NOTE: If the site owning the target page does not like the possibility of you showing their content inside iframes, they might protect it by, let's say, having Javascript in their code, which checks whether the page is inside an iframe. Remove that code while processing the response to your request. If nothing else prevents you from showing the page in an iframe, then you should achieve success.

Why do webpages need to do a 303 redirect?

Is it common that when you need to POST data to your database, that you need to perform a redirect to another location in order to give a response?
I believe some joomla components perform a redirect, and was wondering if this is the norm?
Scenario: I want to POST data from this page to my database
When: I click submit
Then: I should be taken to the success page
When would it be necessary to perform a redirect to the success page instead of loading it initially? I've read on w3.org that a 303 redirect means that the response is contained in another URI, but what would justify redirecting somewhere else in order to get the success page response?
(lol # trying some behat logic :P)
Tagged Joomla as I'm working with it
Yes, it is common, or at least should be. The reason for redirecting after a POST request is to prevent the POST request from being re-sent on a page refresh.

facebook iframe app - how to organize and write code for faster page loading - PHP SDK

I am writing an app within a facebook iframe and am unsure how best to write this. I originally wrote all the code within the main canvas.php file but found everything was running too slow before results were being loaded into the iframe.
I then tried using the php header location method so to try and load different pages into the iframe, thus reducing page load time. However, the header location is ignored.
I have also tried using javascript to get the page to load within the iframe instead, this does load in the new page but the page experiences lots of problems. It wil not pass parrameteres to itself using $_GET.
Basically, I need to perform some checks when the canvas page is first loaded in the iframe and then re-direct to another file to avoid the checks being perfomed on every page load as this seriously shows everything down. I then need to have page reloads with different parrameteres in the URL to populate the iframe with different results, again this is very slow as it has to perfomr all the checks again.
Therefore, how can I achieve a smooth workflow as a normal site within a facebook iframe?
[EDIT] Just thought is Ajax a valid option?
Many thanks in advance.
Most people experience slow response times due to not having a channelURL specified. See http://developers.facebook.com/docs/reference/javascript/
Channel File
The channel file addresses some issues with cross domain communication
in certain browsers. The contents of the channel.html file can be just
a single line:
It is important for the channel file to be cached for as long as
possible. When serving this file, you must send valid Expires headers
with a long expiration period. This will ensure the channel file is
cached by the browser which is important for a smooth user experience.
Without proper caching, cross domain communication will become very
slow and users will suffer a severely degraded experience. A simple
way to do this in PHP is:
The channelUrl parameter is optional, but recommended. Providing a
channel file can help address three specific known issues. First,
pages that include code to communicate across frames may cause Social
Plugins to show up as blank without a channelUrl. Second, if no
channelUrl is provided and a page includes auto-playing audio or
video, the user may hear two streams of audio because the page has
been loaded a second time in the background for cross domain
communication. Third, a channel file will prevent inclusion of extra
hits in your server-side logs. If you do not specify a channelUrl, you
can remove page views containing fb_xd_bust or fb_xd_fragment
parameters from your logs to ensure proper counts.
The channelUrl must be a fully qualified URL matching the page on
which you include the SDK. In other words, the channel file domain
must include www if your site is served using www, and if you modify
document.domain on your page you must make the same document.domain
change in the channel.html file as well. The protocols must also
match. If your page is served over https, your channelUrl must also be
https. Remember to use the matching protocol for the script src as
well. The sample code above uses protocol-relative URLs which should
handle most https cases properly.

webkit .appcache file caches dynamic page

The main page of my mobile web app is a .jsp page. My app requires login (Google App Engine), so there is a Log In button when the user is not logged in and a Log Out button when the user is logged in, all handled by code on the .jsp page.
I load a lot of JS code on the page, so I used a .appcache file to cache that. Unfortunatelly, even though I added my .jsp page to the Network area, the page is being cached in a funny way, ignoring the content server from the server. That means that my Log Out button shows when users are Logged Out and vice-versa.
I tried to add no-cache directives as meta tags, but they are all being ignored.
Ideas?
According to dive into HTML5, the page that references the manifest is automatically included in the manifest.
http://diveintohtml5.ep.io/offline.html
Q: Do I need to list my HTML pages in my cache manifest?
A: Yes and no. If your entire web application is contained in a single page, just make sure that page points to the cache manifest using the manifest attribute. When you navigate to an HTML page with a manifest attribute, the page itself is assumed to be part of the web application, so you don’t need to list it in the manifest file itself. However, if your web application spans multiple pages, you should list all of the HTML pages in the manifest file, otherwise the browser would not know that there are other HTML pages that need to be downloaded and cached.
I have a similar issue, and I think I will end up loading the contents of the page via AJAX.
Caching in appCache is a two stage process: first the cache manifest is checked (in this case, as the page is loading), then if the content of it has changed, that content is reloaded. However, in your case, by that time, the stale page is already loaded and displayed.
The easiest fix would be to specifically exclude the page (but not the .js) from the appCache, so that only the js is cached, and not the page. I sounds like you might have figured that out, as you are trying to do it by putting the page in the network area. Check that that exclusion is correct, as that sounds like the problem, and that html cache attributes are being set correctly on that page.