The perils and pitfalls of the WCI gateway transformer

All right, so you know my ol’ phrase “browser to portal, portal to back-end server“.  That is, the browser connects to the portal, the portal connects to the back-end-server (i.e., your custom code), back-end server sends HTML to the portal, the portal parses and transforms that HTML and returns it to the browser. 

This post is about that step where the portal transforms the HTML you return from the your custom code.  I could be incredibly long-winded here about all sorts of tricks and nuances of some adaptive tags that seem to only half-work, but figured I’d just share some quick tips to give you some ideas on how you can trick the gateway engine to do your bidding.

Problem: You do NOT want a URL transformed, and just want to link to something like /portal/  If you just use <a href=”/portal/″>, the portal will think you’re trying to use a link relative to your application and helpfully transform it for you.  

Solution:  The portal’s parser isn’t all that smart; it just parses the DOM and looks for items like <img src> or <a href> parameters, so if you obfuscate the link a bit, the portal won’t detect it as a “real” link: 

               document.write(‘<a hre’ + ‘f=”/portal/″>link text</a + ‘>’); 

Problem: You have a URL defined in a properties file that you DO want to make sure is transformed, even if it’s in some place in your JS code that the transformer usually can’t detect (like a JS variable). 

Solution #1: Add the variable to an object, set the object.location, and use that string so that when rendered, the transformer will wrap its transformation javascript around your code: 

                var actionServlet = new Object();

                actionServlet.location = ‘<%=SERVLET_URL%>’;

                var actionServletURL = actionServlet.location; 

Solution #2: Directly call the Javascript method available on every page to manually transform the link: 

               var actionServletURL = pt_<%=portletID%>.transformURL(‘<%=SERVLET_URL%>’); 

Problem: You’ve an entire JavaScript file that has to be gatewayed, but you’d just like the portal to “pass it through” without parsing it at all. 

Solution: The portal looks at the MIME type of a document/file before it decides to parse it, and is pretty strict about only parsing MIME types with “text/*” in them (like “text/javascript”).  But browsers aren’t so strict!  So if you set the MIME type of your javascript file to “application/javascript”, the portal won’t transform it, but the browser will still run it like any other javascript file: 

               response.setHeader(“Content-Type”, “application/javascript; charset=utf-8” );

Tags: , ,

One Response to “The perils and pitfalls of the WCI gateway transformer”

  1. Steve says:

    Those are good tips that may come in handy. Thanks for the post.

Leave a Reply