RE: Web Proxy Portlet Relative Paths

1967874, modified 17 Years ago. New Member Posts: 11 Join Date: 1/16/09 Recent Posts
I am attempting to set up the Web Proxy portlet but am having an issue with links that use relative paths. To test I just used www.google.com. The google home page does display fine but the relative links like the “Advertising Programs” end up being linked relative to my web page instead of www.google.com. Does anyone know how to resolve this?
1967874, modified 17 Years ago. New Member Posts: 11 Join Date: 1/16/09 Recent Posts
I have still been unable to resolve my issue with relative paths being rewritten. All hrefs that are absolute are being rewritten correctly to http://www.mydomain.com/pbhs/..... But relative paths are not. They end up as http://www.mydomain.com/relativePath. I have even tried deploying the portletbridge as separate plug-in but with the same results. Is there anyone that has the web proxy or portal bridge working? If so do you not have this issue or have you been able to fix it? Any assistance would be greatly appreciated.
258920, modified 17 Years ago. New Member Posts: 5 Join Date: 11/8/07 Recent Posts
I am having an issue with the exact same thing. I am using the web proxy in liferay and none of my relative links work. Any help or insight would be greatly appreciated!
2378413, modified 17 Years ago. New Member Posts: 7 Join Date: 3/3/09 Recent Posts
I am having the same problem. Did anybody ever figure out how to resolve this?

Thanks,
Brian
1967874, modified 17 Years ago. New Member Posts: 11 Join Date: 1/16/09 Recent Posts
I have still not been able to track down the problem but have not had much time to dedicate to it this week. I am hoping to be able to dive into the portlet bridge code next week to trace through why these URLs are not being rewritten correctly.
thumbnail
14911, modified 17 Years ago. Expert Posts: 484 Join Date: 3/2/06 Recent Posts
Hi,

The best way to handle this by rewriting all the links. However instead of rewriting the web pages directly, the web proxy should write them. When I was part of Sun Portal Team, we had a complete and dynamic rewriting of the urls by set of standard and user configurable rules.

Check the following links.. which have/use the my rewriter component

http://docs.sun.com/app/docs/doc/819-5070/6n768aet0?a=view
http://www.sun.com/blueprints/0702/816-7206-10.pdf
http://www.sun.com/books/catalog/baker.xml - This book has the more latest info (with my name too..)

The following patents have more details on the same..

http://appft1.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&u=%2Fnetahtml%2FPTO%2Fsearch-adv.html&r=0&f=S&l=50&d=PG01&OS=Raja+AND+Nagendra&RS=%28Raja+AND+Nagendra%29&TD=3&Srch1=%2528Raja+AND+Nagendra%2529&StartNum=&Refine=Refine+Search&Query=Raja+AND+Nagendra+AND+Kumar


In all rewriting is a simple for ordinary pages.. However rewriting of complex pages of any product ready applications is a pain and 80 to 90% could be achieved though sun's rewriting approach.

Apache and Navel to has some rewriting which is based on regular expression.. but not so scalable in my view.

Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com
nagendra.raja@tejasoft.com
thumbnail
1395288, modified 17 Years ago. Liferay Legend Posts: 2047 Join Date: 10/7/08 Recent Posts
While googling around, I found this ticket that may be relevant,

https://issues.apache.org/jira/browse/PORTLETBRIDGE-16
thumbnail
493980, modified 17 Years ago. Regular Member Posts: 154 Join Date: 2/19/08 Recent Posts
Hey,
I came up with a work around for your problem. Modify the stylesheet to throw in a ? at the end of the url. The problem is undoubtedly in the BridgeFunctions class. If you find the real solution, please post it.
Thanks
Eric

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:java="java"
xmlns:bridge="java:org.portletbridge.portlet.BridgeFunctions"
extension-element-prefixes="bridge java">

.....................


