cancel
Showing results for 
Search instead for 
Did you mean: 

flaky WebPreviewer when used in anything outside of Share

ofrxnz
Champ in-the-making
Champ in-the-making
So, to give everyone a little background, i have glued together a joomla plugin using parts of joosco and the other plugin (by joomla tools)

basically, it is an updated joomla tools plugin that has been modified to operate as the currently logged in user.  Using the Joosco plugin,  joomla authenticates against Alfresco and the user holds an alf_ticket as a session ID.  Then, the joomlatools plugin use the alf_ticket it picked up for all its operations.   I also fixed the joomlatools to use the new WebPreview component (mostly).  To get this to work, i had to modify the webpreview.js file in share with a switch that detects if alf_ticket is floating around and if it is, use a url with the alf_ticket.  if not, use the original method url with no alf_ticket in the get

the situation is as follows

So, lets say i go into Share and upload 5 documents (2 page PDFs) then i do NOT look at the document page.  as a result, no preview/webpreview is generated. 

Next, i go into Joomla and navigate to one of those documents.  The web previewer loads, the swirly loading thing comes up and the document previews successfully.   Everything works as it should (as long as the preview hasn't been called anywhere before)

However, if i clear my browser cache, restart the browser and navigate back to the same document using the joomla plugin, the swirl will come up and then the preview will fail to load.  Its a generic fail to transfer/load the preview error. 

Now, if i go back into share and look at that document, the previewer always successfully loads the preview while in share.  whether it is cached locally or not.

now, if i go back to the joomla plugin and look at the document, the preview will work (i assume because it was still cached from the share page)

clear my cache again and it does not work in joomla until I go into Share and it gets cached

from what i can tell, the error message was generated within the WebPreviewer.swf and i have no idea where to start. 

Since i am running joomla on a separate server, i set the allowScripts in the instantiation of the previewer to All, so any site could make the previewer do things. 

I thought this would strip any cross site issues but apparently it hasn't. 


Any ideas?  Ill post the code somewhere if anyone wants to take a crack. 

Thanks

Adam
12 REPLIES 12

mikeh
Star Contributor
Star Contributor
You don't mention what O/S or browser you're testing with, but if it's a Windows client and MSIE the try installing Fiddler on the client to help see what's going on. Note you can use Firefox, Safari, etc. with Fiddler too - just configure their proxy servers to localhost:8888

Initially, it sounds like an authentication issue - the "alfresco" proxy endpoint expects to have gone through a login sequence, so you might want to alter the  content URL given to the previewer so it's going directly to the repository.

Thanks,
Mike

ofrxnz
Champ in-the-making
Champ in-the-making
Thanks for the reply,

Sorry i did not include more information.  My mind is a bit fried today after trying to run this one down. 

I am testing primarily on windows xp sp3 on what ever the most current Firefox is.  IE 8 also exhibits the same issue

I used the following bit to generate the url that the WebPreviewer.swf instance recieves. (i think this is the one)

url = Alfresco.constants.PROXY_URI + "api/node/" + nodeRefAsLink + "/content/thumbnails/" + preview + argsNoCache + "&alf_ticket=" + Alfresco.constants.ALF_TICKET;

When processed, the url that is passed to the instance of WebPreviewer.swf is as follows (cleaned of anything identifying).

http://<server>:8080/share/proxy/alfresco/api/node/workspace/SpacesStore/<bigLongNodeRefrenceNumberIThinkItsCalledAUUID>/content/thumbnails/webpreview?c=force&noCacheToken=1241552512508&alf_ticket=TICKET_<stringOfNumbersAndLettersThatAlfGaveMeWhenILoggedIn>

I used the alert(url); method to get that.  I had it post that just before the object was posted using "so.write(this.id + "-swfPlayer-div");"  I guess that does not rule out encoding issues.

If i copy and paste this url into its own tab, even though the WebPreviewer.swf instance in joomla will fail to load webpreview,   this new tab will either try to download a flash file(IE) which, when opened, cycles through every page in the document or, in the case of FF opens in the browser and begins flipping through the document pages.

Also, if i open the joomla page in FF and retrive that url, i can restart IE and clean out my IE cache, paste that url in, and IE has no trouble retrieving the preview (event though all of its cached credentials are cleared) which at least made me think, the &alf_ticket= bit was working as authentication

Ill go ahead and try fiddler and see what happens.  always great to find a new tool

I thought it was an authentication issue too but, once i upload the document the first time if i dont go to the document view in share, the first time i load the webpreview in joomla with a clean cache, it works.  if i clean the cache again it fails.  (unless i went into the document view in Share which probably caches it)

Again thanks for the help.  Every bit is appreciated.

Adam

ofrxnz
Champ in-the-making
Champ in-the-making
update to that last one…..

I tried fiddler and i think you were spot on but i dont know why

fiddler says this is what was asked of the server

GET /share/proxy/alfresco/api/node/workspace/SpacesStore/fdfcb8f0-9929-42c8-8589-4158dfe6e319/content/thumbnails/webpreview?c=force HTTP/1.1

which clearly results in a 401

even though, when i passed it to the flash i thought it was (edited to protect my innocent server)

http://10.0.0.1:8080/share/proxy/alfresco/api/node/workspace/SpacesStore/fdfcb8f0-9929-42c8-8589-415...

Now i have to hunt down where it changed/truncated.

Is the WebPreviewer.swf mutating it before it makes the request?

Anyone have any ideas?

Thanks for the help Mike. 

Adam

ofrxnz
Champ in-the-making
Champ in-the-making
I think this one is solved

in web-preview.js

so.addVariable("url", previewCtx.url);

needed to be changed to

so.addVariable("url", escape(previewCtx.url));

without this the ampersand character would cause a truncation in the AS.

I still need some more through testing but I believe i have web-preview.js modified so the previewer will work with or without the &alf_ticket=ticket_ syntax

if anyone wants it let me know

yasosaran
Champ in-the-making
Champ in-the-making
Hi Adam,

I am trying something like, Trying to open a document in different viewer, but its prompting me for username and password. Could you please tell me how you passed the url , or what modification you did for the url.

Thanks

ofrxnz
Champ in-the-making
Champ in-the-making
so, once you authenticate, you should receive a "ticket" from alfresco.  Simply add on the following GET argument to any API URL and Alfresco will see the ticket, check if its valid and, if it passes, will only require the ticket for authentication. 

this is what the get argument looks like

"alf_ticket=TICKET_f7ebbb176309c35b53acabcc2e3378bc720c9a24"

so, with only one GET argument it will be something like

http://server:8080/alfresco/some/api/path?alf_ticket=TICKET_f7ebbb176309c35b53acabcc2e3378bc720c9a24

for this one, if $path="http://server:8080/alfresco/some/api/path"

in PHP you would build it something like

$url= $path . '?' . $ticket;

or in the case of multiple GET arguments

http://server:8080/alfresco/some/api/path?something=data&somethingElse=arguement&alf_ticket=TICKET_f...

This is an example of a fully built URL my code generates.  this has some time dependent functions, but this is bassically found in the web-preview.js file.  and all i did was add the "alf_ticket=<ticket>" argument.

http://10.0.0.1:8080/share/proxy/alfresco/api/node/workspace/SpacesStore/fdfcb8f0-9929-42c8-8589-415...

I think there is also a JSON and a POST way to use this authentication but GET has worked great for me so far

In the case of the Share webpreviewer (which i am using) i had to do two things, 1.) modify the Share files and put a switch in place that detects a ticket variable.  if the ticket variable is set, use ticket authentication.  else, use the default string and 2.)I needed to properly encode the url to avoid truncation issues…Basically it was dropping everything after the & symbol.  in javascript i did that with escape(url) escape changes symbols to web encoded characters. 

