Issues with Friendly URL and DefaultFriendlyURLMapper

5311645, modified 15 Years ago. New Member Posts: 18 Join Date: 7/14/10 Recent Posts
Hi there,

As my title may suggest i'm currently facing issues with liferay 6's friendly url. what i'm trying to do is:

i developed a portlet that can be used for creating events, manage attendences and some more stuff.

an url that refers to an event is like the following:

http://localhost:8080/web/guest/events?p_auth=EkgoCvT1&p_p_id=meetupsportlet_WAR_meetupsportlet_INSTANCE_kNW3&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_meetupsportlet_WAR_meetupsportlet_INSTANCE_kNW3_javax.portlet.action=SHOW_DETAILS&event_id=9900

Since this URL is very unhandy to remember or to pass it to anyone, i'm trying to shorten it via the friendly URL feature:

Basically the only information i need out of this whole "wall of text", is the event_id

So what im trying to get is sth. like http://localhost:8080/web/guest/events/9900 or maybe http://localhost:8080/web/guest/events/details/9900.

changed the liferay-portlet.xml as follows:

<liferay-portlet-app>
    <portlet>
        <portlet-name>meetups-portlet</portlet-name>
        <icon>/icon.png</icon>
        <friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly-url-mapper-class>
        <friendly-url-mapping>events</friendly-url-mapping>
        <friendly-url-routes>../eventRoutes.xml</friendly-url-routes>
...</portlet></liferay-portlet-app>


and created a eventRoutes.xml that currently only contains

<!--?xml version="1.0"?-->


<routes>
    <route>
        <pattern>events/{event_id}/</pattern>
        <implicit-parameter name="event_id"></implicit-parameter>
    </route>
</routes>


At this point i don't know what to do next and so i was hoping you could give me a hint how to geht that ugly URLs shortened

Any help is appreciated

thanks in advance

Markus
4521410, modified 15 Years ago. Junior Member Posts: 33 Join Date: 1/26/10 Recent Posts
Hello,

I suppose you've used this article from the wiki to get there. If not you should read it.

The only problem I see in your files is that the <pattern> should start with a /.
It should give you an url like this one : http://localhost:8080/web/guest/events/-/events/events/9900

All those "events" correspond to these fields in your xml files :
http://localhost:8080/web/guest/(page name)/-/<friendly-url-mapping>/<pattern>

If your event id is a number, you may want to specify it in the pattern by doing <pattern>/events/{event_id:\d+}/</pattern>.
5311645, modified 15 Years ago. New Member Posts: 18 Join Date: 7/14/10 Recent Posts
hi, thank you for your response

sadly i still couldn't figure out why it doesn't work.

to this point i tested nearly every possible combination of parameter settings, pattern (with / as well as without) and ...
the only result i got was that i grew some more grey hairs, which is quite unsatisfying.

can you figure out ANY possible reason why this doesn't work or maybe provide any hint where to look for the error.

thanks a lot

Markus
4521410, modified 15 Years ago. Junior Member Posts: 33 Join Date: 1/26/10 Recent Posts
Hello,

I just noticed from the url in your first post that your portlet is instanceable.
So your friendly url must have the instanceId included in the pattern, something like this :

    <route>
        <pattern>/{instanceId}/events/{event_id}/</pattern>
        <implicit-parameter name="event_id"></implicit-parameter>
    </route>
thumbnail
4445682, modified 15 Years ago. Regular Member Posts: 220 Join Date: 1/14/10 Recent Posts
Hi Markus,

you can also make your portlet not-instanciable, if you do not need more than one instance of your portlet in one page (which I believe is the case with event-management, right?)

In order to do it, go to your liferay-portlet.xml and set instanciable tag to false:

<liferay-portlet-app>
<portlet>
<portlet-name>blabla</portlet-name>
<icon>/icon.png</icon>
<instanceable>false</instanceable>
<header-portlet-css>/css/style.css</header-portlet-css>
<header-portlet-javascript>/js/bla.js</header-portlet-javascript>
</portlet>

Cheers.
5311645, modified 15 Years ago. New Member Posts: 18 Join Date: 7/14/10 Recent Posts
thanks pujan,