<!-- Rewrite links -->
<xsl:template match="A/@href">
<xsl:variable name="href" select="java:lang.String.new( string( . ) )"/>
<xsl:variable name="hmmm" select="java:lang.String.new( string( '/intl/en/ads/' ) )"/>
<xsl:attribute name="href">
<xsl:choose>
<xsl:when test="java:equals( $href, $hmmm )">
<xsl:value-of select="bridge:link($bridge, $base, '/intl/en/ads/?' )"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="bridge:link($bridge, $base, .)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>

.................................
2378413, modified 17 Years ago. New Member Posts: 7 Join Date: 3/3/09 Recent Posts
@Eric

I am such a LifeRay noob. Where do I put the XSL code below? I poked around and couldn't find where to put it.



Eric Devlin:
Hey,
I came up with a work around for your problem. Modify the stylesheet to throw in a ? at the end of the url. The problem is undoubtedly in the BridgeFunctions class. If you find the real solution, please post it.
Thanks
Eric

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:java="java"
xmlns:bridge="java:org.portletbridge.portlet.BridgeFunctions"
extension-element-prefixes="bridge java">

.....................


<!-- Rewrite links -->
<xsl:template match="A/@href">
<xsl:variable name="href" select="java:lang.String.new( string( . ) )"/>
<xsl:variable name="hmmm" select="java:lang.String.new( string( '/intl/en/ads/' ) )"/>
<xsl:attribute name="href">
<xsl:choose>
<xsl:when test="java:equals( $href, $hmmm )">
<xsl:value-of select="bridge:link($bridge, $base, '/intl/en/ads/?' )"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="bridge:link($bridge, $base, .)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>

.................................
thumbnail
493980, modified 17 Years ago. Regular Member Posts: 154 Join Date: 2/19/08 Recent Posts
Brian,

If you click on the configuration icon (sprocket) in the right hand corner of the portlet, you'll get the setup page. There is a section called stylesheet. By default it is blank. You'll have to dig a copy out from portletbridge-portlet.jar. That should be in the *.war/WEB-INF/lib directory. The path inside the jar for the file you want is org\portletbridge\xsl\portletbridge.xsl. Paste in the changes above and it should get you going. Again if you find the real fix in the code, please post it.

Thanks
Eric
2378413, modified 17 Years ago. New Member Posts: 7 Join Date: 3/3/09 Recent Posts
Thanks for the help Eric.

Being new to Liferay I must say that I am surprised that this is an issue. I would have thought that a proxied site that uses relative links would be common.
1967874, modified 17 Years ago. New Member Posts: 11 Join Date: 1/16/09 Recent Posts
I am not sure the problem is in the BridgeFunctions as it does not appear that the class is being called for the URL. The site I am attempting to proxy is http://www.credoreference.com. The anchor in the html is <a tabindex="2" accesskey="a" href="/advanced.do">Advanced Search</a>. When I proxy from http://www.capecod.edu the URL becomes http://www.capecod.edu/advanced.do which does not work. I need to figure out how to append the http://www.credoreference.com to /advance.do so that the link when proxy will work correctly.
1967874, modified 17 Years ago. New Member Posts: 11 Join Date: 1/16/09 Recent Posts
Ok I was incorrect in my last post, the BridgeFunctions is being called. It now appears to me that the error is in the rewrite method. There is basically an if statement that if the url scheme is http or https do the rewrite else just return the link. The javadocs for java.net.URI indicate that “An absolute URI specifies a scheme; a URI that is not absolute is said to be relative.” So assuming that relative URIs have no scheme there should be another condition to test for absolute then based on this rewrite the URL. The challenge here however is how to append the site information to make the relative url absolute for the rewrite process.
thumbnail
493980, modified 17 Years ago. Regular Member Posts: 154 Join Date: 2/19/08 Recent Posts
I think I found a solution. I changed BridgeFunctions

from
String name = url.getPath();
int lastIndex = name.lastIndexOf('/');
if (lastIndex != -1) {
name = name.substring(lastIndex + 1);
if (name.equals("") && lastIndex > 0)
name = url.getPath().substring(
url.getPath().lastIndexOf('/', lastIndex - 1));

}
if (name.startsWith("/"))
name = name.substring(1);

