Vue combinée Vue Plate Arborescence
Sujets [ Précédent | Suivant ]
toggle
Traolly Xiong
Liferay URL redirect
28 juillet 2014 13:57
Réponse

Traolly Xiong

Rang: Regular Member

Publications: 161

Date d'inscription: 30 décembre 2011

Publications Récentes

Hello Community,
I can't find any solution via search, but is recommended way of redirecting end users to a new URL in a Liferay portlet jsp file?

I'm currently using "reqeust.sendRedirect("http://www.nba.com");" and it's not working.

Any ideas?

Thanks.

Traolly Xiong
Olaf Kock
RE: Liferay URL redirect
29 juillet 2014 00:25
Réponse

Olaf Kock

LIFERAY STAFF

Rang: Liferay Legend

Publications: 3425

Date d'inscription: 23 septembre 2008

Publications Récentes

if you're using this in a JSP, request will be the HttpServletRequest - just because the Servlet/JSP spec specifies that it must be there. (I'm assuming that you're referring to response.sendRedirect..., but still, HttpServletResponse). But you shouldn't use this at all when you render a portlet: While you're rendering your portlet, you can't assume that you're actually rendering the full page: Your portlet might be rendered as a result of an Ajax call, or the response might already be committed.

You can do this in an action handler, e.g. during processAction() on an ActionResponse - it has a legitimate sendRedirect method that you can call to link to a specific external URL.

Another way to achieve the same means, though it's also a hack, is to generate javascript that does the redirection. Why is this a hack? A portlet action can be handled by exactly one portlet, which, incidently, is also the number of redirections that make sense on a single request. If every portlet you have on a page would decide that it should send you somewhere else through javascript, which one would you expect to win?
Traolly Xiong
RE: Liferay URL redirect
30 juillet 2014 09:41
Réponse

Traolly Xiong

Rang: Regular Member

Publications: 161

Date d'inscription: 30 décembre 2011

Publications Récentes

Interesting. The goal is to perform a redirect when detecting a unique string in the URL on the back-end side before
the render phase (JSP). There is really no action to be performed before rendering the JSP so the action URL phase
might not work. It sounds like maybe I may need to override the portlet's render method? Any examples would be great.

Thanks.
Olaf Kock
RE: Liferay URL redirect
30 juillet 2014 11:59
Réponse

Olaf Kock

LIFERAY STAFF

Rang: Liferay Legend

Publications: 3425

Date d'inscription: 23 septembre 2008

Publications Récentes

ServletFilter?
Traolly Xiong
RE: Liferay URL redirect
31 juillet 2014 13:16
Réponse

Traolly Xiong

Rang: Regular Member

Publications: 161

Date d'inscription: 30 décembre 2011

Publications Récentes

I don't think the URL pattern mapping in the "web.xml" will pick up on the browser URL, but only the URL paths for folders / files (i.e. css, js, etc.).
I will attempt to try this and see if it's possible.

ex) web.xml
...
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/</url-pattern>
</filter-mapping>
...

- "/" only triggers filter class when the request is the plugin root
- "/*" triggers for all requests under the plugin dir


Doesn't trigger the filter class base on the browser URL but currently only a servlet or static content path.

Thanks.
Olaf Kock
RE: Liferay URL redirect
31 juillet 2014 15:25
Réponse

Olaf Kock

LIFERAY STAFF

Rang: Liferay Legend

Publications: 3425

Date d'inscription: 23 septembre 2008

Publications Récentes

You can introduce new servlet filters as a hook by adding them to liferay-hook.xml. I'm doing exactly that in my HSTS plugin (without the redirect though). Source is contained in the plugin
Traolly Xiong
RE: Liferay URL redirect
31 juillet 2014 17:20
Réponse

Traolly Xiong

Rang: Regular Member

Publications: 161

Date d'inscription: 30 décembre 2011

Publications Récentes

With some minor tweaks I got the redirect to work as expected.

Thanks for the tips.
Traolly Xiong
RE: Liferay URL redirect
31 juillet 2014 17:24
Réponse

Traolly Xiong

Rang: Regular Member

Publications: 161

Date d'inscription: 30 décembre 2011