i just did so, but withour the desired effect. what i now have is:

liferay-portlet.xml:

<liferay-portlet-app>
    <portlet>
        <portlet-name>meetups-portlet</portlet-name>
        <icon>/icon.png</icon>
        <friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly-url-mapper-class>
        <friendly-url-mapping>events</friendly-url-mapping>
        <friendly-url-routes>../eventRoutes.xml</friendly-url-routes>
        <instanceable>false</instanceable>
        <header-portlet-css>/css/main.css</header-portlet-css>
        <header-portlet-javascript>/js/jquery-1.4.2.js</header-portlet-javascript>
        <footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
        
        
        <css-class-wrapper>meetups-portlet</css-class-wrapper>
    </portlet></liferay-portlet-app>


eventRoutes.xml:

<routes>
    <route>
        <pattern>/events/{event_id}/</pattern>
        <implicit-parameter name="event_id"></implicit-parameter>
    </route>
</routes>


Event-URLs follow the following pattern:


http://localhost:8080/web/guest/events?p_auth=EBGej3rW&amp;p_p_id=meetupsportlet_WAR_meetupsportlet&amp;p_p_lifecycle=1&amp;p_p_state=normal&amp;p_p_mode=view&amp;p_p_col_id=column-1&amp;p_p_col_count=1&amp;_meetupsportlet_WAR_meetupsportlet_javax.portlet.action=SHOW_DETAILS&amp;event_id=9900



although everything seems to be correct configured, it just doesnt work, which starts to freak me out..

Any other ideas what my problem may be?

thanks a lot

Markus
thumbnail
4445682, modified 15 Years ago. Regular Member Posts: 220 Join Date: 1/14/10 Recent Posts
Strange.

Maybe some of Liferay staff have any idea why this doesn't work?
thumbnail
4445682, modified 15 Years ago. Regular Member Posts: 220 Join Date: 1/14/10 Recent Posts
Hi Markus,

I see
<friendly-url-routes>../eventRoutes.xml</friendly-url-routes>

and usually in liferay they use a complete path, like for example in message board portlet:
<friendly-url-routes>com/liferay/portlet/messageboards/message-boards-friendly-url-routes.xml</friendly-url-routes>

and the .xml file is at
src/com/liferay/portlet/messageboards/message-boards-friendly-url-routes.xml

Considering you are using a relative path, are you sure your .xml file is at the right address?
thumbnail
6292564, modified 15 Years ago. New Member Posts: 4 Join Date: 10/29/10 Recent Posts
I'm trying to resolve the exact same issue as Markus. I am also trying to follow the wiki article .

My URL looks like

http://localhost:8080/web/guest/test?p_auth=m5H8XQYc&amp;p_p_id=searchboxportlet_WAR_SamplePortletportlet&amp;p_p_lifecycle=1&amp;p_p_state=normal&amp;p_p_mode=view&amp;p_p_col_id=column-2&amp;p_p_col_count=2&amp;_searchboxportlet_WAR_SamplePortletportlet_query=test&amp;_searchboxportlet_WAR_SamplePortletportlet_search=Search


My portlet XML is

	<portlet>
		<portlet-name>searchboxportlet</portlet-name>
		<icon>/icon.png</icon>
		<friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly-url-mapper-class>
		<friendly-url-mapping>search_friendly_display</friendly-url-mapping>
		<friendly-url-routes>com/test/package/search-friendly-url-routes.xml</friendly-url-routes>
		<instanceable>false</instanceable>
		<private-request-attributes>false</private-request-attributes>
		<private-session-attributes>false</private-session-attributes>
		<header-portlet-css>/css/portlet.css</header-portlet-css>
		<footer-portlet-javascript>
			/js/javascript.js
		</footer-portlet-javascript>
		<css-class-wrapper>searchboxportlet-portlet</css-class-wrapper>
	</portlet>


And my route xml is

<routes>
	<route>
		<pattern>/query/{query}</pattern>
		<implicit-parameter name="query"></implicit-parameter>
	</route>
</routes>