to
String name = url.getPath();
if (name.startsWith("/"))
name = name.substring(1);
int index = name.indexOf('/');
if (index != -1)
name = name.substring( 0, index );
if ( name.length() == 0 )
name = "hmmm";

it also works if you use just
String name = "hmmm";


Looks like name is just for appearances.
2378413, modified 17 Years ago. New Member Posts: 7 Join Date: 3/3/09 Recent Posts
@Eric - What do I have to do to make this change? Do I have to download the source, make the change and jar it up?

Thanks,
Brian

Eric Devlin:
I think I found a solution. I changed BridgeFunctions

from
String name = url.getPath();
int lastIndex = name.lastIndexOf('/');
if (lastIndex != -1) {
name = name.substring(lastIndex + 1);
if (name.equals("") && lastIndex > 0)
name = url.getPath().substring(
url.getPath().lastIndexOf('/', lastIndex - 1));

}
if (name.startsWith("/"))
name = name.substring(1);

to
String name = url.getPath();
if (name.startsWith("/"))
name = name.substring(1);
int index = name.indexOf('/');
if (index != -1)
name = name.substring( 0, index );
if ( name.length() == 0 )
name = "hmmm";

it also works if you use just
String name = "hmmm";


Looks like name is just for appearances.
thumbnail
493980, modified 17 Years ago. Regular Member Posts: 154 Join Date: 2/19/08 Recent Posts
Brian Abston:
@Eric - What do I have to do to make this change? Do I have to download the source, make the change and jar it up?

Thanks,
Brian



That's exactly what you have to do. This thread may provide some help.
2619090, modified 17 Years ago. New Member Post: 1 Join Date: 3/25/09 Recent Posts
I'm trying to use Liferay's WebProxy portlet to allow Liferay to controlled access to our MediaWiki internal Application. Liferay is on the public Internet, user's log into it, and then with WebProxy we would like them to have access to the MediaWiki just like they would on the company internal network. We have additional internal applications we would also like to expose this way.

Is WebProxy being used sucessfully this way, or are other methods being used? (I don't want to use an iFrame because I don't want to expose our MediaWiki site directly on the Internet. I want to go through Liferay.)

I'm having problems getting this to work. Relative links in the content don't seem to be handled, and I've tried the BridgeFunctions modifications listed above with no success. Looking at the code it appears that it only will work with fully qualified links containing http and https. Our MediaWiki has a lot of content with many relative links.

I also tried testing with proxying google, and it only works with about 10% of the links returned from a search. If there is more than one level on the url beyond the server reference it seems to fail with a bad syntax() error being displayed instead of the content. (I'm using the latest Liferay 5.2.2, and the webproxy bundled with it.)


Do you normally need to modify the xsl extensively? Do you need to modify the portletbridge? Any sample xsl that does work with google I can study?
thumbnail
493980, modified 17 Years ago. Regular Member Posts: 154 Join Date: 2/19/08 Recent Posts
Jeff,
Having internal servers behind the firewall with their content proxied by liferay is exactly how we are using it. Generally, I've had pretty good luck with the portlet bridge, but it's not a magic bullet. It helps to understand the site you are proxing and portlet bridge.

I think the patch on this page should handle the relative link problem. I've posted other patches to deal with 1) servlet renamed to pbhs instead of PortletBridgeServlet leading to incorrect css url refs 2) input stream being unavailable on a post 3) removing stylesheet entries which conflict with liferay e.g. body | .portlet

If you've got javascript variables with urls you'll need something like the below.

<xsl:template match="/HTML/BODY">
<DIV>
<xsl:attribute name="class">
<xsl:value-of select="@class"/>
</xsl:attribute>
<xsl:apply-templates select="node()"/>
<script>
<xsl:text>jshref = "</xsl:text><xsl:value-of select="bridge:link($bridge, $base, '/blah/blah.html' )"/><xsl:text>";</xsl:text>
</script>
</DIV>

<SCRIPT>
<xsl:value-of select="@onload"/>
</SCRIPT>
</xsl:template>

Eric