My GWT app URL when a page is access looks like this:
http://127.0.0.1:8888/index.html?gwt.codesvr=127.0.0.1:9997#ViewPage;hash=6a
or
http://127.0.0.1:8888/index.html#ViewPage;hash=6a
However, this does not look good, is there a way for the GWT client side code to make it look like this, to "mask" it somehow to:
http://127.0.0.1:8888/6a
Where I have a servlet configured to forward this "shortened" URL to the long URL above so its very safe to make the URL "masked"? Without losing state and history.
The shortest possibility I know would be an URL like:
http://127.0.0.1:8888/#6a
Therefore you must configure index.html as default page. (It must be configured as default response).
You also have to rewrite the history-management. You have to remove the Place-Token from the URL.
I don't see any way to do this directly with GWT, since GWT needs access to the code fragment in the URL to manage browsing history and state.
One indirect way to do it would be to embed your GWT module inside an iframe that occupies the whole page area. The drawback is that the user would loose the ability to bookmark pages inside the GWT application.
By the way, I don't share your view that it "does not look good". Many popular Web applications use the URL like this, including Gmail. Most users don't care about what's in the URL.
Related
For some specific reasons, I would need to automatically add or append a parameter to URL on every request if and only if that parameter already exists in URL since the first request. In other words, if I have the URL /share/page/site/sample/documentlibrary?embedded, every request to /share/page/site/sample/[whatever] must contain the embedded parameter plus other parameters that could be added by the original request.
I'm working with Alfresco Share (v4.2.b) what means that the web application already exists and despite of I can perform customization, I have limitations because I don't have full control on it. If it was my web app created from scratch it wouldn't be a problem. According to the restrictions I have, the solution ideally should be as less intrusive as possible. At the same time if it is a JavaScript based solution, the use YUI rather than other library is a plus but not a requirement.
I have been searching looking for an approach and after that I have in mind the next possible solutions:
Using JavaScript by adding the parameter to URL before every page unload. Something like:
window.onbeforeunload = function(e) {
// Add parameter to target URL
};
But I believe it doesn't work as I was reading and according to some tests I did. It seems there is a sort of security restriction (which makes sense by the way).
By updating the href attribute of every link (<a/>) using JavaScript too, once the page has finished loading. For example, /share/page/site/sample/document-details?nodeRef=workspace://SpacesStore/089acea3-3b37-403d-9a8d-ae484ddd2ccb could be transformed to /share/page/site/sample/document-details?nodeRef=workspace://SpacesStore/089acea3-3b37-403d-9a8d-ae484ddd2ccb&embedded. The problem of this solution is that both forms GET or POST and href triggered using JavaScript would be out of scope...
Using any URL rewrite technique or library like UrlRewriteFilter (didn't have time yet to test it, sorry).
Create an Alfresco Share extension module which changes or updates every request, maybe with the help of a module or subcomponent evaluator. I don't know if it is doable with extension modules, but I believe I read anywhere that you can perform changes to requests.
I have to add (for those with Alfresco Share knowledge) that options 1, 2 and 4 would be implemented as an extension module.
Well, I hope I have explained good enough my question. I'd strongly appreciate some advice or possible approaches. I will keep working on it anyway and I will come up with any update.
If it's for every request then a filter is the best. Share already uses the urlrewrite like you've stated so change the default one and add your parameter to it.
If you have knowledge of share then overriding the included template would be nice:
override alfresco-template.ftl which is in templates/org/alfresco/include. This template is always loaded when generating a page. It also has the portletMode defined for the Liferay Portlet.
What we've done to embed the documentlibrary is to define our own
share custom page, so I didn't need the 'always' present arg any
more.
What about proxying connections via Apache HTTPd using mod_proxy and then using mod_rewrite to redirect user requests if they do not already contain the mandatory parameter? Using the RewriteRule directive you can specify quite rich expressions that would add the parameter if it is not already there (docs)
Haven't used Alfresco but, one other option would be to have a custom JSP tag.
Lets call it customlink then when you render a link on the page use this custom jsp tag instead of an <a> tag.
E.g
<mynamespace:customlink href="/somelink">My Content</mynamespace:customlink>
The custom JSP tag can then be responsible for checking the query string parameter on the request and if it exists then appends it to the URL and prints the tag with the query string.
This has the benefit of not depending on JS or exposing any of this to the client side. It also allows further expansion in future.
I'm trying to do one app with GWT that will run inside one iframe. Until here everything is ok, the thing is that i have one form in my actual web that will send the request to the iframe. With java script when I push the button "Send Form" I change the src of my iframe and refresh later it:
document.getElementById('iframeSpecialOffers').src = container.url;
document.getElementById('iframeSpecialOffers').contentWindow.location.reload();
The web is running in www.example.com:81 and the new src for my iframe in www.example.com:8082 and i get this error
Unsafe JavaScript attempt to access frame with URL http://example:8082/Home.html#!TilePage;searchQuery=*;searchMode=1;amount=1;
position='47.3686498,8.539182500000038';leftBottomPosition='47.32023,8.448059899999976';
rightTopPosition='47.43468,8.625370100000055';availabilityEndDate=datetime'2012-08-012T18:00:00';$culture=en
from frame with URL http://example:81/. Domains, protocols and ports must match.
Thanks a lot !
To protect people from XSS attacks (Cross site scripting), browsers do not allow you to access anything inside an iFrame or window that isn't from the same domain.
However there is some sort of header you can set that tells the browser that cross domain stuff is allowed.
http://en.wikipedia.org/wiki/Cross-origin_resource_sharing
I am not sure that is the route you should go though, it would be much better to avoid that kind of thing.
If your goal is strictly to refresh the page you can do so by just setting the src again, I believe it will refresh by just doing something like:
document.getElementById('iframeSpecialOffers').src = document.getElementById('iframeSpecialOffers').src;
But if that doesn't work you could append a useless queryString parameter to make it different.
Requirement is to keep a copy of complete web page at server side same as it is rendered on client browser as past records.These records are revisited.
We are trying to store the html of rendered web page. The html is then rendered using resources like javascript, css and image present at server side. These resources keep on changing. Therefore old records are no longer rendered perfectly.
Is there any other way to solve above? We are also thinking converting it into pdf using IText or apache FOP api but they does not consider javascript effect on page while conversion. Is there any APIs available in java to achieve this?
Till now, no approach working perfectly. Please suggest.
Edit:
In summary,requirement is to create a exact copy of rendered web page at server side to store user activities on that page.
wkhtmltopdf should do this quite nicely for you. It will take a URL, and return a pdf.
code.google.com/p/wkhtmltopdf
Example:
wkhtmltopdf http://www.google.com google.pdf
Depending on just how sophisticated your javascript is, and depending on how faithfully you want to capture what the client saw, you may be undertaking an impossible task.
At a high level, you have the following options:
Keep a copy of everything you send to the client
Get the client to return back exactly whatever it has rendered
Build your system in such a way that you can actually fetch all historical versions of the constituent resources if/when you need to reproduce a browser's view.
You can do #1 using JSP filters etc, but it doesn't address issues like the javascript fetching dynamic html content during rendering on the client.
Getting the client to return what they are seeing (#2) is tricky, and bandwidth intensive.
So I would opt for #3. In order to turn a website that renders dynamic content versioned, you have to do several things. First, all datasources need to versioned too. So any queries would need to specify the version. "Version" can be a timestamp or some generation counter that you maintain. If you are taking this approach, you would also need to ensure that any javascript you feed to the client does not fetch external resources directly. Rather, it should ask for any resources from your system. Your system would in turn fetch the external content (or reuse from a cache).
The answer would depend on the server technology being used to write the HTML. Are you using Java/JSPs or Servlets or some sort of an HTTPResponse object to push the HTML/data to the browser?
If only the CSS/JS/HTML are changing, why don't you just take snapshots of your client-side codebase and store them as website versions?
If other data is involved (like XML/JSON) take a snapshot of those and version that as well. Then the snapshot of the client codebase as mentioned above with the contemporary snapshot of the data should together give you the exact rendering of your website as at that point of time.
A very resource-consuming requirement but...
You haven't written what application server you are using and what framework. If you're generating responces in your own code, you can just store it while generating.
Another possibility is to write a filter, that would wrap servlet's OutputStream and log everything that was written to it, you must just assure your filter is on the top of the hierarchy.
Another, very powerfull, easiest to manage and generic solution, however possibly the most resource-consuming: write transparent proxy server staying between user and application server, that would redirect each call to app server and return exact response, additionally saving each request and response.
If you're storing the html page, why not the references to the js, css, and images too?
I don't know what your implementation is now, but you should create a filesystem with all of the html pages and resources, and create references to the locations in a db. You should be backing up the resources in the filesystem every time you change them!
I use this implementation for an image archive. When a client passes us the url of an image we want to be able to go back and check out exactly what the image was at that time they sent it (since it's a url it can change at any time). I have a script that will download the image as soon as we receive the url, store it in the filesystem, and then store the path to the file in the db along with other various details. This is similar to what you need, just a couple more rows in your table for the js, css, images paths.
For quite a long time I use proxy servlet, and from my experience in order for javascript to properly work, the proxy servlet has to be configured to run in the ROOT context. However, a site http://www.filestube.com/ from what I investigated, its running a site from another domain on a iframe.
I am wondering what kind of approach is this?
From what I can see on the target page it loads javascript from some 'local' domains (*.filestube.com) who then in turn load javascript from another domain (e.G. google or facebook in this case).
Also there is an IFrame on the site, but IFrames may come from everywhere anyway.
So the kind of approach is: Normal, don't think about user privacy and just load everything you think you might need from everywhere.
We have a website which is coded Java with Struts Framework. The WebSite's Urls are not seo friendly. All of them are like below
../buyerApplication.do&companyId=2323
Now We want to make these URLs SEO friendly and I searched and found these solutions:
tuckey.org/urlrewrite : but i don't rely on this system.
adding
title end of link after '&' such as
"../newsId=33233&does-art-in-the-city-equal-art-for-the-city"
: In this solution I am not sure it
works well.
I am waiting your sugestions to solve this problem best.
I actually used URLRewriter (http://tuckey.org/urlrewrite/), which you referenced in your original question. It was very easy to set up and filled my needs perfectly.
To the point, you need a Filter for this.
If you want to keep your existing application's architecture, you'll need to define and create a set of rules to convert unfriendly urls to friendly urls and let the filter convert it and forward the request to the unfriendly url.
If there is no means of modifying an existing application but you want to create a new application based on this idea, you could consider to having a single page controller which translates the HttpServletRequest#getPathInfo()/getRequestURI() to execute the appropriate action class (command pattern) and finally forward the request to the appropriate JSP page. Not sure how that would fit into Struts as I haven't worked with Struts previously.
For what it's worth, you can also look at the REST plugin http://struts.apache.org/2.x/docs/rest-plugin.html, which amongst other things will make your URLs more friendly