I can confirm that Liferay is able to access the route XML because when I ignore parameters it actually removes parameters. e.g.

<routes>
	<route>
		<pattern></pattern>
		<ignored-parameter name="p_p_col_id" />
		<ignored-parameter name="p_p_col_count" />
		<ignored-parameter name="p_p_mode" />
		<ignored-parameter name="p_p_state" />
	</route>
</routes>


The above route removes most of the parameters and gives me the following URL

http://localhost:8080/web/guest/test/-/search_friendly_display?p_auth=m5H8XQYc&amp;p_p_lifecycle=1&amp;_searchboxportlet_WAR_SamplePortletportlet_query=test&amp;_searchboxportlet_WAR_SamplePortletportlet_search=Search


But as you can see it leaves the "p_auth" parameter that makes it impossible for me to give the URL to someone else.

I'm still not quite sure I completely understand how the route xml works and would really appreciate any additional pointers or next steps.

Thanks in advance
6330432, modified 15 Years ago. New Member Post: 1 Join Date: 11/3/10 Recent Posts
Experiencing something similar here...

With friendly routes applied the url still carries the p_auth parameter. Removing it causes a PrincipalException to be thrown "Invalid authentication token".

Any ideas how to work around this?
(I saw somewhere in this forum someone suggesting disabling the p_auth check.. but that does not feel right)

Thanks,
Pedro
thumbnail
6292564, modified 15 Years ago. New Member Posts: 4 Join Date: 10/29/10 Recent Posts
I was finally able to the routing to work (partially) for my case using the following XML

<routes>
	<route>
		<pattern>/{search}</pattern>
		<implicit-parameter name="p_p_id">searchboxportlet_WAR_SamplePortletportlet</implicit-parameter>
		<implicit-parameter name="p_p_lifecycle">1</implicit-parameter>
	</route>
</routes>


However, I'm still unable to hide the p_auth parameter. I see the "Document Library" portlet from Liferay doing it but I couldn't figure out how, any pointers there would help.
5311645, modified 15 Years ago. New Member Posts: 18 Join Date: 7/14/10 Recent Posts
Hi all,

I made some progress in solving my problem. Im now at the same point that milton is.

The Event-URLs look like:

http://localhost:8080/web/guest/events/-/events/SHOW_DETAILS/?p_auth=ArUrV4F6&amp;event_id=947


The problem im stil facing at this point is, that p_auth, as well as event_id, aren't hidden.

Since milton has the same troubles with p_auth, i'd probably assume its a malfunction of liferay. I also believe that the problem with not hiding "event_id" is related to this.

Maybe some liferay staff could write some sentences to this issue.

Thanks in advance, markus
thumbnail
Eduard Saldaña, modified 14 Years ago. New Member Posts: 19 Join Date: 3/9/11 Recent Posts
Markus Ziller:
Hi all,

I made some progress in solving my problem. Im now at the same point that milton is.

The Event-URLs look like:

http://localhost:8080/web/guest/events/-/events/SHOW_DETAILS/?p_auth=ArUrV4F6&amp;event_id=947


The problem im stil facing at this point is, that p_auth, as well as event_id, aren't hidden.

Since milton has the same troubles with p_auth, i'd probably assume its a malfunction of liferay. I also believe that the problem with not hiding "event_id" is related to this.

Maybe some liferay staff could write some sentences to this issue.

Thanks in advance, markus


Hi Markus,

How did you convert _meetupsportlet_WAR_meetupsportlet_javax.portlet.action=SHOW_DETAILS into /SHOW_DETAILS?? I have the same problem but I can't solve this problem.

Thank you very much
Sergey Stepanenko, modified 14 Years ago. Junior Member Posts: 47 Join Date: 6/1/10 Recent Posts
I'm also interested - can't figure out how to tranform spring action parameters. Please post .xml if possible! Thanks in advance!
Phoenix Zerin, modified 14 Years ago. Junior Member Posts: 60 Join Date: 6/28/11 Recent Posts
Eduard Saldaña:
Hi Markus,

