Forums de discussion

RE: Filter not being called when web service is called

thumbnail
David H Nebinger, modifié il y a 9 années.

RE: Filter not being called when web service is called

Liferay Legend Publications: 14916 Date d'inscription: 02/09/06 Publications récentes
Gwowen Fu:

Hello,

I want to get the request object from a filter when my service in a hook is called. I found a post that has code like the following but the filter is not being called at all.
I am using Liferay 6.1.20 EE.


import javax.servlet.FilterChain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.liferay.portal.kernel.util.AutoResetThreadLocal;
import com.liferay.portal.servlet.filters.BasePortalFilter;

public class RequestFilter extends BasePortalFilter {

    private static ThreadLocal<httpservletrequest> _localRequest =
            new AutoResetThreadLocal<httpservletrequest>(
                RequestFilter.class + "._localRequest");
    
    
    protected void processFilter(HttpServletRequest request,
            HttpServletResponse response, FilterChain filterChain)
            throws Exception {

        System.out.println("Process Filter [" + request + "]");

        _localRequest.set((HttpServletRequest) request);

        try {
            filterChain.doFilter(request, response);
        }
        finally {
            // To be thread safe the local thread are removed
            _localRequest.remove();            
        }
    }    

    
    public static HttpServletRequest getRequest() {
        System.out.println("getRequest()");

        HttpServletRequest request = _localRequest.get();

        return request;
    }
    
}</httpservletrequest></httpservletrequest>


https://www.liferay.com/community/forums/-/message_boards/message/32154822

Thanks for any suggestion!
Gwowen


This is a servlet filter. Where did it get applied? To the portal (where all incoming portal requests come from) or to your hook's web.xml (which won't get invoked for squat)?

And honestly I know what you're trying to do and it really should be avoided. You are trying to get to the HTTP request inside of your service method. This is a very clear indication that you're trying to hack your system up to get to the request inside of the service implementation.

There is absolutely nothing, and I mean nothing, that you should be doing to require access to the HTTP request inside of your service method. It is a clear indication that your code is simply wrong, your entire architecture is broken, and you're in for a world of hurt in the long run.
Gwowen Fu, modifié il y a 9 années.

RE: Filter not being called when web service is called

Expert Publications: 315 Date d'inscription: 27/12/10 Publications récentes
Hi David,

Thanks for the advise. I know it is not the right way but I just couldn't get the simple code to work for regular site member in Luminis Liferay in the first place.

AUI().use("liferay-portlet-url", function(A) {
    var url = Liferay.PortletURL.createRenderURL();
    url.setPortletId("56");
    url.setPortletMode("view");
    url.setWindowState('EXCLUSIVE');
    url.setParameter("groupId", themeDisplay.getCompanyGroupId());
    url.setParameter("articleId", "7761819");
    var portletURL1 = url.toString();
 );


I also tried the link generated from web content preview action. It is working for admin but not working when I login as a regular user.
https://somehost.edu/c/journal/view_article_content?cmd=view&groupId=10184&articleId=7761941

It must be something that turned off by Ellucian to not allow regular user to access web content this way. Does Liferay provide a property for this or it is hacked by Ellucian?

I still cannot get a hold with Ellucian that's why I am looking for any help here.

Thank you!
Gwowen
thumbnail
David H Nebinger, modifié il y a 9 années.

RE: Filter not being called when web service is called

Liferay Legend Publications: 14916 Date d'inscription: 02/09/06 Publications récentes
Yeah, that's hard to answer, Gwowen. I guess I would say that the harsh words are really more for readers who get here later that want to access the request within the service implementation in general, not your special case of trying to add another layer to Ellucian (which is another layer around Liferay).

It's hard to say what Ellucian may or may not have done to Liferay. For Liferay sites that I've helped set up, the end product can sometimes drastically differ from the Liferay default simply because there's a list of requirements to satisfy and changes/overrides are necessary to make that happen. Surely the Ellucian folks had a list of requirements they needed to satisfy and that would have required some changes/overrides, but I'm not really privy to any of it. Their changes could have been minimal or they could have been significant.

I think it's still appropriate to go through Ellucian for their guidance first; even though you're having difficulty getting through to them, it's still their product and it's probably still better to work within their constraints. I mean, I can give some general guidance for a vanilla Liferay, but since their system is not a vanilla Liferay the guidance might not apply at all.

I know it's not what you'll want to hear, but I don't know how else to help...
Gwowen Fu, modifié il y a 9 années.

RE: Filter not being called when web service is called

Expert Publications: 315 Date d'inscription: 27/12/10 Publications récentes
Thanks, David. At least it is good to know that vanilla Liferay doesn't do that. It is really nice to have someone like you in this community.