Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7410463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:14:16+00:00 2026-05-29T06:14:16+00:00

In my application I have added interceptor to filter the request.Here each user is

  • 0

In my application I have added interceptor to filter the request.Here each user is associated with a list of menu. So if user try to access page which is not associated to him then we will redirect him to unauthorizedUser.jsp page otherwise we will let the user to access the page.

Here is my interceptor code …

 @Override
    public  String intercept(ActionInvocation actionInvocation) throws Exception {
        String returnAction = "unauth.user";
        Map<String, String> keyValMap = FCCommonUtils.getALLMenuIdMap();
        ActionContext context = actionInvocation.getInvocationContext();

        HttpServletRequest request = (HttpServletRequest) context.get(StrutsStatics.HTTP_REQUEST);
        HttpSession session = null;
        if (request != null) {
            session = request.getSession(false);
            String contextPath = request.getContextPath();
            contextPath = contextPath + RequestURIDtls.SEPERATOR;
            String reqURI = request.getRequestURI().substring(contextPath.length(), request.getRequestURI().length());
            String requestedRole = keyValMap.get(reqURI);

            if (requestedRole != null && session != null) {
                UserInfoUIForm userForm = (UserInfoUIForm) session.getAttribute(WebConstants.USER_INFO);
                if (userForm != null) {
                    List<Long> userRoleLst = FCCommonUtils.getmenuids(userForm.getRoleId());

                    if (userRoleLst.contains(new Long(requestedRole))) {
                        //TODO : GUNJAN : NEED TO DO R&D WHY actionInvocation.invoke() CREATES NULL POINTER EXCEPTION
                        //returnAction=actionInvocation.invoke();                        
                        returnAction = "success";
                    } else {
                        returnAction = "unauth.user";
                    }
                } else {
                    returnAction = "unauth.user";
                }
            } else {
                returnAction = "unauth.user";
            }

        } else {
            returnAction = "unauth.user";
        }
        return returnAction;
    }

In above code returnAction=actionInvocation.invoke() gives null pointer exception.

Here is my struts.xml configuration to access the page ..

<action name="viewCorporate" class="com.ndil.web.corporate.MstCorporateAction" method="viewCorporatePage">
            <interceptor-ref name="menuFilterInterceptor" />
            <result name="unauth.user">/jsp/unAuthUser.jsp</result>
            <result name="success">/jsp/mngCorporate.jsp</result>
        </action>         

Can any one suggest me why actionInvocation.invoke() gives null pointer exception ???

Thanks,
Gunjan Shah.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:14:18+00:00Added an answer on May 29, 2026 at 6:14 am

    Free code review.

    1) Intercept result decared as variable, unused.

    2) Said value should be a constant anyway.

    3) Variable is named incorrectly–it’s not an action name, it’s a result name.

    4) If you’re in an interceptor, you’ve gotten a request–there’s just no way for this to be null. If it is null, something far more serious than an unauthorized user has occurred, and the world should blow up.

    5) Similarly, unless you’ve specifically configured your entire app not to create sessions, checking for a session is redundant. If you don’t, something has gone horribly wrong. Check for known session attributes to determine if a user is logged in, not for the presence of the session itself–much easier.

    IMO both 4 and 5, if handled at all, should be handled with declarative exceptions. In that state, the web app is likely inoperable–peg the user to HTTP 500 or similar.

    6) The nested conditionals are way too deep. Strict adherence to “one return per method” creates difficult-to-understand code, particularly when a method has deeply-nested conditionals.

    7) It looks like you’re relying on form data to determine the user’s role. This is inherently insecure; user role information should be kept in the session, where it can’t be easily manipulated.

    8) Some miscellaneous tweaks leave us with this:

    public class FooInterceptor {
    
        private static final String UNAUTHORIZED_USER = "unauth.user";
    
        public  String intercept(ActionInvocation actionInvocation) throws Exception {
            ActionContext context = actionInvocation.getInvocationContext();
            HttpServletRequest request = (HttpServletRequest) context.get(StrutsStatics.HTTP_REQUEST);
            if (request == null) {
                return UNAUTHORIZED_USER;
            }
    
            HttpSession session = request.getSession(false);
            if (session == null) {
                return UNAUTHORIZED_USER;
            }
    
            Long requestedRole = getRequestedRole(request);
            if (requestedRole == null) {
                return UNAUTHORIZED_USER;
            }
    
            UserInfoUIForm userForm = (UserInfoUIForm) session.getAttribute(WebConstants.USER_INFO);
            if (userForm == null) {
                return UNAUTHORIZED_USER;
            }
    
            List<Long> userRoles = FCCommonUtils.getmenuids(userForm.getRoleId());
            return userRoles.contains(requestedRole) ? ActionSupport.SUCCESS : UNAUTHORIZED_USER;
        }
    
        private Long getRequestedRole(HttpServletRequest request) {
            String contextPath = request.getContextPath() + RequestURIDtls.SEPARATOR;
            String reqURI = request.getRequestURI().substring(contextPath.length(), request.getRequestURI().length());
            try {
                return Long.valueOf(FCCommonUtils.getALLMenuIdMap().get(reqURI));
            } catch (NumberFormatException e) {
                return null;
            }
        }
    }
    

    While testing the method remains relatively difficult, it’s much easier to understand the precise testing needs. It’s easier to read, because you no longer have to wonder “what if the opposite is true?” as in the deeply-nested code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just added a Telerik menu to my MVC application. I also have
I have an application you can access here When you open the app, please
Currently, each web service for our application has a user parameter that is added
I have an application in which I have added a menu. Clicking on this
In a C# Winforms (3.5) application I have added a class that contains many
I have added some settings to my c# application using the configuration editor. There
Consider System.Windows.Forms.StatusStrip . I have added a StatusStrip to my Windows Forms application, but
I have just added a Core Plot view to my application based on a
In my application I have QGraphicsScene with pixmap added and all is viewed in
I have an ASP.NET MVC application with a separate project added for tests. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.