How did you convert _meetupsportlet_WAR_meetupsportlet_javax.portlet.action=SHOW_DETAILS into /SHOW_DETAILS?? I have the same problem but I can't solve this problem.

Thank you very much



See this thread. You'll need to make sure you add <implicit-parameter name="p_p_lifecycle">1</implicit-parameter> to your routes.xml file.
thumbnail
Eduard Saldaña, modified 14 Years ago. New Member Posts: 19 Join Date: 3/9/11 Recent Posts
Hi all,
We solved the problem using urlRewrite.xml located in "/ROOT/WEB-INF"

To solve the problem we map the url in xml file and then we make the links like the mapping. I attach an example below.

<rule>
  <from>^/web/guest/(.*)/(.*)/(.*)$</from>
  <to>/web/guests/page?p_p_id=portletNameFront_WAR_portletNameportlet_INSTANCE_J3Wi&amp;p_p_lifecycle=1&amp;p_p_state=normal&amp;p_p_mode=view&amp;p_p_col_id=column-1&amp;p_p_col_pos=1&amp;p_p_col_count=2&amp;_portletNameFront_WAR_portletNameportlet_INSTANCE_J3Wi_javax.portlet.action=actionName&amp;parameter1=$1&amp;parameter2=$2
  </to>
</rule>


Where each $number is the param (.*) of the from tag.

In that way we could convert this ugly url web/guests/page?p_p_id=portletNameFront_WAR_portletNameportlet_INSTANCE_J3Wi&amp;p_p_lifecycle=1&amp;p_p_state=normal&amp;p_p_mode=view&amp;p_p_col_id=column-1&amp;p_p_col_pos=1&amp;p_p_col_count=2&amp;_portletNameFront_WAR_portletNameportlet_INSTANCE_J3Wi_javax.portlet.action=actionName&amp;parameter1=param1&amp;parameter2=param2

to /web/guest/param1/param2/FriendlyName

Note that the last parameter is only to make the url more friendly.
5311645, modified 15 Years ago. New Member Posts: 18 Join Date: 7/14/10 Recent Posts
Milton Waddams:
I was finally able to the routing to work (partially) for my case using the following XML

<routes>
	<route>
		<pattern>/{search}</pattern>
		<implicit-parameter name="p_p_id">searchboxportlet_WAR_SamplePortletportlet</implicit-parameter>
		<implicit-parameter name="p_p_lifecycle">1</implicit-parameter>
	</route>
</routes>


However, I'm still unable to hide the p_auth parameter. I see the "Document Library" portlet from Liferay doing it but I couldn't figure out how, any pointers there would help.


try adding


portlet.add.default.resource.check.enabled=false
auth.token.check.enabled=false


to your portal-ext.properties.

this removes the p_auth paramater from the url.

since i'm not quite sure what the effects of this on the behaving of liferay are, i'd rather look at this as a kind of workaround than as an actual solution
thumbnail
6292564, modified 15 Years ago. New Member Posts: 4 Join Date: 10/29/10 Recent Posts
Markus Ziller:

try adding


portlet.add.default.resource.check.enabled=false
auth.token.check.enabled=false


to your portal-ext.properties.

this removes the p_auth paramater from the url.

since i'm not quite sure what the effects of this on the behaving of liferay are, i'd rather look at this as a kind of workaround than as an actual solution


Thanks Markus!

I will give that a try. It should do what I need *for now*. I would also be interested to know how it affects liferay behavior and if there is a recommended alternative.
thumbnail
Puj Z, modified 14 Years ago. Regular Member Posts: 220 Join Date: 1/14/10 Recent Posts
I don't think you can use friendly URLs for action URLs. At least you can't use the action name directly as one of the attributes of the URL. But I'm not 100% sure.
thumbnail
Gunther Verhemeldonck, modified 7 Years ago. New Member Posts: 7 Join Date: 11/23/12 Recent Posts

It is possible for sure. Just add an init-param entry to your portlet.xml to disable the p_auth token just for this single portlet.

<init-param>
<name>check-auth-token</name>
<value>false</value>
</init-param>

For Liferay DXP add following property to your portlet:

    "javax.portlet.init-param.check-auth-token=false"