let me know if that points you in the right direction. 

Im out of town right now so dont have any code snippits readily available

Adam

yasosaran
Champ in-the-making
Champ in-the-making
Hi Adam,

Thanks for the reply. Could you please post the code for how to get the alf_ticket? I am not sure how to do that.

Thanks,
Yaso

ofrxnz
Champ in-the-making
Champ in-the-making
you can get a ticket from the server using either GET or POST

Here is teh GET method.  GET is easier to use when your figuring out how this works but POST is more favorable for security/obfuscation. 

http://server:8080/alfresco/service/api/login?u=username&pw=password

It will present you with a ticket

in the joomla plug in, the code to put the alfticket part on the end of a URL will look something like this

?alf_ticket='.$this->getTicket()


this is the chunk of code in the joomla plugin that returns the ticket when you pass it the URL i posted at the top.  mind you, i have modified this from its original code

   protected function getXml($uri) 
   {
      $result = null;
      
      try
      {   
         $client = new Zend_Http_Client($uri, array(
             'maxredirects' => 0,
             'timeout'      => 30));

         //$client->setAuth($this->_profile->username, $this->_profile->password);
         $response =& $client->request();

         if ($response->isSuccessful()) {
            $result = new SimpleXMLElement($response->getBody());
         } else {
            JError::raiseError($response->getStatus(), "Could not connect to server : ".$response->responseCodeAsText($response->getStatus()));
         }
      }
      catch (Zend_Http_Client_Exception $e)
      {
         JError::raiseError(500, $e->getMessage());
      }
      
      return $result;
   }

yasosaran
Champ in-the-making
Champ in-the-making
Hi Adam

Thanks again for the code snippet. But I am trying it in javascript. Let me see how I could the ticket.

In meanwhile, instead of passing alf_ticket to the url I added, a=true (this is in the web-preview javascript) , now its not prompting me for the credentials. It seems to be working, only thing I don't what "a=true" is for

Do you know what "a=true"  refers?

Thanks.