Publications Récentes

Dealing with hooks for this sole purpose of detecting a unique URL with some query parameters, doing a redirect and setting session variables may not be enough to go that route. The idea is slick though. I'll use what I've implemented for now and will consider your suggestion if ever need be.

Thanks.
Traolly Xiong
RE: Liferay URL redirect
25 août 2014 18:34
Réponse

Traolly Xiong

Rang: Regular Member

Publications: 161

Date d'inscription: 30 décembre 2011

Publications Récentes

Hello,
Using this servlet, I can't seem to use the api to determine if the user is logged in or not.

ex)
- ThemeDisplay api
- request.getRemoteUser()
- User class

They all seem to just return null logged in or not. I'm not sure as to why yet.

Any tips on this issue?

Thanks.
Nagendra Kumar Busam
RE: Liferay URL redirect
25 août 2014 21:38
Réponse

Nagendra Kumar Busam

Rang: Liferay Master

Publications: 653

Date d'inscription: 7 juillet 2009

Publications Récentes

I am not sure whether you tried what was written in this link

http://stackoverflow.com/questions/19266690/how-to-get-liferay-remote-user-from-filter-class
Traolly Xiong
RE: Liferay URL redirect
25 août 2014 23:53
Réponse

Traolly Xiong

Rang: Regular Member

Publications: 161

Date d'inscription: 30 décembre 2011

Publications Récentes

Yes I've tried that and it always returns null. Have you tried it before and if yes, have you tried it locally as well?
Olaf Kock
RE: Liferay URL redirect
26 août 2014 01:01
Réponse

Olaf Kock

LIFERAY STAFF

Rang: Liferay Legend

Publications: 3425

Date d'inscription: 23 septembre 2008

Publications Récentes

In liferay-hook.xml you can specify where your filter should be inserted into the existing filters. Check what I did in HSTS-hook:
1<servlet-filter-mapping>
2  <servlet-filter-name>HSTS-Filter</servlet-filter-name>
3  <before-filter>SSO Open SSO Filter</before-filter>
4  <url-pattern>/*</url-pattern>
5  <dispatcher>REQUEST</dispatcher>
6  <dispatcher>FORWARD</dispatcher>
7</servlet-filter-mapping>

e.g. the before-filter line. As I'm using request.getAttribute("USER") and it returns the valid user, you might insert your filter at a different place in the chain, when this is not yet initialized.
Traolly Xiong
RE: Liferay URL redirect
10 septembre 2014 13:01
Réponse

Traolly Xiong

Rang: Regular Member

Publications: 161

Date d'inscription: 30 décembre 2011

Publications Récentes

Interesting I must try this out.

Thanks.
Enrique Valdes Lacasa
RE: Liferay URL redirect
20 février 2015 15:51
Réponse

Enrique Valdes Lacasa

Rang: Junior Member

Publications: 67

Date d'inscription: 29 juillet 2014

Publications Récentes

Interesting discussion...I haven't tried this one out yet but it seems like something cool to do with hooks.

I am in the middle of implementing a functionality, and maybe someone who used this had a quick answer:

I want authenticated users to be redirected to the home page (at the /home url) when they try to visit the login page...rather than to land at the login page. My login page url in portal-ext.properties is: auth.login.url=/web/guest/login.

So, after reading this...I think that adding a servlet filter hook with some url mapping to match /web/guest/login would be appropriate. Then I would have to process the redirection somehow...which is what is causing me some doubts. I thought of asking first to see if anyone could give some recommendation.

Thank you so much! And have a good weekend.
Enrique Valdes Lacasa
RE: Liferay URL redirect
23 février 2015 10:36
Réponse

Enrique Valdes Lacasa

Rang: Junior Member

Publications: 67

Date d'inscription: 29 juillet 2014

Publications Récentes

Replying to myself...I just found a post where a member asked EXACTLY what I asked here on Friday, so I will continue with the discussion there:
https://www.liferay.com/community/forums/-/message_boards/message/21314522
It could be an interesting post for anyone that wants to learn more about Filter hooks like me. I think I was in the right path for a solution...a member replied with an interesting code snippet there that I am about to try.